view ds.c @ 2:f362b20de51e

Remove trailing whitespaces.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 22 Feb 2015 18:03:26 +0100
parents e70ea46d6073
children 73c20831be0a
line wrap: on
line source

#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;
}