Re: [PATCH 07/16] HID: wiimote: Parse accelerometer data
flat view
From: David Herrmann <hidden>
Date: 2011-07-28 18:51:38
On Thu, Jul 28, 2011 at 8:12 PM, Oliver Neukum [off-list ref] wrote:
Am Donnerstag, 28. Juli 2011, 18:08:27 schrieb David Herrmann:quoted
+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@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html