From 04e44b9f1c1b65198ea1ac883dcd9f153933413d Mon Sep 17 00:00:00 2001 From: Mike Turvey Date: Tue, 2 Jan 2018 21:37:57 -0700 Subject: Capturing Button Inputs Currently only working on Windows over USB interface Inputs are only printed out, still need to propagate them up the stack. Buttons are placed in a queue, and "processed" on a different thread to avoid starvation. --- include/libsurvive/survive.h | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/libsurvive/survive.h b/include/libsurvive/survive.h index c4b2abe..f3a17c8 100644 --- a/include/libsurvive/survive.h +++ b/include/libsurvive/survive.h @@ -4,6 +4,7 @@ #include #include "survive_types.h" #include "poser.h" +#include "os_generic.h" #ifdef __cplusplus extern "C" { @@ -18,7 +19,7 @@ struct SurviveObject char codename[4]; //3 letters, null-terminated. Currently HMD, WM0, WM1. char drivername[4]; //3 letters for driver. Currently "HTC" - int16_t buttonmask; + int32_t buttonmask; int16_t axis1; int16_t axis2; @@ -90,6 +91,37 @@ struct BaseStationData struct config_group; +#define BUTTON_QUEUE_MAX_LEN 32 + +#define BUTTON_EVENT_BUTTON_NONE 0 +#define BUTTON_EVENT_BUTTON_DOWN 1 +#define BUTTON_EVENT_BUTTON_UP 2 +#define BUTTON_EVENT_AXIS_CHANGED 3 + +// note: buttonId and axisId are 1-indexed values. +// a value of 0 for an id means that no data is present in that value +// additionally, when x and y values are both present in axis data, +// axis1 will be x, axis2 will be y. +typedef struct +{ + uint8_t isPopulated; //probably can remove this given the semaphore in the parent struct. helps with debugging + uint8_t eventType; + uint8_t buttonId; + uint8_t axis1Id; + uint16_t axis1Val; + uint8_t axis2Id; + uint16_t axis2Val; + SurviveObject *so; +} ButtonQueueEntry; + +typedef struct +{ + uint8_t nextReadIndex; //init to 0 + uint8_t nextWriteIndex; // init to 0 + og_sema_t buttonservicesem; + ButtonQueueEntry entry[BUTTON_QUEUE_MAX_LEN]; +} ButtonQueue; + struct SurviveContext { text_feedback_func faultfunction; @@ -114,6 +146,12 @@ struct SurviveContext DeviceDriverCb * drivercloses; DeviceDriverMagicCb * drivermagics; int driver_ct; + + uint8_t isClosing; // flag to indicate if threads should terminate themselves + + og_thread_t buttonservicethread; + ButtonQueue buttonQueue; + }; SurviveContext * survive_init( int headless ); -- cgit v1.2.3