Mercurial > remote-gamepad-server
changeset 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 | 61bb81a9a440 |
children | c0223d75444d |
files | ds.c ds.h uinput.c |
diffstat | 3 files changed, 69 insertions(+), 66 deletions(-) [+] |
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; }
--- a/ds.h +++ b/ds.h @@ -5,18 +5,37 @@ /* Describe Device */ -typedef struct ds_s{ - uint8_t A:1; /* Pressed or held buttons */ - uint8_t B:1; - uint8_t X:1; - uint8_t Y:1; - uint8_t L:1; - uint8_t R:1; - uint8_t Start:1; - uint8_t Select:1; - uint8_t aX; - uint8_t aY; -} __attribute__((packed)) ds_t; +typedef union { + uint32_t hex; + struct { + uint32_t a:1; /* Pressed or held buttons */ + uint32_t b:1; + uint32_t select:1; + uint32_t start:1; + uint32_t right:1; + uint32_t left:1; + uint32_t up:1; + uint32_t down:1; + uint32_t r:1; + uint32_t l:1; + uint32_t x:1; + uint32_t y:1; + uint32_t padding1:2; + uint32_t zl:1; + uint32_t zr:1; + uint32_t padding2:4; + uint32_t touch:1; + uint32_t padding3:3; + uint32_t c_right:1; + uint32_t c_left:1; + uint32_t c_up:1; + uint32_t c_down:1; + uint32_t circle_right:1; + uint32_t circle_left:1; + uint32_t circle_up:1; + uint32_t circle_down:1; + } __attribute__((packed)); +} ds_t; /*
--- a/uinput.c +++ b/uinput.c @@ -10,7 +10,7 @@ #include <stdbool.h> -#define DS_NAME "NintendoDS Wireless Gamepad" +#define DS_NAME "Nintendo 3DS" /* Not found these values... but it's not important! */ #define DS_VENDOR 0xdead @@ -59,8 +59,8 @@ int init_uinput_device(void){ dev.absmax[ABS_Y] = DS_MAX_Y; dev.absmin[ABS_Y] = DS_MIN_Y; - dev.absfuzz[ABS_X] = 4; - dev.absflat[ABS_X] = 2; + dev.absfuzz[ABS_Y] = 4; + dev.absflat[ABS_Y] = 2; if(write(fd, &dev, sizeof(dev)) < (ssize_t)sizeof(dev)){ @@ -76,8 +76,14 @@ int init_uinput_device(void){ if( ioctl(fd, UI_SET_KEYBIT, BTN_Y) ) return -1; if( ioctl(fd, UI_SET_KEYBIT, BTN_TL) ) return -1; if( ioctl(fd, UI_SET_KEYBIT, BTN_TR) ) return -1; + if( ioctl(fd, UI_SET_KEYBIT, BTN_TL2) ) return -1; + if( ioctl(fd, UI_SET_KEYBIT, BTN_TR2) ) return -1; if( ioctl(fd, UI_SET_KEYBIT, BTN_START) ) return -1; if( ioctl(fd, UI_SET_KEYBIT, BTN_SELECT)) return -1; + if( ioctl(fd, UI_SET_KEYBIT, BTN_DPAD_UP)) return -1; + if( ioctl(fd, UI_SET_KEYBIT, BTN_DPAD_DOWN)) return -1; + if( ioctl(fd, UI_SET_KEYBIT, BTN_DPAD_LEFT)) return -1; + if( ioctl(fd, UI_SET_KEYBIT, BTN_DPAD_RIGHT)) return -1; /* D-Pad [-0xFFFF - 0xFFFF] */ if( ioctl(fd, UI_SET_EVBIT, EV_ABS) ) return -1;