Mercurial > remote-gamepad-server
view ds.c @ 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 | 73c20831be0a |
children | 6aa40a25de22 |
line wrap: on
line source
#include "ds.h" #include "uinput.h" #include <stdint.h> #include <string.h> #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 */ void ds_process_evt(ds_t* ds, int uinput_fd){ static ds_t previous; /* BUTTONS: */ 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.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.cpad.x != ds->cpad.x) do_uinput(uinput_fd, ABS_RX, ds->cpad.x, EV_ABS); 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; }