diff options
author | David Herrmann <dh.herrmann@googlemail.com> | 2011-07-05 07:45:15 -0400 |
---|---|---|
committer | Jiri Kosina <jkosina@suse.cz> | 2011-07-11 08:30:23 -0400 |
commit | a4d19197627e2a8645cccd9039edf513c6384297 (patch) | |
tree | 986e55ccfa80b6bbfedd861abd68c331c8c8be78 /drivers/hid | |
parent | 23c063cb02b69244bbc215cb81c2cad0208fbecf (diff) |
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')
-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 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, | |||
130 | return 0; | 130 | return 0; |
131 | } | 131 | } |
132 | 132 | ||
133 | struct wiiproto_handler { | ||
134 | __u8 id; | ||
135 | size_t size; | ||
136 | void (*func)(struct wiimote_data *wdata, const __u8 *payload); | ||
137 | }; | ||
138 | |||
139 | static struct wiiproto_handler handlers[] = { | ||
140 | { .id = 0 } | ||
141 | }; | ||
142 | |||
133 | static int wiimote_hid_event(struct hid_device *hdev, struct hid_report *report, | 143 | static int wiimote_hid_event(struct hid_device *hdev, struct hid_report *report, |
134 | u8 *raw_data, int size) | 144 | u8 *raw_data, int size) |
135 | { | 145 | { |
136 | struct wiimote_data *wdata = hid_get_drvdata(hdev); | 146 | struct wiimote_data *wdata = hid_get_drvdata(hdev); |
147 | struct wiiproto_handler *h; | ||
148 | int i; | ||
137 | 149 | ||
138 | if (!atomic_read(&wdata->ready)) | 150 | if (!atomic_read(&wdata->ready)) |
139 | return -EBUSY; | 151 | return -EBUSY; |
@@ -143,6 +155,12 @@ static int wiimote_hid_event(struct hid_device *hdev, struct hid_report *report, | |||
143 | if (size < 1) | 155 | if (size < 1) |
144 | return -EINVAL; | 156 | return -EINVAL; |
145 | 157 | ||
158 | for (i = 0; handlers[i].id; ++i) { | ||
159 | h = &handlers[i]; | ||
160 | if (h->id == raw_data[0] && h->size < size) | ||
161 | h->func(wdata, &raw_data[1]); | ||
162 | } | ||
163 | |||
146 | return 0; | 164 | return 0; |
147 | } | 165 | } |
148 | 166 | ||