diff options
author | David Herrmann <dh.herrmann@googlemail.com> | 2011-09-06 07:50:38 -0400 |
---|---|---|
committer | Jiri Kosina <jkosina@suse.cz> | 2011-09-07 07:25:18 -0400 |
commit | e3979a9189d744ffecae1bcd36ae0a8b6d22f65f (patch) | |
tree | 2ee6a3fc8bcffc1662b7c020c619ede27c98a15e /drivers/hid | |
parent | 0370d7cb30716b202b2412b9b2d4740fd3152d30 (diff) |
HID: wiimote: Add status request
The wiimote does not send status reports continuously so this adds a helper
function to request a status report and parses the battery charge level.
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'drivers/hid')
-rw-r--r-- | drivers/hid/hid-wiimote.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/drivers/hid/hid-wiimote.c b/drivers/hid/hid-wiimote.c index 66583986bcdb..48198cb0fed2 100644 --- a/drivers/hid/hid-wiimote.c +++ b/drivers/hid/hid-wiimote.c | |||
@@ -41,6 +41,7 @@ struct wiimote_state { | |||
41 | __u32 opt; | 41 | __u32 opt; |
42 | 42 | ||
43 | /* results of synchronous requests */ | 43 | /* results of synchronous requests */ |
44 | __u8 cmd_battery; | ||
44 | __u8 cmd_err; | 45 | __u8 cmd_err; |
45 | }; | 46 | }; |
46 | 47 | ||
@@ -83,6 +84,7 @@ enum wiiproto_reqs { | |||
83 | WIIPROTO_REQ_LED = 0x11, | 84 | WIIPROTO_REQ_LED = 0x11, |
84 | WIIPROTO_REQ_DRM = 0x12, | 85 | WIIPROTO_REQ_DRM = 0x12, |
85 | WIIPROTO_REQ_IR1 = 0x13, | 86 | WIIPROTO_REQ_IR1 = 0x13, |
87 | WIIPROTO_REQ_SREQ = 0x15, | ||
86 | WIIPROTO_REQ_WMEM = 0x16, | 88 | WIIPROTO_REQ_WMEM = 0x16, |
87 | WIIPROTO_REQ_RMEM = 0x17, | 89 | WIIPROTO_REQ_RMEM = 0x17, |
88 | WIIPROTO_REQ_IR2 = 0x1a, | 90 | WIIPROTO_REQ_IR2 = 0x1a, |
@@ -354,6 +356,17 @@ static void wiiproto_req_drm(struct wiimote_data *wdata, __u8 drm) | |||
354 | wiimote_queue(wdata, cmd, sizeof(cmd)); | 356 | wiimote_queue(wdata, cmd, sizeof(cmd)); |
355 | } | 357 | } |
356 | 358 | ||
359 | static void wiiproto_req_status(struct wiimote_data *wdata) | ||
360 | { | ||
361 | __u8 cmd[2]; | ||
362 | |||
363 | cmd[0] = WIIPROTO_REQ_SREQ; | ||
364 | cmd[1] = 0; | ||
365 | |||
366 | wiiproto_keep_rumble(wdata, &cmd[1]); | ||
367 | wiimote_queue(wdata, cmd, sizeof(cmd)); | ||
368 | } | ||
369 | |||
357 | static void wiiproto_req_accel(struct wiimote_data *wdata, __u8 accel) | 370 | static void wiiproto_req_accel(struct wiimote_data *wdata, __u8 accel) |
358 | { | 371 | { |
359 | accel = !!accel; | 372 | accel = !!accel; |
@@ -805,6 +818,11 @@ static void handler_status(struct wiimote_data *wdata, const __u8 *payload) | |||
805 | 818 | ||
806 | /* on status reports the drm is reset so we need to resend the drm */ | 819 | /* on status reports the drm is reset so we need to resend the drm */ |
807 | wiiproto_req_drm(wdata, WIIPROTO_REQ_NULL); | 820 | wiiproto_req_drm(wdata, WIIPROTO_REQ_NULL); |
821 | |||
822 | if (wiimote_cmd_pending(wdata, WIIPROTO_REQ_SREQ, 0)) { | ||
823 | wdata->state.cmd_battery = payload[5]; | ||
824 | wiimote_cmd_complete(wdata); | ||
825 | } | ||
808 | } | 826 | } |
809 | 827 | ||
810 | static void handler_data(struct wiimote_data *wdata, const __u8 *payload) | 828 | static void handler_data(struct wiimote_data *wdata, const __u8 *payload) |