aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Turvey <mturvey6@gmail.com>2018-01-03 18:58:43 -0700
committerMike Turvey <mturvey6@gmail.com>2018-01-03 18:59:48 -0700
commitf183aa480c549695ac5b481fade04e62f71d1e0a (patch)
tree63e956b42d54b12f7d7c943023c4e587ebad50b1
parentffb879d7a69c3c38937ff0159de0a5d1db99b713 (diff)
downloadlibsurvive-f183aa480c549695ac5b481fade04e62f71d1e0a.tar.gz
libsurvive-f183aa480c549695ac5b481fade04e62f71d1e0a.tar.bz2
Controller Buttons Fully Implemented
Fully plumbed support for controller buttons Also, commented haptic call because it messed with the vive_magic calls, given where I had it.
-rw-r--r--include/libsurvive/survive.h8
-rw-r--r--include/libsurvive/survive_types.h8
-rwxr-xr-xsrc/survive.c36
-rw-r--r--src/survive_process.c11
-rwxr-xr-xsrc/survive_vive.c28
5 files changed, 65 insertions, 26 deletions
diff --git a/include/libsurvive/survive.h b/include/libsurvive/survive.h
index f3a17c8..e4afadf 100644
--- a/include/libsurvive/survive.h
+++ b/include/libsurvive/survive.h
@@ -93,10 +93,7 @@ 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
@@ -129,6 +126,7 @@ struct SurviveContext
light_process_func lightproc;
imu_process_func imuproc;
angle_process_func angleproc;
+ button_process_func buttonproc;
struct config_group* global_config_values;
struct config_group* lh_config; //lighthouse configs
@@ -163,6 +161,7 @@ void survive_install_error_fn( SurviveContext * ctx, text_feedback_func fbp );
void survive_install_light_fn( SurviveContext * ctx, light_process_func fbp );
void survive_install_imu_fn( SurviveContext * ctx, imu_process_func fbp );
void survive_install_angle_fn( SurviveContext * ctx, angle_process_func fbp );
+void survive_install_button_fn( SurviveContext * ctx, button_process_func fbp );
void survive_close( SurviveContext * ctx );
int survive_poll( SurviveContext * ctx );
@@ -185,6 +184,7 @@ int survive_cal_get_status( struct SurviveContext * ctx, char * description, int
void survive_default_light_process( SurviveObject * so, int sensor_id, int acode, int timeinsweep, uint32_t timecode, uint32_t length , uint32_t lh);
void survive_default_imu_process( SurviveObject * so, int mode, FLT * accelgyro, uint32_t timecode, int id );
void survive_default_angle_process( SurviveObject * so, int sensor_id, int acode, uint32_t timecode, FLT length, FLT angle, uint32_t lh );
+void survive_default_button_process(SurviveObject * so, uint8_t eventType, uint8_t buttonId, uint8_t axis1Id, uint16_t axis1Val, uint8_t axis2Id, uint16_t axis2Val);
////////////////////// Survive Drivers ////////////////////////////
diff --git a/include/libsurvive/survive_types.h b/include/libsurvive/survive_types.h
index 224719e..fa3eb2f 100644
--- a/include/libsurvive/survive_types.h
+++ b/include/libsurvive/survive_types.h
@@ -27,6 +27,12 @@ typedef struct SurvivePose
#define INTBUFFSIZE 64
#define SENSORS_PER_OBJECT 32
+// These are used for the eventType of button_process_func
+#define BUTTON_EVENT_BUTTON_NONE 0
+#define BUTTON_EVENT_BUTTON_DOWN 1
+#define BUTTON_EVENT_BUTTON_UP 2
+#define BUTTON_EVENT_AXIS_CHANGED 3
+
typedef struct SurviveObject SurviveObject;
typedef struct SurviveContext SurviveContext;
typedef struct BaseStationData BaseStationData;
@@ -36,7 +42,7 @@ typedef void (*text_feedback_func)( SurviveContext * ctx, const char * fault );
typedef void (*light_process_func)( SurviveObject * so, int sensor_id, int acode, int timeinsweep, uint32_t timecode, uint32_t length, uint32_t lighthouse);
typedef void (*imu_process_func)( SurviveObject * so, int mask, FLT * accelgyro, uint32_t timecode, int id );
typedef void (*angle_process_func)( SurviveObject * so, int sensor_id, int acode, uint32_t timecode, FLT length, FLT angle, uint32_t lh);
-
+typedef void (*button_process_func)(SurviveObject * so, uint8_t eventType, uint8_t buttonId, uint8_t axis1Id, uint16_t axis1Val, uint8_t axis2Id, uint16_t axis2Val);
//Device drivers (prefix your drivers with "DriverReg") i.e.
// REGISTER_LINKTIME( DriverRegHTCVive );
diff --git a/src/survive.c b/src/survive.c
index 99b6648..d3c0918 100755
--- a/src/survive.c
+++ b/src/survive.c
@@ -64,13 +64,25 @@ static void button_servicer(void * context)
return;
}
- printf("ButtonEntry: eventType:%x, buttonId:%d, axis1:%d, axis1Val:%8.8x, axis2:%d, axis2Val:%8.8x\n",
- entry->eventType,
- entry->buttonId,
- entry->axis1Id,
- entry->axis1Val,
- entry->axis2Id,
- entry->axis2Val);
+ //printf("ButtonEntry: eventType:%x, buttonId:%d, axis1:%d, axis1Val:%8.8x, axis2:%d, axis2Val:%8.8x\n",
+ // entry->eventType,
+ // entry->buttonId,
+ // entry->axis1Id,
+ // entry->axis1Val,
+ // entry->axis2Id,
+ // entry->axis2Val);
+
+ button_process_func butt_func = ctx->buttonproc;
+ if (butt_func)
+ {
+ butt_func(entry->so,
+ entry->eventType,
+ entry->buttonId,
+ entry->axis1Id,
+ entry->axis1Val,
+ entry->axis2Id,
+ entry->axis2Val);
+ }
ctx->buttonQueue.nextReadIndex++;
if (ctx->buttonQueue.nextReadIndex >= BUTTON_QUEUE_MAX_LEN)
@@ -171,6 +183,7 @@ SurviveContext * survive_init( int headless )
// start the thread to process button data
ctx->buttonservicethread = OGCreateThread(button_servicer, ctx);
+ survive_install_button_fn(ctx, NULL);
return ctx;
}
@@ -216,6 +229,15 @@ void survive_install_angle_fn( SurviveContext * ctx, angle_process_func fbp )
ctx->angleproc = survive_default_angle_process;
}
+void survive_install_button_fn(SurviveContext * ctx, button_process_func fbp)
+{
+ if (fbp)
+ ctx->buttonproc = fbp;
+ else
+ ctx->buttonproc = survive_default_button_process;
+
+}
+
int survive_add_object( SurviveContext * ctx, SurviveObject * obj )
{
int oldct = ctx->objs_ct;
diff --git a/src/survive_process.c b/src/survive_process.c
index 3af2da9..eaed881 100644
--- a/src/survive_process.c
+++ b/src/survive_process.c
@@ -63,6 +63,17 @@ void survive_default_angle_process( SurviveObject * so, int sensor_id, int acode
}
}
+void survive_default_button_process(SurviveObject * so, uint8_t eventType, uint8_t buttonId, uint8_t axis1Id, uint16_t axis1Val, uint8_t axis2Id, uint16_t axis2Val)
+{
+ // do nothing.
+ printf("ButtonEntry: eventType:%x, buttonId:%d, axis1:%d, axis1Val:%8.8x, axis2:%d, axis2Val:%8.8x\n",
+ eventType,
+ buttonId,
+ axis1Id,
+ axis1Val,
+ axis2Id,
+ axis2Val);
+}
void survive_default_imu_process( SurviveObject * so, int mask, FLT * accelgyromag, uint32_t timecode, int id )
{
diff --git a/src/survive_vive.c b/src/survive_vive.c
index e271e3e..3df60ba 100755
--- a/src/survive_vive.c
+++ b/src/survive_vive.c
@@ -619,30 +619,30 @@ int survive_vive_send_magic(SurviveContext * ctx, void * drv, int magic_code, vo
//#endif
-//#if 0
- for (int i = 0; i < 0xff; i++)
+#if 0
+ for (int i = 0; i < 0xf; i++)
{
//uint8_t vive_controller_haptic_pulse[64] = { 0xff, 0x8f, 0x7, 0 /*right*/, 0xFF /*period on*/, 0xFF/*period on*/, 0xFF/*period off*/, 0xFF/*period off*/, 0xFF /* repeat Count */, 0xFF /* repeat count */ };
//uint8_t vive_controller_haptic_pulse[64] = { 0xff, 0x8f, 0x07, 0x00, 0xf4, 0x01, 0xb5, 0xa2, 0x01, 0x00 }; // data taken from Nairol's captures
uint8_t vive_controller_haptic_pulse[64] = { 0xff, 0x8f, 0x07, 0x00, 0xf4, 0x01, 0xb5, 0xa2, 0x01, 0x00 };
- //r = update_feature_report( sv->udev[USB_DEV_WATCHMAN1], 0, vive_controller_haptic_pulse, sizeof( vive_controller_haptic_pulse ) );
- r = update_feature_report(sv->udev[USB_DEV_WATCHMAN1], 0, vive_controller_haptic_pulse, sizeof(vive_controller_haptic_pulse));
+ r = update_feature_report( sv->udev[USB_DEV_WATCHMAN1], 0, vive_controller_haptic_pulse, sizeof( vive_controller_haptic_pulse ) );
+ r = getupdate_feature_report(sv->udev[USB_DEV_WATCHMAN1], 0, vive_controller_haptic_pulse, sizeof(vive_controller_haptic_pulse));
SV_INFO("UCR: %d", r);
if (r != sizeof(vive_controller_haptic_pulse)) printf("HAPTIC FAILED **************************\n"); // return 5;
OGUSleep(1000);
}
-//#endif
+#endif
#if 0
- // working code to turn off a wireless controller:
- {
- uint8_t vive_controller_off[64] = { 0xff, 0x9f, 0x04, 'o', 'f', 'f', '!' };
- //r = update_feature_report( sv->udev[USB_DEV_WATCHMAN1], 0, vive_controller_haptic_pulse, sizeof( vive_controller_haptic_pulse ) );
- r = update_feature_report(sv->udev[USB_DEV_WATCHMAN1], 0, vive_controller_off, sizeof(vive_controller_off));
- SV_INFO("UCR: %d", r);
- if (r != sizeof(vive_controller_off)) printf("OFF FAILED **************************\n"); // return 5;
- OGUSleep(1000);
- }
+ //// working code to turn off a wireless controller:
+ //{
+ // uint8_t vive_controller_off[64] = { 0xff, 0x9f, 0x04, 'o', 'f', 'f', '!' };
+ // //r = update_feature_report( sv->udev[USB_DEV_WATCHMAN1], 0, vive_controller_haptic_pulse, sizeof( vive_controller_haptic_pulse ) );
+ // r = update_feature_report(sv->udev[USB_DEV_WATCHMAN1], 0, vive_controller_off, sizeof(vive_controller_off));
+ // SV_INFO("UCR: %d", r);
+ // if (r != sizeof(vive_controller_off)) printf("OFF FAILED **************************\n"); // return 5;
+ // OGUSleep(1000);
+ //}
#endif
//if (sv->udev[USB_DEV_TRACKER0])
//{