我已经能够让它与这个代码一起工作(在东芝 Satellite Pro S300L-120,Windows 7 上):
void ReadAccel(float a[3])
{
HANDLE h = CreateFile(L"\\\\.\\TVALZ", GENERIC_ALL, FILE_SHARE_WRITE|FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
struct dummy
{
unsigned long magic1; /* = 0x0000FE00 */
unsigned long magic2; /* = 0x000000A6 */
unsigned short x, y;
unsigned long unknown, z;
unsigned long direction;
} d;
memset(&d, 0, sizeof(d));
unsigned long retlen;
d.magic1 = 0x0000FE00;
d.magic2 = 0xA6;
d.direction = 0;
DeviceIoControl(h, 0x222880, &d, sizeof(d), &d, sizeof(d), &retlen, NULL);
d.magic1 = 0x0000FE00;
d.direction = 1;
Sleep(20); /* Doesn't seem to work without the wait */
DeviceIoControl(h, 0x222880, &d, sizeof(d), &d, sizeof(d), &retlen, NULL);
signed short x = (d.x & 0x7FFF) * (d.x & 0x8000?-1:1);
signed short y = (d.y & 0x7FFF) * (d.y & 0x8000?-1:1);
signed short z = (d.z & 0x7FFF) * (d.z & 0x8000?-1:1);
a[2] = -(float)z * 9.8 / 205; /* this is just an estimate to go to SI units */
a[1] = (float)y * 9.8 / 205;
a[0] = (float)x * 9.8 / 205;
CloseHandle(h);
}
它可能还不是很漂亮,但我们可以开始玩了:)
顺便说一句,我使用了东芝硬件监视器附带的 TPCHCTL.dll 来解决这个问题。