summaryrefslogtreecommitdiffstats
path: root/drivers/hid/hid-wiimote.c
diff options
context:
space:
mode:
authorDavid Herrmann <dh.herrmann@googlemail.com>2011-07-05 13:45:15 +0200
committerJiri Kosina <jkosina@suse.cz>2011-07-11 14:30:23 +0200
commita4d19197627e2a8645cccd9039edf513c6384297 (patch)
tree986e55ccfa80b6bbfedd861abd68c331c8c8be78 /drivers/hid/hid-wiimote.c
parent23c063cb02b69244bbc215cb81c2cad0208fbecf (diff)
downloadlinux-a4d19197627e2a8645cccd9039edf513c6384297.tar.bz2
HID: wiimote: Add wiimote event handler
Create array of all event handlers and call each handler when we receive the related event. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'drivers/hid/hid-wiimote.c')
-rw-r--r--drivers/hid/hid-wiimote.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/drivers/hid/hid-wiimote.c b/drivers/hid/hid-wiimote.c
index bfc50493ec6b..c86ae92b51db 100644
--- a/drivers/hid/hid-wiimote.c
+++ b/drivers/hid/hid-wiimote.c
@@ -130,10 +130,22 @@ static int wiimote_input_event(struct input_dev *dev, unsigned int type,
return 0;
}
+struct wiiproto_handler {
+ __u8 id;
+ size_t size;
+ void (*func)(struct wiimote_data *wdata, const __u8 *payload);
+};
+
+static struct wiiproto_handler handlers[] = {
+ { .id = 0 }
+};
+
static int wiimote_hid_event(struct hid_device *hdev, struct hid_report *report,
u8 *raw_data, int size)
{
struct wiimote_data *wdata = hid_get_drvdata(hdev);
+ struct wiiproto_handler *h;
+ int i;
if (!atomic_read(&wdata->ready))
return -EBUSY;
@@ -143,6 +155,12 @@ static int wiimote_hid_event(struct hid_device *hdev, struct hid_report *report,
if (size < 1)
return -EINVAL;
+ for (i = 0; handlers[i].id; ++i) {
+ h = &handlers[i];
+ if (h->id == raw_data[0] && h->size < size)
+ h->func(wdata, &raw_data[1]);
+ }
+
return 0;
}