annotate ds.c @ 8:dec5fe6cd0d0

Open the uinput device in write-only, and display every error.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 18 Aug 2015 02:09:15 +0100
parents 6aa40a25de22
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
e70ea46d6073 Initial import from http://wouhanegaine.free.fr/dev/DSPad02b_neo07.zip
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1 #include "ds.h"
e70ea46d6073 Initial import from http://wouhanegaine.free.fr/dev/DSPad02b_neo07.zip
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
2 #include "uinput.h"
7
6aa40a25de22 Remove debug and add an assert on the size of the received struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 6
diff changeset
3 #include <assert.h>
0
e70ea46d6073 Initial import from http://wouhanegaine.free.fr/dev/DSPad02b_neo07.zip
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
4 #include <stdint.h>
e70ea46d6073 Initial import from http://wouhanegaine.free.fr/dev/DSPad02b_neo07.zip
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
5 #include <string.h>
e70ea46d6073 Initial import from http://wouhanegaine.free.fr/dev/DSPad02b_neo07.zip
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
6
e70ea46d6073 Initial import from http://wouhanegaine.free.fr/dev/DSPad02b_neo07.zip
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
7
e70ea46d6073 Initial import from http://wouhanegaine.free.fr/dev/DSPad02b_neo07.zip
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
8 #include <stdio.h>
e70ea46d6073 Initial import from http://wouhanegaine.free.fr/dev/DSPad02b_neo07.zip
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
9
e70ea46d6073 Initial import from http://wouhanegaine.free.fr/dev/DSPad02b_neo07.zip
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
10
4
73c20831be0a Replace DS input with 3DS, for now disable axis input.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 2
diff changeset
11 #define maybe_do_uinput(button, uinput_button) \
73c20831be0a Replace DS input with 3DS, for now disable axis input.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 2
diff changeset
12 do { \
7
6aa40a25de22 Remove debug and add an assert on the size of the received struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 6
diff changeset
13 if (!previous.button && ds->button) \
4
73c20831be0a Replace DS input with 3DS, for now disable axis input.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 2
diff changeset
14 do_uinput(uinput_fd, uinput_button, 1, EV_KEY); \
7
6aa40a25de22 Remove debug and add an assert on the size of the received struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 6
diff changeset
15 else if (previous.button && !ds->button) \
4
73c20831be0a Replace DS input with 3DS, for now disable axis input.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 2
diff changeset
16 do_uinput(uinput_fd, uinput_button, 0, EV_KEY); \
73c20831be0a Replace DS input with 3DS, for now disable axis input.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 2
diff changeset
17 } while(0)
73c20831be0a Replace DS input with 3DS, for now disable axis input.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 2
diff changeset
18
73c20831be0a Replace DS input with 3DS, for now disable axis input.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 2
diff changeset
19
0
e70ea46d6073 Initial import from http://wouhanegaine.free.fr/dev/DSPad02b_neo07.zip
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
20 /*
e70ea46d6073 Initial import from http://wouhanegaine.free.fr/dev/DSPad02b_neo07.zip
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
21 Throws events according to ds keys status
e70ea46d6073 Initial import from http://wouhanegaine.free.fr/dev/DSPad02b_neo07.zip
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
22 */
e70ea46d6073 Initial import from http://wouhanegaine.free.fr/dev/DSPad02b_neo07.zip
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
23 void ds_process_evt(ds_t* ds, int uinput_fd){
e70ea46d6073 Initial import from http://wouhanegaine.free.fr/dev/DSPad02b_neo07.zip
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
24
e70ea46d6073 Initial import from http://wouhanegaine.free.fr/dev/DSPad02b_neo07.zip
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
25 static ds_t previous;
e70ea46d6073 Initial import from http://wouhanegaine.free.fr/dev/DSPad02b_neo07.zip
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
26
7
6aa40a25de22 Remove debug and add an assert on the size of the received struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 6
diff changeset
27 assert(8 == sizeof(ds_t));
6aa40a25de22 Remove debug and add an assert on the size of the received struct.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 6
diff changeset
28
0
e70ea46d6073 Initial import from http://wouhanegaine.free.fr/dev/DSPad02b_neo07.zip
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
29 /* BUTTONS: */
4
73c20831be0a Replace DS input with 3DS, for now disable axis input.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 2
diff changeset
30 maybe_do_uinput(a, BTN_A);
73c20831be0a Replace DS input with 3DS, for now disable axis input.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 2
diff changeset
31 maybe_do_uinput(b, BTN_B);
73c20831be0a Replace DS input with 3DS, for now disable axis input.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 2
diff changeset
32 maybe_do_uinput(x, BTN_X);
73c20831be0a Replace DS input with 3DS, for now disable axis input.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 2
diff changeset
33 maybe_do_uinput(y, BTN_Y);
73c20831be0a Replace DS input with 3DS, for now disable axis input.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 2
diff changeset
34 maybe_do_uinput(l, BTN_TL);
73c20831be0a Replace DS input with 3DS, for now disable axis input.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 2
diff changeset
35 maybe_do_uinput(r, BTN_TR);
73c20831be0a Replace DS input with 3DS, for now disable axis input.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 2
diff changeset
36 maybe_do_uinput(zl, BTN_TL2);
73c20831be0a Replace DS input with 3DS, for now disable axis input.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 2
diff changeset
37 maybe_do_uinput(zr, BTN_TR2);
73c20831be0a Replace DS input with 3DS, for now disable axis input.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 2
diff changeset
38 maybe_do_uinput(start, BTN_START);
73c20831be0a Replace DS input with 3DS, for now disable axis input.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 2
diff changeset
39 maybe_do_uinput(select, BTN_SELECT);
73c20831be0a Replace DS input with 3DS, for now disable axis input.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 2
diff changeset
40 maybe_do_uinput(up, BTN_DPAD_UP);
73c20831be0a Replace DS input with 3DS, for now disable axis input.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 2
diff changeset
41 maybe_do_uinput(down, BTN_DPAD_DOWN);
73c20831be0a Replace DS input with 3DS, for now disable axis input.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 2
diff changeset
42 maybe_do_uinput(left, BTN_DPAD_LEFT);
73c20831be0a Replace DS input with 3DS, for now disable axis input.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 2
diff changeset
43 maybe_do_uinput(right, BTN_DPAD_RIGHT);
0
e70ea46d6073 Initial import from http://wouhanegaine.free.fr/dev/DSPad02b_neo07.zip
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
44
e70ea46d6073 Initial import from http://wouhanegaine.free.fr/dev/DSPad02b_neo07.zip
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
45 /* DIRECTIONS */
2
f362b20de51e Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
46
6
eafcd170dc6d Add circle pad and c pad support, and provisional touch support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
47 if(previous.pad.x != ds->pad.x)
eafcd170dc6d Add circle pad and c pad support, and provisional touch support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
48 do_uinput(uinput_fd, ABS_X, ds->pad.x, EV_ABS);
eafcd170dc6d Add circle pad and c pad support, and provisional touch support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
49
eafcd170dc6d Add circle pad and c pad support, and provisional touch support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
50 if(previous.pad.y != ds->pad.y)
eafcd170dc6d Add circle pad and c pad support, and provisional touch support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
51 do_uinput(uinput_fd, ABS_Y, ds->pad.y, EV_ABS);
2
f362b20de51e Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
52
6
eafcd170dc6d Add circle pad and c pad support, and provisional touch support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
53 if(previous.cpad.x != ds->cpad.x)
eafcd170dc6d Add circle pad and c pad support, and provisional touch support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
54 do_uinput(uinput_fd, ABS_RX, ds->cpad.x, EV_ABS);
2
f362b20de51e Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
55
6
eafcd170dc6d Add circle pad and c pad support, and provisional touch support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
56 if(previous.cpad.y != ds->cpad.y)
eafcd170dc6d Add circle pad and c pad support, and provisional touch support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
57 do_uinput(uinput_fd, ABS_RY, ds->cpad.y, EV_ABS);
eafcd170dc6d Add circle pad and c pad support, and provisional touch support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
58
eafcd170dc6d Add circle pad and c pad support, and provisional touch support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
59 flush_uinput(uinput_fd);
eafcd170dc6d Add circle pad and c pad support, and provisional touch support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
60
eafcd170dc6d Add circle pad and c pad support, and provisional touch support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 4
diff changeset
61 memcpy(&previous, ds, sizeof(ds_t));
2
f362b20de51e Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 0
diff changeset
62
0
e70ea46d6073 Initial import from http://wouhanegaine.free.fr/dev/DSPad02b_neo07.zip
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
63 return;
e70ea46d6073 Initial import from http://wouhanegaine.free.fr/dev/DSPad02b_neo07.zip
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
64 }