changeset 6:eafcd170dc6d

Add circle pad and c pad support, and provisional touch support.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 18 Aug 2015 02:07:48 +0100
parents c0223d75444d
children 6aa40a25de22
files ds.c ds.h service.c uinput.c uinput.h
diffstat 5 files changed, 56 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/ds.c
+++ b/ds.c
@@ -44,15 +44,21 @@ void ds_process_evt(ds_t* ds, int uinput
 
     /* DIRECTIONS */
 
-    /*
-    if(previous.aX != ds->aX)
-        do_uinput(uinput_fd, ABS_X, ds->aX, EV_ABS);
+    if(previous.pad.x != ds->pad.x)
+        do_uinput(uinput_fd, ABS_X, ds->pad.x, EV_ABS);
+
+    if(previous.pad.y != ds->pad.y)
+        do_uinput(uinput_fd, ABS_Y, ds->pad.y, EV_ABS);
 
-    if(previous.aY != ds->aY)
-        do_uinput(uinput_fd, ABS_Y, ds->aY, EV_ABS);
-    */
+    if(previous.cpad.x != ds->cpad.x)
+        do_uinput(uinput_fd, ABS_RX, ds->cpad.x, EV_ABS);
 
-    previous.hex = ds->hex;
+    if(previous.cpad.y != ds->cpad.y)
+        do_uinput(uinput_fd, ABS_RY, ds->cpad.y, EV_ABS);
+
+    flush_uinput(uinput_fd);
+
+    memcpy(&previous, ds, sizeof(ds_t));
 
     return;
 }
--- a/ds.h
+++ b/ds.h
@@ -5,8 +5,7 @@
 
 
 /* Describe Device */
-typedef union {
-    uint32_t hex;
+typedef struct {
     struct {
         uint32_t a:1;      /* Pressed or held buttons */
         uint32_t b:1;
@@ -24,7 +23,7 @@ typedef union {
         uint32_t zl:1;
         uint32_t zr:1;
         uint32_t padding2:4;
-        uint32_t touch:1;
+        uint32_t touched:1;
         uint32_t padding3:3;
         uint32_t c_right:1;
         uint32_t c_left:1;
@@ -34,8 +33,16 @@ typedef union {
         uint32_t circle_left:1;
         uint32_t circle_up:1;
         uint32_t circle_down:1;
-    } __attribute__((packed));
-} ds_t;
+    };
+    struct {
+        int16_t x;
+        int16_t y;
+    } pad, cpad;
+    struct {
+        uint16_t x;
+        uint16_t y;
+    } touch;
+} __attribute__((packed)) ds_t;
 
 
 /*
--- a/service.c
+++ b/service.c
@@ -114,8 +114,12 @@ void start_service(void){
 
 
     /* Center device axis when created */
-    do_uinput(uinput_fd, ABS_Y, DS_MAX_Y/2, EV_ABS);
-    do_uinput(uinput_fd, ABS_X, DS_MAX_X/2, EV_ABS);
+    do_uinput(uinput_fd, ABS_X, 0, EV_ABS);
+    do_uinput(uinput_fd, ABS_Y, 0, EV_ABS);
+    do_uinput(uinput_fd, ABS_RX, 0, EV_ABS);
+    do_uinput(uinput_fd, ABS_RY, 0, EV_ABS);
+    //do_uinput(uinput_fd, ABS_TOUCH_X, (TOUCH_MAX_X - TOUCH_MIN_X) / 2, EV_ABS);
+    //do_uinput(uinput_fd, ABS_TOUCH_Y, (TOUCH_MAX_Y - TOUCH_MIN_Y) / 2, EV_ABS);
 
     while(1){
         result = receive_ds_info(sock_fd, &ds);
--- a/uinput.c
+++ b/uinput.c
@@ -52,17 +52,30 @@ int init_uinput_device(void){
     dev.id.product = DS_PRODUCT;
     dev.id.version = DS_VERSION;
 
-    dev.absmax[ABS_X]  = DS_MAX_X;
-    dev.absmin[ABS_X]  = DS_MIN_X;
+    // Circle pad
+    dev.absmax[ABS_X]  = PAD_MAX;
+    dev.absmin[ABS_X]  = -PAD_MAX;
     dev.absfuzz[ABS_X] = 4;
     dev.absflat[ABS_X] = 2;
 
-    dev.absmax[ABS_Y]  = DS_MAX_Y;
-    dev.absmin[ABS_Y]  = DS_MIN_Y;
+    dev.absmax[ABS_Y]  = PAD_MAX;
+    dev.absmin[ABS_Y]  = -PAD_MAX;
     dev.absfuzz[ABS_Y] = 4;
     dev.absflat[ABS_Y] = 2;
 
 
+    // C pad
+    dev.absmax[ABS_RX]  = PAD_MAX;
+    dev.absmin[ABS_RX]  = -PAD_MAX;
+    dev.absfuzz[ABS_RX] = 4;
+    dev.absflat[ABS_RX] = 2;
+
+    dev.absmax[ABS_RY]  = PAD_MAX;
+    dev.absmin[ABS_RY]  = -PAD_MAX;
+    dev.absfuzz[ABS_RY] = 4;
+    dev.absflat[ABS_RY] = 2;
+
+
     if(write(fd, &dev, sizeof(dev)) < (ssize_t)sizeof(dev)){
         fprintf(stderr, " [%d]  Registering device at uinput failed\n", curdev);
         return -1;
@@ -89,6 +102,8 @@ int init_uinput_device(void){
     if( ioctl(fd, UI_SET_EVBIT,  EV_ABS)    ) return -1;
     if( ioctl(fd, UI_SET_ABSBIT, ABS_X)     ) return -1;
     if( ioctl(fd, UI_SET_ABSBIT, ABS_Y)     ) return -1;
+    if( ioctl(fd, UI_SET_ABSBIT, ABS_RX)    ) return -1;
+    if( ioctl(fd, UI_SET_ABSBIT, ABS_RY)    ) return -1;
 
 
     /* Register device */
--- a/uinput.h
+++ b/uinput.h
@@ -5,10 +5,12 @@
 #include <linux/input.h>
 #include <linux/uinput.h>
 
-#define DS_MIN_X    0
-#define DS_MAX_X    255
-#define DS_MIN_Y    0
-#define DS_MAX_Y    191
+#define PAD_MAX        156
+
+#define TOUCH_MIN_X    0
+#define TOUCH_MAX_X    319
+#define TOUCH_MIN_Y    0
+#define TOUCH_MAX_Y    239
 
 
 /*