Mercurial > remote-gamepad-server
diff ds.c @ 0:e70ea46d6073
Initial import from http://wouhanegaine.free.fr/dev/DSPad02b_neo07.zip
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sun, 22 Feb 2015 01:38:06 +0100 |
parents | |
children | f362b20de51e |
line wrap: on
line diff
new file mode 100644 --- /dev/null +++ b/ds.c @@ -0,0 +1,80 @@ +#include "ds.h" +#include "uinput.h" +#include <stdint.h> +#include <string.h> + + +#include <stdio.h> + + +/* + Throws events according to ds keys status +*/ +void ds_process_evt(ds_t* ds, int uinput_fd){ + + 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); + + + /* 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)); + + return; +}