From e35cff6d299a07d9b34f303717083a9299a37e82 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Mon, 28 Aug 2023 15:16:12 +0100 Subject: Initial import --- src/control.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/control.c (limited to 'src/control.c') diff --git a/src/control.c b/src/control.c new file mode 100644 index 0000000..440ede7 --- /dev/null +++ b/src/control.c @@ -0,0 +1,36 @@ +#include + +#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; +} -- cgit v1.2.3