Mercurial > remote-gamepad-server
view ds.c @ 9:5e15d64a2d24 default tip
If somebody closed stdin, fd could be both valid and 0, don’t check for that.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Tue, 18 Aug 2015 02:09:55 +0100 |
parents | 6aa40a25de22 |
children |
line wrap: on
line source
#include "ds.h" #include "uinput.h" #include <assert.h> #include <stdint.h> #include <string.h> #include <stdio.h> #define maybe_do_uinput(button, uinput_button) \ do { \ if (!previous.button && ds->button) \ do_uinput(uinput_fd, uinput_button, 1, EV_KEY); \ else if (previous.button && !ds->button) \ 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; assert(8 == sizeof(ds_t)); /* 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; }