1use super::{Code, Kind, Press, Release};
2use crate::Event;
3use ffi::*;
4use libc::c_int;
5
6#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
7pub enum Controller {
8 All,
9 Misc(Misc),
10 Mouse(Mouse),
11 JoyStick(JoyStick),
12 GamePad(GamePad),
13 Digi(Digi),
14 Wheel(Wheel),
15 DPad(DPad),
16 TriggerHappy(TriggerHappy),
17}
18
19impl Into<Event> for Controller {
20 fn into(self) -> Event {
21 Event::Controller(self)
22 }
23}
24
25impl Press for Controller {}
26impl Release for Controller {}
27
28impl Kind for Controller {
29 fn kind(&self) -> c_int {
30 EV_KEY
31 }
32}
33
34impl Code for Controller {
35 fn code(&self) -> c_int {
36 match self {
37 &Controller::All => unreachable!(),
38
39 &Controller::Misc(ref v) => v.code(),
40 &Controller::Mouse(ref v) => v.code(),
41 &Controller::JoyStick(ref v) => v.code(),
42 &Controller::GamePad(ref v) => v.code(),
43 &Controller::Digi(ref v) => v.code(),
44 &Controller::Wheel(ref v) => v.code(),
45 &Controller::DPad(ref v) => v.code(),
46 &Controller::TriggerHappy(ref v) => v.code(),
47 }
48 }
49}
50
51custom_derive! {
52 #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, IterVariants(MiscVariants))]
53 pub enum Misc {
54 _0,
55 _1,
56 _2,
57 _3,
58 _4,
59 _5,
60 _6,
61 _7,
62 _8,
63 _9,
64 }
65}
66
67impl Into<Event> for Misc {
68 fn into(self) -> Event {
69 Event::Controller(Controller::Misc(self))
70 }
71}
72
73impl Kind for Misc {
74 fn kind(&self) -> c_int {
75 EV_KEY
76 }
77}
78
79impl Code for Misc {
80 fn code(&self) -> c_int {
81 match self {
82 &Misc::_0 => BTN_0,
83 &Misc::_1 => BTN_1,
84 &Misc::_2 => BTN_2,
85 &Misc::_3 => BTN_3,
86 &Misc::_4 => BTN_4,
87 &Misc::_5 => BTN_5,
88 &Misc::_6 => BTN_6,
89 &Misc::_7 => BTN_7,
90 &Misc::_8 => BTN_8,
91 &Misc::_9 => BTN_9,
92 }
93 }
94}
95
96custom_derive! {
97 #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, IterVariants(MouseVariants))]
98 pub enum Mouse {
99 Left,
100 Right,
101 Middle,
102 Side,
103 Extra,
104 Forward,
105 Back,
106 Task,
107 }
108}
109
110impl Into<Event> for Mouse {
111 fn into(self) -> Event {
112 Event::Controller(Controller::Mouse(self))
113 }
114}
115
116impl Code for Mouse {
117 fn code(&self) -> c_int {
118 match self {
119 &Mouse::Left => BTN_LEFT,
120 &Mouse::Right => BTN_RIGHT,
121 &Mouse::Middle => BTN_MIDDLE,
122 &Mouse::Side => BTN_SIDE,
123 &Mouse::Extra => BTN_EXTRA,
124 &Mouse::Forward => BTN_FORWARD,
125 &Mouse::Back => BTN_BACK,
126 &Mouse::Task => BTN_TASK,
127 }
128 }
129}
130
131custom_derive! {
132 #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, IterVariants(JoyStickVariants))]
133 pub enum JoyStick {
134 Trigger,
135 Thumb,
136 Thumb2,
137 Top,
138 Top2,
139 Pinkie,
140 Base,
141 Base2,
142 Base3,
143 Base4,
144 Base5,
145 Base6,
146 Dead,
147 }
148}
149
150impl Into<Event> for JoyStick {
151 fn into(self) -> Event {
152 Event::Controller(Controller::JoyStick(self))
153 }
154}
155
156impl Press for JoyStick {}
157impl Release for JoyStick {}
158
159impl Kind for JoyStick {
160 fn kind(&self) -> c_int {
161 EV_KEY
162 }
163}
164
165impl Code for JoyStick {
166 fn code(&self) -> c_int {
167 match self {
168 &JoyStick::Trigger => BTN_TRIGGER,
169 &JoyStick::Thumb => BTN_THUMB,
170 &JoyStick::Thumb2 => BTN_THUMB2,
171 &JoyStick::Top => BTN_TOP,
172 &JoyStick::Top2 => BTN_TOP2,
173 &JoyStick::Pinkie => BTN_PINKIE,
174 &JoyStick::Base => BTN_BASE,
175 &JoyStick::Base2 => BTN_BASE2,
176 &JoyStick::Base3 => BTN_BASE3,
177 &JoyStick::Base4 => BTN_BASE4,
178 &JoyStick::Base5 => BTN_BASE5,
179 &JoyStick::Base6 => BTN_BASE6,
180 &JoyStick::Dead => BTN_DEAD,
181 }
182 }
183}
184
185custom_derive! {
186 #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, IterVariants(GamePadVariants))]
187 pub enum GamePad {
188 South,
189 A,
190 East,
191 B,
192 C,
193 North,
194 X,
195 West,
196 Y,
197 Z,
198 TL,
199 TR,
200 TL2,
201 TR2,
202 Select,
203 Start,
204 Mode,
205 ThumbL,
206 ThumbR,
207 }
208}
209
210impl Into<Event> for GamePad {
211 fn into(self) -> Event {
212 Event::Controller(Controller::GamePad(self))
213 }
214}
215
216impl Press for GamePad {}
217impl Release for GamePad {}
218
219impl Kind for GamePad {
220 fn kind(&self) -> c_int {
221 EV_KEY
222 }
223}
224
225impl Code for GamePad {
226 fn code(&self) -> c_int {
227 match self {
228 &GamePad::South => BTN_SOUTH,
229 &GamePad::A => BTN_A,
230 &GamePad::East => BTN_EAST,
231 &GamePad::B => BTN_B,
232 &GamePad::C => BTN_C,
233 &GamePad::North => BTN_NORTH,
234 &GamePad::X => BTN_X,
235 &GamePad::West => BTN_WEST,
236 &GamePad::Y => BTN_Y,
237 &GamePad::Z => BTN_Z,
238 &GamePad::TL => BTN_TL,
239 &GamePad::TR => BTN_TR,
240 &GamePad::TL2 => BTN_TL2,
241 &GamePad::TR2 => BTN_TR2,
242 &GamePad::Select => BTN_SELECT,
243 &GamePad::Start => BTN_START,
244 &GamePad::Mode => BTN_MODE,
245 &GamePad::ThumbL => BTN_THUMBL,
246 &GamePad::ThumbR => BTN_THUMBR,
247 }
248 }
249}
250
251custom_derive! {
252 #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, IterVariants(DigiVariants))]
253 pub enum Digi {
254 Pen,
255 Rubber,
256 Brush,
257 Pencil,
258 AirBrush,
259 Finger,
260 Mouse,
261 Lens,
262 QuintTap,
263 Touch,
264 Stylus,
265 Stylus2,
266 DoubleTap,
267 TripleTap,
268 QuadTap,
269 }
270}
271
272impl Into<Event> for Digi {
273 fn into(self) -> Event {
274 Event::Controller(Controller::Digi(self))
275 }
276}
277
278impl Press for Digi {}
279impl Release for Digi {}
280
281impl Kind for Digi {
282 fn kind(&self) -> c_int {
283 EV_KEY
284 }
285}
286
287impl Code for Digi {
288 fn code(&self) -> c_int {
289 match self {
290 &Digi::Pen => BTN_TOOL_PEN,
291 &Digi::Rubber => BTN_TOOL_RUBBER,
292 &Digi::Brush => BTN_TOOL_BRUSH,
293 &Digi::Pencil => BTN_TOOL_PENCIL,
294 &Digi::AirBrush => BTN_TOOL_AIRBRUSH,
295 &Digi::Finger => BTN_TOOL_FINGER,
296 &Digi::Mouse => BTN_TOOL_MOUSE,
297 &Digi::Lens => BTN_TOOL_LENS,
298 &Digi::QuintTap => BTN_TOOL_QUINTTAP,
299 &Digi::Touch => BTN_TOUCH,
300 &Digi::Stylus => BTN_STYLUS,
301 &Digi::Stylus2 => BTN_STYLUS2,
302 &Digi::DoubleTap => BTN_TOOL_DOUBLETAP,
303 &Digi::TripleTap => BTN_TOOL_TRIPLETAP,
304 &Digi::QuadTap => BTN_TOOL_QUADTAP,
305 }
306 }
307}
308
309custom_derive! {
310 #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, IterVariants(WheelVariants))]
311 pub enum Wheel {
312 GearDown,
313 GearUp,
314 }
315}
316
317impl Into<Event> for Wheel {
318 fn into(self) -> Event {
319 Event::Controller(Controller::Wheel(self))
320 }
321}
322
323impl Press for Wheel {}
324impl Release for Wheel {}
325
326impl Kind for Wheel {
327 fn kind(&self) -> c_int {
328 EV_KEY
329 }
330}
331
332impl Code for Wheel {
333 fn code(&self) -> c_int {
334 match self {
335 &Wheel::GearDown => BTN_GEAR_DOWN,
336 &Wheel::GearUp => BTN_GEAR_UP,
337 }
338 }
339}
340
341custom_derive! {
342 #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, IterVariants(DPadVariants))]
343 pub enum DPad {
344 Up,
345 Down,
346 Left,
347 Right,
348 }
349}
350
351impl Into<Event> for DPad {
352 fn into(self) -> Event {
353 Event::Controller(Controller::DPad(self))
354 }
355}
356
357impl Press for DPad {}
358impl Release for DPad {}
359
360impl Kind for DPad {
361 fn kind(&self) -> c_int {
362 EV_KEY
363 }
364}
365
366impl Code for DPad {
367 fn code(&self) -> c_int {
368 match self {
369 &DPad::Up => BTN_DPAD_UP,
370 &DPad::Down => BTN_DPAD_DOWN,
371 &DPad::Left => BTN_DPAD_LEFT,
372 &DPad::Right => BTN_DPAD_RIGHT,
373 }
374 }
375}
376
377custom_derive! {
378 #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, IterVariants(TriggerHappyVariants))]
379 pub enum TriggerHappy {
380 _1,
381 _2,
382 _3,
383 _4,
384 _5,
385 _6,
386 _7,
387 _8,
388 _9,
389 _10,
390 _11,
391 _12,
392 _13,
393 _14,
394 _15,
395 _16,
396 _17,
397 _18,
398 _19,
399 _20,
400 _21,
401 _22,
402 _23,
403 _24,
404 _25,
405 _26,
406 _27,
407 _28,
408 _29,
409 _30,
410 _31,
411 _32,
412 _33,
413 _34,
414 _35,
415 _36,
416 _37,
417 _38,
418 _39,
419 _40,
420 }
421}
422
423impl Into<Event> for TriggerHappy {
424 fn into(self) -> Event {
425 Event::Controller(Controller::TriggerHappy(self))
426 }
427}
428
429impl Press for TriggerHappy {}
430impl Release for TriggerHappy {}
431
432impl Kind for TriggerHappy {
433 fn kind(&self) -> c_int {
434 EV_KEY
435 }
436}
437
438impl Code for TriggerHappy {
439 fn code(&self) -> c_int {
440 match self {
441 &TriggerHappy::_1 => BTN_TRIGGER_HAPPY1,
442 &TriggerHappy::_2 => BTN_TRIGGER_HAPPY2,
443 &TriggerHappy::_3 => BTN_TRIGGER_HAPPY3,
444 &TriggerHappy::_4 => BTN_TRIGGER_HAPPY4,
445 &TriggerHappy::_5 => BTN_TRIGGER_HAPPY5,
446 &TriggerHappy::_6 => BTN_TRIGGER_HAPPY6,
447 &TriggerHappy::_7 => BTN_TRIGGER_HAPPY7,
448 &TriggerHappy::_8 => BTN_TRIGGER_HAPPY8,
449 &TriggerHappy::_9 => BTN_TRIGGER_HAPPY9,
450 &TriggerHappy::_10 => BTN_TRIGGER_HAPPY10,
451 &TriggerHappy::_11 => BTN_TRIGGER_HAPPY11,
452 &TriggerHappy::_12 => BTN_TRIGGER_HAPPY12,
453 &TriggerHappy::_13 => BTN_TRIGGER_HAPPY13,
454 &TriggerHappy::_14 => BTN_TRIGGER_HAPPY14,
455 &TriggerHappy::_15 => BTN_TRIGGER_HAPPY15,
456 &TriggerHappy::_16 => BTN_TRIGGER_HAPPY16,
457 &TriggerHappy::_17 => BTN_TRIGGER_HAPPY17,
458 &TriggerHappy::_18 => BTN_TRIGGER_HAPPY18,
459 &TriggerHappy::_19 => BTN_TRIGGER_HAPPY19,
460 &TriggerHappy::_20 => BTN_TRIGGER_HAPPY20,
461 &TriggerHappy::_21 => BTN_TRIGGER_HAPPY21,
462 &TriggerHappy::_22 => BTN_TRIGGER_HAPPY22,
463 &TriggerHappy::_23 => BTN_TRIGGER_HAPPY23,
464 &TriggerHappy::_24 => BTN_TRIGGER_HAPPY24,
465 &TriggerHappy::_25 => BTN_TRIGGER_HAPPY25,
466 &TriggerHappy::_26 => BTN_TRIGGER_HAPPY26,
467 &TriggerHappy::_27 => BTN_TRIGGER_HAPPY27,
468 &TriggerHappy::_28 => BTN_TRIGGER_HAPPY28,
469 &TriggerHappy::_29 => BTN_TRIGGER_HAPPY29,
470 &TriggerHappy::_30 => BTN_TRIGGER_HAPPY30,
471 &TriggerHappy::_31 => BTN_TRIGGER_HAPPY31,
472 &TriggerHappy::_32 => BTN_TRIGGER_HAPPY32,
473 &TriggerHappy::_33 => BTN_TRIGGER_HAPPY33,
474 &TriggerHappy::_34 => BTN_TRIGGER_HAPPY34,
475 &TriggerHappy::_35 => BTN_TRIGGER_HAPPY35,
476 &TriggerHappy::_36 => BTN_TRIGGER_HAPPY36,
477 &TriggerHappy::_37 => BTN_TRIGGER_HAPPY37,
478 &TriggerHappy::_38 => BTN_TRIGGER_HAPPY38,
479 &TriggerHappy::_39 => BTN_TRIGGER_HAPPY39,
480 &TriggerHappy::_40 => BTN_TRIGGER_HAPPY40,
481 }
482 }
483}