diff 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
line wrap: on
line diff
--- a/ds.c
+++ b/ds.c
@@ -7,6 +7,18 @@
 #include <stdio.h>
 
 
+#define maybe_do_uinput(button, uinput_button) \
+do { \
+    if (!previous.button && ds->button) { \
+        printf("Button " #uinput_button " pressed.\n"); \
+        do_uinput(uinput_fd, uinput_button, 1, EV_KEY); \
+    } else if (previous.button && !ds->button) { \
+        printf("Button " #uinput_button " released.\n"); \
+        do_uinput(uinput_fd, uinput_button, 0, EV_KEY); \
+    } \
+} while(0)
+
+
 /*
     Throws events according to ds keys status
 */
@@ -14,67 +26,33 @@ void ds_process_evt(ds_t* ds, int uinput
 
     static ds_t previous;
 
-    /* Fear the evil copy/paste!! */
-
-
     /* BUTTONS: */
-    if( !previous.A && ds->A )    /* pressed */
-        do_uinput(uinput_fd, BTN_A, 1, EV_KEY);
-    else if( previous.A && !ds->A )   /* released */
-        do_uinput(uinput_fd, BTN_A, 0, EV_KEY);
-
-
-    if( !previous.B && ds->B )
-        do_uinput(uinput_fd, BTN_B, 1, EV_KEY);
-    else if( previous.B && !ds->B )
-        do_uinput(uinput_fd, BTN_B, 0, EV_KEY);
-
-
-    if( !previous.X && ds->X )
-        do_uinput(uinput_fd, BTN_X, 1, EV_KEY);
-    else if( previous.X && !ds->X )
-        do_uinput(uinput_fd, BTN_X, 0, EV_KEY);
-
-
-    if( !previous.Y && ds->Y )
-        do_uinput(uinput_fd, BTN_Y, 1, EV_KEY);
-    else if( previous.Y && !ds->Y )
-        do_uinput(uinput_fd, BTN_Y, 0, EV_KEY);
-
-
-    if( !previous.L && ds->L )
-        do_uinput(uinput_fd, BTN_TL, 1, EV_KEY);
-    else if( (previous.L) && !(ds->L) )
-        do_uinput(uinput_fd, BTN_TL, 0, EV_KEY);
-
-
-    if( !previous.R && ds->R )
-        do_uinput(uinput_fd, BTN_TR, 1, EV_KEY);
-    else if( previous.R && !ds->R )
-        do_uinput(uinput_fd, BTN_TR, 0, EV_KEY);
-
-
-    if( !previous.Start && ds->Start )
-        do_uinput(uinput_fd, BTN_START, 1, EV_KEY);
-    else if( previous.Start && !ds->Start )
-        do_uinput(uinput_fd, BTN_START, 0, EV_KEY);
-
-
-    if( !previous.Select && ds->Select )
-        do_uinput(uinput_fd, BTN_SELECT, 1, EV_KEY);
-    else if( previous.Select && !ds->Select )
-        do_uinput(uinput_fd, BTN_SELECT, 0, EV_KEY);
-
+    maybe_do_uinput(a, BTN_A);
+    maybe_do_uinput(b, BTN_B);
+    maybe_do_uinput(x, BTN_X);
+    maybe_do_uinput(y, BTN_Y);
+    maybe_do_uinput(l, BTN_TL);
+    maybe_do_uinput(r, BTN_TR);
+    maybe_do_uinput(zl, BTN_TL2);
+    maybe_do_uinput(zr, BTN_TR2);
+    maybe_do_uinput(start, BTN_START);
+    maybe_do_uinput(select, BTN_SELECT);
+    maybe_do_uinput(up, BTN_DPAD_UP);
+    maybe_do_uinput(down, BTN_DPAD_DOWN);
+    maybe_do_uinput(left, BTN_DPAD_LEFT);
+    maybe_do_uinput(right, BTN_DPAD_RIGHT);
 
     /* DIRECTIONS */
 
+    /*
     if(previous.aX != ds->aX)
         do_uinput(uinput_fd, ABS_X, ds->aX, EV_ABS);
 
     if(previous.aY != ds->aY)
         do_uinput(uinput_fd, ABS_Y, ds->aY, EV_ABS);
+    */
 
-    memcpy(&previous, ds, sizeof(ds_t));
+    previous.hex = ds->hex;
 
     return;
 }