-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjoydev-dancepad-1.2-4.13.3.patch
225 lines (219 loc) · 7.88 KB
/
joydev-dancepad-1.2-4.13.3.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
--- linux-4.13.3-old/drivers/input/joydev.c 2017-09-20 03:28:17.000000000 -0300
+++ linux-4.13.3/drivers/input/joydev.c 2017-10-01 11:41:53.823274369 -0300
@@ -37,6 +37,9 @@
#define JOYDEV_MINORS 16
#define JOYDEV_BUFFER_SIZE 64
+#define DANCEPAD_VENDOR 0x0810
+#define DANCEPAD_PRODUCT 0x0001
+
struct joydev {
int open;
struct input_handle handle;
@@ -57,6 +60,9 @@
__u8 absmap[ABS_CNT];
__u8 abspam[ABS_CNT];
__s16 abs[ABS_CNT];
+ bool dance_pad;
+ unsigned x_axis_status;
+ unsigned y_axis_status;
};
struct joydev_client {
@@ -114,43 +120,150 @@
kill_fasync(&client->fasync, SIGIO, POLL_IN);
}
-static void joydev_event(struct input_handle *handle,
- unsigned int type, unsigned int code, int value)
+static void joydev_send_event(struct js_event *event, struct joydev *joydev)
{
- struct joydev *joydev = handle->private;
struct joydev_client *client;
- struct js_event event;
-
- switch (type) {
-
- case EV_KEY:
- if (code < BTN_MISC || value == 2)
- return;
- event.type = JS_EVENT_BUTTON;
- event.number = joydev->keymap[code - BTN_MISC];
- event.value = value;
- break;
-
- case EV_ABS:
- event.type = JS_EVENT_AXIS;
- event.number = joydev->absmap[code];
- event.value = joydev_correct(value,
- &joydev->corr[event.number]);
- if (event.value == joydev->abs[event.number])
- return;
- joydev->abs[event.number] = event.value;
- break;
-
- default:
- return;
- }
-
- event.time = jiffies_to_msecs(jiffies);
+ event->time = jiffies_to_msecs(jiffies);
rcu_read_lock();
list_for_each_entry_rcu(client, &joydev->client_list, node)
- joydev_pass_event(client, &event);
+ joydev_pass_event(client, event);
rcu_read_unlock();
+}
+
+static void joydev_event(struct input_handle *handle,
+ unsigned int type, unsigned int code, int value)
+{
+ struct joydev *joydev = handle->private;
+ struct js_event event;
+
+# define JOYDEV_LEFT 12
+# define JOYDEV_RIGHT 13
+# define JOYDEV_UP 14
+# define JOYDEV_DOWN 15
+# define X_AXIS 0
+# define Y_AXIS 1
+# define X_AXIS_LEFT 1
+# define X_AXIS_RIGHT 2
+# define Y_AXIS_UP 1
+# define Y_AXIS_DOWN 2
+
+ if (joydev->dance_pad)
+ {
+
+ unsigned x_axis_new_status = joydev->x_axis_status;
+ unsigned y_axis_new_status = joydev->y_axis_status;
+
+ switch (type) {
+
+ case EV_KEY:
+ if (code < BTN_MISC || value == 2)
+ return;
+ event.type = JS_EVENT_BUTTON;
+ event.number = joydev->keymap[code - BTN_MISC];
+ event.value = value;
+
+ joydev_send_event(&event, joydev);
+
+ break;
+
+ case EV_ABS:
+ if (code == X_AXIS)
+ {
+ if (value == 0)
+ {
+ x_axis_new_status |= X_AXIS_LEFT;
+ x_axis_new_status &= ~X_AXIS_RIGHT;
+ }
+ if (value == 255)
+ {
+ x_axis_new_status |= X_AXIS_RIGHT;
+ x_axis_new_status &= ~X_AXIS_LEFT;
+ }
+ if (value == 128)
+ x_axis_new_status |= X_AXIS_LEFT | X_AXIS_RIGHT;
+ if (value == 127)
+ x_axis_new_status = 0;
+ }
+ if (code == Y_AXIS)
+ {
+ if (value == 0)
+ {
+ y_axis_new_status |= Y_AXIS_UP;
+ y_axis_new_status &= ~Y_AXIS_DOWN;
+ }
+ if (value == 255)
+ {
+ y_axis_new_status |= Y_AXIS_DOWN;
+ y_axis_new_status &= ~Y_AXIS_UP;
+ }
+ if (value == 128)
+ y_axis_new_status |= Y_AXIS_UP | Y_AXIS_DOWN;
+ if (value == 127)
+ y_axis_new_status = 0;
+ }
+
+ event.type = JS_EVENT_BUTTON;
+ if ((x_axis_new_status ^ joydev->x_axis_status) & X_AXIS_LEFT)
+ {
+ event.number = JOYDEV_LEFT;
+ event.value = (x_axis_new_status & X_AXIS_LEFT) > 0 ? 1 : 0;
+ joydev_send_event(&event, joydev);
+ }
+ if ((x_axis_new_status ^ joydev->x_axis_status) & X_AXIS_RIGHT)
+ {
+ event.number = JOYDEV_RIGHT;
+ event.value = (x_axis_new_status & X_AXIS_RIGHT) > 0 ? 1 : 0;
+ joydev_send_event(&event, joydev);
+ }
+ if ((y_axis_new_status ^ joydev->y_axis_status) & Y_AXIS_UP)
+ {
+ event.number = JOYDEV_UP;
+ event.value = (y_axis_new_status & Y_AXIS_UP) > 0 ? 1 : 0;
+ joydev_send_event(&event, joydev);
+ }
+ if ((y_axis_new_status ^ joydev->y_axis_status) & Y_AXIS_DOWN)
+ {
+ event.number = JOYDEV_DOWN;
+ event.value = (y_axis_new_status & Y_AXIS_DOWN) > 0 ? 1 : 0;
+ joydev_send_event(&event, joydev);
+ }
+
+ joydev->x_axis_status = x_axis_new_status;
+ joydev->y_axis_status = y_axis_new_status;
+
+ break;
+ default:
+ return;
+ }
+ }
+ else
+ {
+ switch (type) {
+
+ case EV_KEY:
+ if (code < BTN_MISC || value == 2)
+ return;
+ event.type = JS_EVENT_BUTTON;
+ event.number = joydev->keymap[code - BTN_MISC];
+ event.value = value;
+ break;
+
+ case EV_ABS:
+ event.type = JS_EVENT_AXIS;
+ event.number = joydev->absmap[code];
+ event.value = joydev_correct(value,
+ &joydev->corr[event.number]);
+ if (event.value == joydev->abs[event.number])
+ return;
+ joydev->abs[event.number] = event.value;
+ break;
+
+ default:
+ return;
+ }
+ joydev_send_event(&event, joydev);
+ }
wake_up_interruptible(&joydev->wait);
}
@@ -900,6 +1013,20 @@
}
}
+ if (dev->id.vendor == DANCEPAD_VENDOR && dev->id.product == DANCEPAD_PRODUCT)
+ {
+ joydev->dance_pad = true;
+ joydev->x_axis_status = 0;
+ joydev->y_axis_status = 0;
+ joydev->nkey += 4;
+ printk("Dancepad detected: activating workaround.\n");
+ }
+ else
+ {
+ joydev->dance_pad = false;
+ }
+
+
joydev->dev.devt = MKDEV(INPUT_MAJOR, minor);
joydev->dev.class = &input_class;
joydev->dev.parent = &dev->dev;