view ds.c @ 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 f362b20de51e
children eafcd170dc6d
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.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);
    */

    previous.hex = ds->hex;

    return;
}