comparison ds.c @ 7:6aa40a25de22

Remove debug and add an assert on the size of the received struct.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 18 Aug 2015 02:08:29 +0100
parents eafcd170dc6d
children
comparison
equal deleted inserted replaced
6:eafcd170dc6d 7:6aa40a25de22
1 #include "ds.h" 1 #include "ds.h"
2 #include "uinput.h" 2 #include "uinput.h"
3 #include <assert.h>
3 #include <stdint.h> 4 #include <stdint.h>
4 #include <string.h> 5 #include <string.h>
5 6
6 7
7 #include <stdio.h> 8 #include <stdio.h>
8 9
9 10
10 #define maybe_do_uinput(button, uinput_button) \ 11 #define maybe_do_uinput(button, uinput_button) \
11 do { \ 12 do { \
12 if (!previous.button && ds->button) { \ 13 if (!previous.button && ds->button) \
13 printf("Button " #uinput_button " pressed.\n"); \
14 do_uinput(uinput_fd, uinput_button, 1, EV_KEY); \ 14 do_uinput(uinput_fd, uinput_button, 1, EV_KEY); \
15 } else if (previous.button && !ds->button) { \ 15 else if (previous.button && !ds->button) \
16 printf("Button " #uinput_button " released.\n"); \
17 do_uinput(uinput_fd, uinput_button, 0, EV_KEY); \ 16 do_uinput(uinput_fd, uinput_button, 0, EV_KEY); \
18 } \
19 } while(0) 17 } while(0)
20 18
21 19
22 /* 20 /*
23 Throws events according to ds keys status 21 Throws events according to ds keys status
24 */ 22 */
25 void ds_process_evt(ds_t* ds, int uinput_fd){ 23 void ds_process_evt(ds_t* ds, int uinput_fd){
26 24
27 static ds_t previous; 25 static ds_t previous;
26
27 assert(8 == sizeof(ds_t));
28 28
29 /* BUTTONS: */ 29 /* BUTTONS: */
30 maybe_do_uinput(a, BTN_A); 30 maybe_do_uinput(a, BTN_A);
31 maybe_do_uinput(b, BTN_B); 31 maybe_do_uinput(b, BTN_B);
32 maybe_do_uinput(x, BTN_X); 32 maybe_do_uinput(x, BTN_X);