Mercurial > remote-gamepad-server
comparison ds.c @ 4:73c20831be0a
Replace DS input with 3DS, for now disable axis input.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sun, 22 Feb 2015 18:09:53 +0100 |
parents | f362b20de51e |
children | eafcd170dc6d |
comparison
equal
deleted
inserted
replaced
3:61bb81a9a440 | 4:73c20831be0a |
---|---|
5 | 5 |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 | 8 |
9 | 9 |
10 #define maybe_do_uinput(button, uinput_button) \ | |
11 do { \ | |
12 if (!previous.button && ds->button) { \ | |
13 printf("Button " #uinput_button " pressed.\n"); \ | |
14 do_uinput(uinput_fd, uinput_button, 1, EV_KEY); \ | |
15 } else if (previous.button && !ds->button) { \ | |
16 printf("Button " #uinput_button " released.\n"); \ | |
17 do_uinput(uinput_fd, uinput_button, 0, EV_KEY); \ | |
18 } \ | |
19 } while(0) | |
20 | |
21 | |
10 /* | 22 /* |
11 Throws events according to ds keys status | 23 Throws events according to ds keys status |
12 */ | 24 */ |
13 void ds_process_evt(ds_t* ds, int uinput_fd){ | 25 void ds_process_evt(ds_t* ds, int uinput_fd){ |
14 | 26 |
15 static ds_t previous; | 27 static ds_t previous; |
16 | 28 |
17 /* Fear the evil copy/paste!! */ | |
18 | |
19 | |
20 /* BUTTONS: */ | 29 /* BUTTONS: */ |
21 if( !previous.A && ds->A ) /* pressed */ | 30 maybe_do_uinput(a, BTN_A); |
22 do_uinput(uinput_fd, BTN_A, 1, EV_KEY); | 31 maybe_do_uinput(b, BTN_B); |
23 else if( previous.A && !ds->A ) /* released */ | 32 maybe_do_uinput(x, BTN_X); |
24 do_uinput(uinput_fd, BTN_A, 0, EV_KEY); | 33 maybe_do_uinput(y, BTN_Y); |
25 | 34 maybe_do_uinput(l, BTN_TL); |
26 | 35 maybe_do_uinput(r, BTN_TR); |
27 if( !previous.B && ds->B ) | 36 maybe_do_uinput(zl, BTN_TL2); |
28 do_uinput(uinput_fd, BTN_B, 1, EV_KEY); | 37 maybe_do_uinput(zr, BTN_TR2); |
29 else if( previous.B && !ds->B ) | 38 maybe_do_uinput(start, BTN_START); |
30 do_uinput(uinput_fd, BTN_B, 0, EV_KEY); | 39 maybe_do_uinput(select, BTN_SELECT); |
31 | 40 maybe_do_uinput(up, BTN_DPAD_UP); |
32 | 41 maybe_do_uinput(down, BTN_DPAD_DOWN); |
33 if( !previous.X && ds->X ) | 42 maybe_do_uinput(left, BTN_DPAD_LEFT); |
34 do_uinput(uinput_fd, BTN_X, 1, EV_KEY); | 43 maybe_do_uinput(right, BTN_DPAD_RIGHT); |
35 else if( previous.X && !ds->X ) | |
36 do_uinput(uinput_fd, BTN_X, 0, EV_KEY); | |
37 | |
38 | |
39 if( !previous.Y && ds->Y ) | |
40 do_uinput(uinput_fd, BTN_Y, 1, EV_KEY); | |
41 else if( previous.Y && !ds->Y ) | |
42 do_uinput(uinput_fd, BTN_Y, 0, EV_KEY); | |
43 | |
44 | |
45 if( !previous.L && ds->L ) | |
46 do_uinput(uinput_fd, BTN_TL, 1, EV_KEY); | |
47 else if( (previous.L) && !(ds->L) ) | |
48 do_uinput(uinput_fd, BTN_TL, 0, EV_KEY); | |
49 | |
50 | |
51 if( !previous.R && ds->R ) | |
52 do_uinput(uinput_fd, BTN_TR, 1, EV_KEY); | |
53 else if( previous.R && !ds->R ) | |
54 do_uinput(uinput_fd, BTN_TR, 0, EV_KEY); | |
55 | |
56 | |
57 if( !previous.Start && ds->Start ) | |
58 do_uinput(uinput_fd, BTN_START, 1, EV_KEY); | |
59 else if( previous.Start && !ds->Start ) | |
60 do_uinput(uinput_fd, BTN_START, 0, EV_KEY); | |
61 | |
62 | |
63 if( !previous.Select && ds->Select ) | |
64 do_uinput(uinput_fd, BTN_SELECT, 1, EV_KEY); | |
65 else if( previous.Select && !ds->Select ) | |
66 do_uinput(uinput_fd, BTN_SELECT, 0, EV_KEY); | |
67 | |
68 | 44 |
69 /* DIRECTIONS */ | 45 /* DIRECTIONS */ |
70 | 46 |
47 /* | |
71 if(previous.aX != ds->aX) | 48 if(previous.aX != ds->aX) |
72 do_uinput(uinput_fd, ABS_X, ds->aX, EV_ABS); | 49 do_uinput(uinput_fd, ABS_X, ds->aX, EV_ABS); |
73 | 50 |
74 if(previous.aY != ds->aY) | 51 if(previous.aY != ds->aY) |
75 do_uinput(uinput_fd, ABS_Y, ds->aY, EV_ABS); | 52 do_uinput(uinput_fd, ABS_Y, ds->aY, EV_ABS); |
53 */ | |
76 | 54 |
77 memcpy(&previous, ds, sizeof(ds_t)); | 55 previous.hex = ds->hex; |
78 | 56 |
79 return; | 57 return; |
80 } | 58 } |