aboutsummaryrefslogtreecommitdiff
path: root/src/control.c
blob: 440ede7ee007d1cae0ba87a6df5b1de7fffbe356 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <stdint.h>

#include "ubox_keyb.h"
#include "ubox_joy.h"

#include "ubox_control.h"

static uint8_t joy = 0;

void ubox_control_init()
{
    joy = ubox_joy_detect();
}

uint8_t ubox_control_read()
{
    uint8_t r = UBOX_CTL_NONE;

    if (ubox_keys[UBOX_KEY_UP])
        r |= UBOX_CTL_UP;
    if (ubox_keys[UBOX_KEY_DOWN])
        r |= UBOX_CTL_DOWN;
    if (ubox_keys[UBOX_KEY_LEFT])
        r |= UBOX_CTL_LEFT;
    if (ubox_keys[UBOX_KEY_RIGHT])
        r |= UBOX_CTL_RIGHT;
    if (ubox_keys[UBOX_KEY_Z])
        r |= UBOX_CTL_FIRE1;
    if (ubox_keys[UBOX_KEY_X])
        r |= UBOX_CTL_FIRE2;

    if (joy)
        r |= ubox_joy_read();

    return r;
}