Re: [PATCH 07/16] HID: wiimote: Parse accelerometer data

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Jul 28, 2011 at 8:12 PM, Oliver Neukum <oneukum@xxxxxxx> wrote:
> Am Donnerstag, 28. Juli 2011, 18:08:27 schrieb David Herrmann:
>> +static void handler_accel(struct wiimote_data *wdata, const __u8 *payload)
>> +{
>> +       __u16 x, y, z;
>> +
>> +       if (!(wdata->state.flags & WIIPROTO_FLAG_ACCEL))
>> +               return;
>> +
>> +       /*
>> +        * payload is: BB BB XX YY ZZ
>> +        * Buttons data contains LSBs
>> +        */
>> +
>> +       x = payload[2] << 2;
>> +       y = payload[3] << 2;
>> +       z = payload[4] << 2;
>> +
>> +       x |= (payload[0] >> 5) & 0x3;
>> +       y |= (payload[1] >> 4) & 0x2;
>> +       z |= (payload[1] >> 5) & 0x2;
>
> Could you make the comments a bit clearer. Those last lines are impossible
> to understand.

The LSBs are encoded in the "BB BB" data and I am extracting them. I
have documented the whole protocol in a separated document but if it
is common practice to add those comments to the code, I will add it in
the next version.

X, Y and Z data of accelerometer have 10 bits of precision. The data
is reported as 5 bytes:
BB BB XX YY ZZ
The first two bytes also contain the button data but there are 5
additional bits in the BB BB data that contain the LSBs of the
accelerometer.
XX YY ZZ are the upper 8 bits of the three accelerometer values.

BB BB have 8 bits. Bit 6 and 7 of first byte are LSBs of X value.
Bit 6 of second byte is LSB of Y value. Bit 7 of second byte is LSB of
Z value. The 10th bit of Y and Z are no available and set to 0.
As a table:

1st byte BB
Bit: 1 2 3 4 5 6 7 8
     ---------------
     B B B B B X X B

2nd byte BB
Bit: 1 2 3 4 5 6 7 8
     ---------------
     B B B B B Y Z B

B is button data and ignored here. handler_keys() takes care of them.

>        Regards
>                Oliver

Thanks for your review.
Regards
David
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media Devel]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Linux Wireless Networking]     [Linux Omap]

  Powered by Linux