From 76623e6a945cb8be50f8081f610b397e480dcf58 Mon Sep 17 00:00:00 2001 From: cnlohr Date: Fri, 3 Mar 2017 01:32:49 -0500 Subject: First thoughts on a resolver? --- include/survive.h | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/survive.h b/include/survive.h index 51910a6..0d43465 100644 --- a/include/survive.h +++ b/include/survive.h @@ -20,6 +20,11 @@ struct SurviveContext; //It will also require a recompile. TODO: revisit this and correct the comment once fixed. #define NUM_LIGHTHOUSES 2 +struct SurviveObject; + +//XXX TODO -> Probably should be one function to take multiple types of input? +typedef int (*ResolverCB)( struct SurviveObject * so ); + struct SurviveObject { struct SurviveContext * ctx; @@ -36,9 +41,16 @@ struct SurviveObject int8_t ison:1; int8_t additional_flags:6; + //Pose Information, also "resolver" field. + FLT PoseConfidence; //0..1 + FLT Position[3]; + FLT Rotation[4]; + void * Resolver; + ResolverCB * PreferredResolverFn; //XXX TODO + + int8_t nr_locations; FLT * sensor_locations; FLT * sensor_normals; - int8_t nr_locations; //Timing sensitive data (mostly for disambiguation) int32_t timebase_hz; //48,000,000 for normal vive hardware. (checked) @@ -51,7 +63,7 @@ struct SurviveObject int32_t pulse_synctime_slack; //5,000 for normal vive hardware. (guessed) //Flood info, for calculating which laser is currently sweeping. - int8_t oldcode; + int8_t oldcode; int8_t sync_set_number; //0 = master, 1 = slave, -1 = fault. int8_t did_handle_ootx; //If unset, will send lightcap data for sync pulses next time a sensor is hit. uint32_t last_time[NUM_LIGHTHOUSES]; @@ -60,10 +72,14 @@ struct SurviveObject uint32_t last_lighttime; //May be a 24- or 32- bit number depending on what device. + //Debug int tsl; }; + + + typedef void (*text_feedback_func)( struct SurviveContext * ctx, const char * fault ); typedef void (*light_process_func)( struct SurviveObject * so, int sensor_id, int acode, int timeinsweep, uint32_t timecode, uint32_t length ); typedef void (*imu_process_func)( struct SurviveObject * so, int16_t * accelgyro, uint32_t timecode, int id ); -- cgit v1.2.3 From 58b19da6848e64c9ca7aa47d8b3e0cd30db89d44 Mon Sep 17 00:00:00 2001 From: cnlohr Date: Fri, 3 Mar 2017 02:15:04 -0500 Subject: Split out into some more things in the include folder. Getting closer to trying to have posers. --- include/libsurvive/poser.h | 54 +++++++++++++++++ include/libsurvive/survive.h | 95 +++++++++++++++++++++++++++++ include/libsurvive/survive_types.h | 29 +++++++++ include/survive.h | 118 ------------------------------------- 4 files changed, 178 insertions(+), 118 deletions(-) create mode 100644 include/libsurvive/poser.h create mode 100644 include/libsurvive/survive.h create mode 100644 include/libsurvive/survive_types.h delete mode 100644 include/survive.h (limited to 'include') diff --git a/include/libsurvive/poser.h b/include/libsurvive/poser.h new file mode 100644 index 0000000..4894acf --- /dev/null +++ b/include/libsurvive/poser.h @@ -0,0 +1,54 @@ +#ifndef _LSPOSER_H +#define _LSPOSER_H + +#include "survive_types.h" + +typedef enum PoserType_t +{ + POSERDATA_NONE = 0, + POSERDATA_IMU, + POSERDATA_LIGHT, //Single lighting event. + POSERDATA_FULL_SCENE, //Full, statified X, Y sweep data for both lighthouses. +} PoserType; + +struct PoserData +{ + PoserType pt; + uint8_t data[0]; +}; + +struct PoserDataIMU +{ + PoserType pt; + uint8_t datamask; //0 = accel present, 1 = gyro present, 2 = mag present. + FLT accel[3]; + FLT gyro[3]; + FLT mag[3]; +}; + +struct PoserDataLight +{ + PoserType pt; + int sensor_id; + int acode; //OOTX Code associated with this sweep. base_station = acode >> 2; axis = acode & 1; + uint32_t timecode; //In object-local ticks. + FLT length; //In seconds + FLT angle; //In radians from center of lighthouse. +}; + +struct PoserDataFullScene +{ + PoserType pt; + + //If "lengths[...]" < 0, means not a valid piece of sweep information. + FLT lengths[SENSORS_PER_OBJECT][NUM_LIGHTHOUSES][2]; + FLT angles [SENSORS_PER_OBJECT][NUM_LIGHTHOUSES][2]; //2 Axes + + struct PoserDataIMU lastimu; +}; + +//When you register your posers using the internal system, +typedef int (*PoserCB)( struct SurviveObject * so, struct PoserData * pd ); + + +#endif diff --git a/include/libsurvive/survive.h b/include/libsurvive/survive.h new file mode 100644 index 0000000..536c7fb --- /dev/null +++ b/include/libsurvive/survive.h @@ -0,0 +1,95 @@ +#ifndef _SURVIVE_H +#define _SURVIVE_H + +#include +#include "poser.h" + +struct SurviveContext; + +//DANGER: This structure may be redefined. Note that it is logically split into 64-bit chunks +//for optimization on 32- and 64-bit systems. + +struct SurviveObject +{ + struct SurviveContext * ctx; + + char codename[4]; //3 letters, null-terminated. Currently HMD, WM0, WM1. + char drivername[4]; //3 letters for driver. Currently "HTC" + int16_t buttonmask; + int16_t axis1; + + int16_t axis2; + int16_t axis3; + int8_t charge; + int8_t charging:1; + int8_t ison:1; + int8_t additional_flags:6; + + //Pose Information, also "resolver" field. + FLT PoseConfidence; //0..1 + FLT Position[3]; + FLT Rotation[4]; + void * PoserData; //Initialized to zero, configured by poser, can be anything the poser wants. + PoserCB * PoserFn; + + //Device-specific information about the location of the sensors. This data will be used by the poser. + int8_t nr_locations; + FLT * sensor_locations; + FLT * sensor_normals; + + //Timing sensitive data (mostly for disambiguation) + int32_t timebase_hz; //48,000,000 for normal vive hardware. (checked) + int32_t timecenter_ticks; //200,000 for normal vive hardware. (checked) + int32_t pulsedist_max_ticks; //500,000 for normal vive hardware. (guessed) + int32_t pulselength_min_sync; //2,200 for normal vive hardware. (guessed) + int32_t pulse_in_clear_time; //35,000 for normal vive hardware. (guessed) + int32_t pulse_max_for_sweep; //1,800 for normal vive hardware. (guessed) + int32_t pulse_synctime_offset; //20,000 for normal vive hardware. (guessed) + int32_t pulse_synctime_slack; //5,000 for normal vive hardware. (guessed) + + //Flood info, for calculating which laser is currently sweeping. + int8_t oldcode; + int8_t sync_set_number; //0 = master, 1 = slave, -1 = fault. + int8_t did_handle_ootx; //If unset, will send lightcap data for sync pulses next time a sensor is hit. + uint32_t last_time[NUM_LIGHTHOUSES]; + uint32_t last_length[NUM_LIGHTHOUSES]; + uint32_t recent_sync_time; + + uint32_t last_lighttime; //May be a 24- or 32- bit number depending on what device. + + + //Debug + int tsl; +}; + +struct SurviveContext * survive_init( int headless ); + +//For any of these, you may pass in 0 for the function pointer to use default behavior. +void survive_install_info_fn( struct SurviveContext * ctx, text_feedback_func fbp ); +void survive_install_error_fn( struct SurviveContext * ctx, text_feedback_func fbp ); +void survive_install_light_fn( struct SurviveContext * ctx, light_process_func fbp ); +void survive_install_imu_fn( struct SurviveContext * ctx, imu_process_func fbp ); +void survive_install_angle_fn( struct SurviveContext * ctx, angle_process_func fbp ); + +void survive_close( struct SurviveContext * ctx ); +int survive_poll(); + +struct SurviveObject * survive_get_so_by_name( struct SurviveContext * ctx, const char * name ); + +//Utilitiy functions. +int survive_simple_inflate( struct SurviveContext * ctx, const char * input, int inlen, char * output, int outlen ); + +int survive_send_magic( struct SurviveContext * ctx, int magic_code, void * data, int datalen ); + +//Install the calibrator. +void survive_cal_install( struct SurviveContext * ctx ); + +//Call these from your callback if overridden. +//Accept higher-level data. +void survive_default_light_process( struct SurviveObject * so, int sensor_id, int acode, int timeinsweep, uint32_t timecode, uint32_t length ); +void survive_default_imu_process( struct SurviveObject * so, int16_t * accelgyro, uint32_t timecode, int id ); +void survive_default_angle_process( struct SurviveObject * so, int sensor_id, int acode, uint32_t timecode, FLT length, FLT angle ); + + +#endif + diff --git a/include/libsurvive/survive_types.h b/include/libsurvive/survive_types.h new file mode 100644 index 0000000..593819f --- /dev/null +++ b/include/libsurvive/survive_types.h @@ -0,0 +1,29 @@ +#ifndef _SURVIVE_TYPES_H +#define _SURVIVE_TYPES_H + +#ifndef FLT +#ifdef USE_DOUBLE +#define FLT double +#else +#define FLT float +#endif +#endif + + +//Careful with this, you can't just add another one right now, would take minor changes in survive_data.c and the cal tools. +//It will also require a recompile. TODO: revisit this and correct the comment once fixed. +#define NUM_LIGHTHOUSES 2 + +#define INTBUFFSIZE 64 +#define SENSORS_PER_OBJECT 32 + +struct SurviveObject; +struct SurviveContext; + +typedef void (*text_feedback_func)( struct SurviveContext * ctx, const char * fault ); +typedef void (*light_process_func)( struct SurviveObject * so, int sensor_id, int acode, int timeinsweep, uint32_t timecode, uint32_t length ); +typedef void (*imu_process_func)( struct SurviveObject * so, int16_t * accelgyro, uint32_t timecode, int id ); +typedef void (*angle_process_func)( struct SurviveObject * so, int sensor_id, int acode, uint32_t timecode, FLT length, FLT angle ); + +#endif + diff --git a/include/survive.h b/include/survive.h deleted file mode 100644 index 0d43465..0000000 --- a/include/survive.h +++ /dev/null @@ -1,118 +0,0 @@ -#ifndef _SURVIVE_H -#define _SURVIVE_H - -#include - -#ifndef FLT -#ifdef USE_DOUBLE -#define FLT double -#else -#define FLT float -#endif -#endif - -struct SurviveContext; - -//DANGER: This structure may be redefined. Note that it is logically split into 64-bit chunks -//for optimization on 32- and 64-bit systems. - -//Careful with this, you can't just add another one right now, would take minor changes in survive_data.c and the cal tools. -//It will also require a recompile. TODO: revisit this and correct the comment once fixed. -#define NUM_LIGHTHOUSES 2 - -struct SurviveObject; - -//XXX TODO -> Probably should be one function to take multiple types of input? -typedef int (*ResolverCB)( struct SurviveObject * so ); - -struct SurviveObject -{ - struct SurviveContext * ctx; - - char codename[4]; //3 letters, null-terminated. Currently HMD, WM0, WM1. - char drivername[4]; //3 letters for driver. Currently "HTC" - int16_t buttonmask; - int16_t axis1; - - int16_t axis2; - int16_t axis3; - int8_t charge; - int8_t charging:1; - int8_t ison:1; - int8_t additional_flags:6; - - //Pose Information, also "resolver" field. - FLT PoseConfidence; //0..1 - FLT Position[3]; - FLT Rotation[4]; - void * Resolver; - ResolverCB * PreferredResolverFn; //XXX TODO - - int8_t nr_locations; - FLT * sensor_locations; - FLT * sensor_normals; - - //Timing sensitive data (mostly for disambiguation) - int32_t timebase_hz; //48,000,000 for normal vive hardware. (checked) - int32_t timecenter_ticks; //200,000 for normal vive hardware. (checked) - int32_t pulsedist_max_ticks; //500,000 for normal vive hardware. (guessed) - int32_t pulselength_min_sync; //2,200 for normal vive hardware. (guessed) - int32_t pulse_in_clear_time; //35,000 for normal vive hardware. (guessed) - int32_t pulse_max_for_sweep; //1,800 for normal vive hardware. (guessed) - int32_t pulse_synctime_offset; //20,000 for normal vive hardware. (guessed) - int32_t pulse_synctime_slack; //5,000 for normal vive hardware. (guessed) - - //Flood info, for calculating which laser is currently sweeping. - int8_t oldcode; - int8_t sync_set_number; //0 = master, 1 = slave, -1 = fault. - int8_t did_handle_ootx; //If unset, will send lightcap data for sync pulses next time a sensor is hit. - uint32_t last_time[NUM_LIGHTHOUSES]; - uint32_t last_length[NUM_LIGHTHOUSES]; - uint32_t recent_sync_time; - - uint32_t last_lighttime; //May be a 24- or 32- bit number depending on what device. - - - //Debug - int tsl; -}; - - - - -typedef void (*text_feedback_func)( struct SurviveContext * ctx, const char * fault ); -typedef void (*light_process_func)( struct SurviveObject * so, int sensor_id, int acode, int timeinsweep, uint32_t timecode, uint32_t length ); -typedef void (*imu_process_func)( struct SurviveObject * so, int16_t * accelgyro, uint32_t timecode, int id ); -typedef void (*angle_process_func)( struct SurviveObject * so, int sensor_id, int acode, uint32_t timecode, FLT length, FLT angle ); - -struct SurviveContext * survive_init( int headless ); - -//For any of these, you may pass in 0 for the function pointer to use default behavior. -void survive_install_info_fn( struct SurviveContext * ctx, text_feedback_func fbp ); -void survive_install_error_fn( struct SurviveContext * ctx, text_feedback_func fbp ); -void survive_install_light_fn( struct SurviveContext * ctx, light_process_func fbp ); -void survive_install_imu_fn( struct SurviveContext * ctx, imu_process_func fbp ); -void survive_install_angle_fn( struct SurviveContext * ctx, angle_process_func fbp ); - -void survive_close( struct SurviveContext * ctx ); -int survive_poll(); - -struct SurviveObject * survive_get_so_by_name( struct SurviveContext * ctx, const char * name ); - -//Utilitiy functions. -int survive_simple_inflate( struct SurviveContext * ctx, const char * input, int inlen, char * output, int outlen ); - -int survive_send_magic( struct SurviveContext * ctx, int magic_code, void * data, int datalen ); - -//Install the calibrator. -void survive_cal_install( struct SurviveContext * ctx ); - -//Call these from your callback if overridden. -//Accept higher-level data. -void survive_default_light_process( struct SurviveObject * so, int sensor_id, int acode, int timeinsweep, uint32_t timecode, uint32_t length ); -void survive_default_imu_process( struct SurviveObject * so, int16_t * accelgyro, uint32_t timecode, int id ); -void survive_default_angle_process( struct SurviveObject * so, int sensor_id, int acode, uint32_t timecode, FLT length, FLT angle ); - - -#endif - -- cgit v1.2.3 From 394cbc465e776137834eea830038b43ea98f6268 Mon Sep 17 00:00:00 2001 From: cnlohr Date: Wed, 8 Mar 2017 00:30:48 -0500 Subject: Switch types over to avoiding extra struct keyword. Switch poses to "SurvivePose" type. --- include/libsurvive/poser.h | 22 +++++++++++----------- include/libsurvive/survive.h | 8 ++++---- include/libsurvive/survive_types.h | 17 +++++++++++------ 3 files changed, 26 insertions(+), 21 deletions(-) (limited to 'include') diff --git a/include/libsurvive/poser.h b/include/libsurvive/poser.h index 4894acf..c514953 100644 --- a/include/libsurvive/poser.h +++ b/include/libsurvive/poser.h @@ -11,22 +11,22 @@ typedef enum PoserType_t POSERDATA_FULL_SCENE, //Full, statified X, Y sweep data for both lighthouses. } PoserType; -struct PoserData +typedef struct { PoserType pt; uint8_t data[0]; -}; +} PoserData; -struct PoserDataIMU +typedef struct { PoserType pt; uint8_t datamask; //0 = accel present, 1 = gyro present, 2 = mag present. FLT accel[3]; FLT gyro[3]; FLT mag[3]; -}; +} PoserDataIMU; -struct PoserDataLight +typedef struct { PoserType pt; int sensor_id; @@ -34,21 +34,21 @@ struct PoserDataLight uint32_t timecode; //In object-local ticks. FLT length; //In seconds FLT angle; //In radians from center of lighthouse. -}; +} PoserDataLight; -struct PoserDataFullScene +typedef struct { PoserType pt; //If "lengths[...]" < 0, means not a valid piece of sweep information. FLT lengths[SENSORS_PER_OBJECT][NUM_LIGHTHOUSES][2]; - FLT angles [SENSORS_PER_OBJECT][NUM_LIGHTHOUSES][2]; //2 Axes + FLT angles [SENSORS_PER_OBJECT][NUM_LIGHTHOUSES][2]; //2 Axes (Angles in LH space) - struct PoserDataIMU lastimu; -}; + PoserDataIMU lastimu; +} PoserDataFullScene; //When you register your posers using the internal system, -typedef int (*PoserCB)( struct SurviveObject * so, struct PoserData * pd ); +typedef int (*PoserCB)( SurviveObject * so, PoserData * pd ); #endif diff --git a/include/libsurvive/survive.h b/include/libsurvive/survive.h index 536c7fb..20e50ca 100644 --- a/include/libsurvive/survive.h +++ b/include/libsurvive/survive.h @@ -4,14 +4,14 @@ #include #include "poser.h" -struct SurviveContext; +typedef struct SurviveContext SurviveContext; //DANGER: This structure may be redefined. Note that it is logically split into 64-bit chunks //for optimization on 32- and 64-bit systems. struct SurviveObject { - struct SurviveContext * ctx; + SurviveContext * ctx; char codename[4]; //3 letters, null-terminated. Currently HMD, WM0, WM1. char drivername[4]; //3 letters for driver. Currently "HTC" @@ -27,8 +27,8 @@ struct SurviveObject //Pose Information, also "resolver" field. FLT PoseConfidence; //0..1 - FLT Position[3]; - FLT Rotation[4]; + SurvivePose OutPose; + SurvivePose FromLHPose[NUM_LIGHTHOUSES]; //Optionally filled out by poser, contains computed position from each lighthouse. void * PoserData; //Initialized to zero, configured by poser, can be anything the poser wants. PoserCB * PoserFn; diff --git a/include/libsurvive/survive_types.h b/include/libsurvive/survive_types.h index 593819f..6137774 100644 --- a/include/libsurvive/survive_types.h +++ b/include/libsurvive/survive_types.h @@ -9,6 +9,11 @@ #endif #endif +typedef struct SurvivePose +{ + FLT Pos[3]; + FLT Rot[4]; +} SurvivePose; //Careful with this, you can't just add another one right now, would take minor changes in survive_data.c and the cal tools. //It will also require a recompile. TODO: revisit this and correct the comment once fixed. @@ -17,13 +22,13 @@ #define INTBUFFSIZE 64 #define SENSORS_PER_OBJECT 32 -struct SurviveObject; -struct SurviveContext; +typedef struct SurviveObject SurviveObject; +typedef struct SurviveContext SurviveContext; -typedef void (*text_feedback_func)( struct SurviveContext * ctx, const char * fault ); -typedef void (*light_process_func)( struct SurviveObject * so, int sensor_id, int acode, int timeinsweep, uint32_t timecode, uint32_t length ); -typedef void (*imu_process_func)( struct SurviveObject * so, int16_t * accelgyro, uint32_t timecode, int id ); -typedef void (*angle_process_func)( struct SurviveObject * so, int sensor_id, int acode, uint32_t timecode, FLT length, FLT angle ); +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 ); +typedef void (*imu_process_func)( SurviveObject * so, int16_t * 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 ); #endif -- cgit v1.2.3 From a087915c5dd8c356911453a019723ebaa9904a36 Mon Sep 17 00:00:00 2001 From: cnlohr Date: Wed, 8 Mar 2017 00:53:28 -0500 Subject: Move most of the libsurvive stuff into a common area. --- include/libsurvive/survive.h | 101 ++++++++++++++++++++++++++++++------- include/libsurvive/survive_types.h | 10 ++++ 2 files changed, 94 insertions(+), 17 deletions(-) (limited to 'include') diff --git a/include/libsurvive/survive.h b/include/libsurvive/survive.h index 20e50ca..01b5e2b 100644 --- a/include/libsurvive/survive.h +++ b/include/libsurvive/survive.h @@ -2,10 +2,9 @@ #define _SURVIVE_H #include +#include "survive_types.h" #include "poser.h" -typedef struct SurviveContext SurviveContext; - //DANGER: This structure may be redefined. Note that it is logically split into 64-bit chunks //for optimization on 32- and 64-bit systems. @@ -25,7 +24,7 @@ struct SurviveObject int8_t ison:1; int8_t additional_flags:6; - //Pose Information, also "resolver" field. + //Pose Information, also "poser" field. FLT PoseConfidence; //0..1 SurvivePose OutPose; SurvivePose FromLHPose[NUM_LIGHTHOUSES]; //Optionally filled out by poser, contains computed position from each lighthouse. @@ -62,34 +61,102 @@ struct SurviveObject int tsl; }; -struct SurviveContext * survive_init( int headless ); + +struct BaseStationData +{ + uint8_t PositionSet:1; + + SurvivePose Pose; + + uint8_t OOTXSet:1; + uint32_t BaseStationID; + FLT fcalphase[2]; + FLT fcaltilt[2]; + FLT fcalcurve[2]; + FLT fcalgibpha[2]; + FLT fcalgibmag[2]; +}; + +struct SurviveContext +{ + text_feedback_func faultfunction; + text_feedback_func notefunction; + light_process_func lightproc; + imu_process_func imuproc; + angle_process_func angleproc; + + //Calibration data: + BaseStationData bsd[NUM_LIGHTHOUSES]; + + SurviveCalData * calptr; //If and only if the calibration subsystem is attached. + + SurviveObject ** objs; + int objs_ct; + + void ** drivers; + DeviceDriverCb * driverpolls; + DeviceDriverCb * drivercloses; + DeviceDriverMagicCb * drivermagics; + int driver_ct; +}; + +SurviveContext * survive_init( int headless ); //For any of these, you may pass in 0 for the function pointer to use default behavior. -void survive_install_info_fn( struct SurviveContext * ctx, text_feedback_func fbp ); -void survive_install_error_fn( struct SurviveContext * ctx, text_feedback_func fbp ); -void survive_install_light_fn( struct SurviveContext * ctx, light_process_func fbp ); -void survive_install_imu_fn( struct SurviveContext * ctx, imu_process_func fbp ); -void survive_install_angle_fn( struct SurviveContext * ctx, angle_process_func fbp ); +void survive_install_info_fn( SurviveContext * ctx, text_feedback_func fbp ); +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_close( struct SurviveContext * ctx ); +void survive_close( SurviveContext * ctx ); int survive_poll(); -struct SurviveObject * survive_get_so_by_name( struct SurviveContext * ctx, const char * name ); +SurviveObject * survive_get_so_by_name( SurviveContext * ctx, const char * name ); //Utilitiy functions. -int survive_simple_inflate( struct SurviveContext * ctx, const char * input, int inlen, char * output, int outlen ); +int survive_simple_inflate( SurviveContext * ctx, const char * input, int inlen, char * output, int outlen ); -int survive_send_magic( struct SurviveContext * ctx, int magic_code, void * data, int datalen ); +int survive_send_magic( SurviveContext * ctx, int magic_code, void * data, int datalen ); //Install the calibrator. -void survive_cal_install( struct SurviveContext * ctx ); +void survive_cal_install( SurviveContext * ctx ); //Call these from your callback if overridden. //Accept higher-level data. -void survive_default_light_process( struct SurviveObject * so, int sensor_id, int acode, int timeinsweep, uint32_t timecode, uint32_t length ); -void survive_default_imu_process( struct SurviveObject * so, int16_t * accelgyro, uint32_t timecode, int id ); -void survive_default_angle_process( struct SurviveObject * so, int sensor_id, int acode, uint32_t timecode, FLT length, FLT angle ); +void survive_default_light_process( SurviveObject * so, int sensor_id, int acode, int timeinsweep, uint32_t timecode, uint32_t length ); +void survive_default_imu_process( SurviveObject * so, int16_t * 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 ); + + +////////////////////// Survive Drivers //////////////////////////// + +void RegisterDriver( const char * name, void * data ); +void * GetDriver( const char * name ); +const char * GetDriverNameMatching( const char * prefix, int place ); +void ListDrivers(); +#define REGISTER_LINKTIME( func ) \ + void __attribute__((constructor)) Register##func() { RegisterDriver( #func, &func ); } + +int survive_add_object( SurviveContext * ctx, SurviveObject * obj ); +void survive_add_driver( SurviveContext * ctx, void * payload, DeviceDriverCb poll, DeviceDriverCb close, DeviceDriverMagicCb magic ); + + +////////////////////// Lightcap driver data /////////////////////// + +//For lightcap, etc. Don't change this structure at all. Regular vive is dependent on it being exactly as-is. +//When you write drivers, you can use this to send survive lightcap data. +typedef struct +{ + uint8_t sensor_id; + uint8_t type; //Mostly unused. Set to 255 to ignore it. + uint16_t length; + uint32_t timestamp; +} __attribute__((packed)) LightcapElement; + +//This is the disambiguator function, for taking light timing and figuring out place-in-sweep for a given photodiode. +void handle_lightcap( SurviveObject * so, LightcapElement * le ); #endif diff --git a/include/libsurvive/survive_types.h b/include/libsurvive/survive_types.h index 6137774..f235330 100644 --- a/include/libsurvive/survive_types.h +++ b/include/libsurvive/survive_types.h @@ -24,11 +24,21 @@ typedef struct SurvivePose typedef struct SurviveObject SurviveObject; typedef struct SurviveContext SurviveContext; +typedef struct BaseStationData BaseStationData; +typedef struct SurviveCalData SurviveCalData; //XXX Warning: This may be removed. Check at a later time for its defunctness. 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 ); typedef void (*imu_process_func)( SurviveObject * so, int16_t * 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 ); + +//Device drivers (prefix your drivers with "DriverReg") i.e. +// REGISTER_LINKTIME( DriverRegHTCVive ); +typedef int (*DeviceDriver)( SurviveContext * ctx ); +typedef int (*DeviceDriverCb)( struct SurviveContext * ctx, void * driver ); +typedef int (*DeviceDriverMagicCb)( struct SurviveContext * ctx, void * driver, int magic_code, void * data, int datalen ); + + #endif -- cgit v1.2.3 From 2a4a803b2f162692ca11e700b32da0a77049bfd2 Mon Sep 17 00:00:00 2001 From: cnlohr Date: Wed, 8 Mar 2017 01:01:42 -0500 Subject: cleaning up more header stuff --- include/libsurvive/survive.h | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'include') diff --git a/include/libsurvive/survive.h b/include/libsurvive/survive.h index 01b5e2b..c35e43c 100644 --- a/include/libsurvive/survive.h +++ b/include/libsurvive/survive.h @@ -103,6 +103,7 @@ struct SurviveContext SurviveContext * survive_init( int headless ); //For any of these, you may pass in 0 for the function pointer to use default behavior. +//In general unless you are doing wacky things like recording or playing back data, you won't need to use this. void survive_install_info_fn( SurviveContext * ctx, text_feedback_func fbp ); void survive_install_error_fn( SurviveContext * ctx, text_feedback_func fbp ); void survive_install_light_fn( SurviveContext * ctx, light_process_func fbp ); @@ -120,7 +121,7 @@ int survive_simple_inflate( SurviveContext * ctx, const char * input, int inlen, int survive_send_magic( SurviveContext * ctx, int magic_code, void * data, int datalen ); //Install the calibrator. -void survive_cal_install( SurviveContext * ctx ); +void survive_cal_install( SurviveContext * ctx ); //XXX This will be removed if not already done so. //Call these from your callback if overridden. //Accept higher-level data. @@ -132,18 +133,17 @@ void survive_default_angle_process( SurviveObject * so, int sensor_id, int acode ////////////////////// Survive Drivers //////////////////////////// void RegisterDriver( const char * name, void * data ); -void * GetDriver( const char * name ); -const char * GetDriverNameMatching( const char * prefix, int place ); -void ListDrivers(); #define REGISTER_LINKTIME( func ) \ void __attribute__((constructor)) Register##func() { RegisterDriver( #func, &func ); } -int survive_add_object( SurviveContext * ctx, SurviveObject * obj ); -void survive_add_driver( SurviveContext * ctx, void * payload, DeviceDriverCb poll, DeviceDriverCb close, DeviceDriverMagicCb magic ); -////////////////////// Lightcap driver data /////////////////////// +///////////////////////// General stuff for writing drivers /////// + +//For device drivers to call. This actually attaches them. +int survive_add_object( SurviveContext * ctx, SurviveObject * obj ); +void survive_add_driver( SurviveContext * ctx, void * payload, DeviceDriverCb poll, DeviceDriverCb close, DeviceDriverMagicCb magic ); //For lightcap, etc. Don't change this structure at all. Regular vive is dependent on it being exactly as-is. //When you write drivers, you can use this to send survive lightcap data. @@ -158,5 +158,9 @@ typedef struct //This is the disambiguator function, for taking light timing and figuring out place-in-sweep for a given photodiode. void handle_lightcap( SurviveObject * so, LightcapElement * le ); +#define SV_INFO( x... ) { char stbuff[1024]; sprintf( stbuff, x ); ctx->notefunction( ctx, stbuff ); } +#define SV_ERROR( x... ) { char stbuff[1024]; sprintf( stbuff, x ); ctx->faultfunction( ctx, stbuff ); } +#define SV_KILL() exit(0) //XXX This should likely be re-defined. + #endif -- cgit v1.2.3 From c65498054c77192b2a12fdb5ef44439a14110292 Mon Sep 17 00:00:00 2001 From: cnlohr Date: Wed, 8 Mar 2017 01:43:56 -0500 Subject: Architect the way the posers receive data. --- include/libsurvive/poser.h | 4 +++- include/libsurvive/survive.h | 4 ++-- include/libsurvive/survive_types.h | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/libsurvive/poser.h b/include/libsurvive/poser.h index c514953..98c926e 100644 --- a/include/libsurvive/poser.h +++ b/include/libsurvive/poser.h @@ -9,6 +9,7 @@ typedef enum PoserType_t POSERDATA_IMU, POSERDATA_LIGHT, //Single lighting event. POSERDATA_FULL_SCENE, //Full, statified X, Y sweep data for both lighthouses. + POSERDATA_DISASSOCIATE, //If you get this, it doesn't contain data. It just tells you to please disassociate from the current SurviveObject and delete your poserdata. } PoserType; typedef struct @@ -24,6 +25,7 @@ typedef struct FLT accel[3]; FLT gyro[3]; FLT mag[3]; + uint32_t timecode; //In object-local ticks. } PoserDataIMU; typedef struct @@ -47,7 +49,7 @@ typedef struct PoserDataIMU lastimu; } PoserDataFullScene; -//When you register your posers using the internal system, +//When you write your posers, use the following definition, and register with REGISTER_LINKTIME. typedef int (*PoserCB)( SurviveObject * so, PoserData * pd ); diff --git a/include/libsurvive/survive.h b/include/libsurvive/survive.h index c35e43c..7fd6046 100644 --- a/include/libsurvive/survive.h +++ b/include/libsurvive/survive.h @@ -29,7 +29,7 @@ struct SurviveObject SurvivePose OutPose; SurvivePose FromLHPose[NUM_LIGHTHOUSES]; //Optionally filled out by poser, contains computed position from each lighthouse. void * PoserData; //Initialized to zero, configured by poser, can be anything the poser wants. - PoserCB * PoserFn; + PoserCB PoserFn; //Device-specific information about the location of the sensors. This data will be used by the poser. int8_t nr_locations; @@ -126,7 +126,7 @@ void survive_cal_install( SurviveContext * ctx ); //XXX This will be removed if //Call these from your callback if overridden. //Accept higher-level data. void survive_default_light_process( SurviveObject * so, int sensor_id, int acode, int timeinsweep, uint32_t timecode, uint32_t length ); -void survive_default_imu_process( SurviveObject * so, int16_t * accelgyro, uint32_t timecode, int id ); +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 ); diff --git a/include/libsurvive/survive_types.h b/include/libsurvive/survive_types.h index f235330..1600e11 100644 --- a/include/libsurvive/survive_types.h +++ b/include/libsurvive/survive_types.h @@ -29,7 +29,7 @@ typedef struct SurviveCalData SurviveCalData; //XXX Warning: This may be remov 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 ); -typedef void (*imu_process_func)( SurviveObject * so, int16_t * accelgyro, uint32_t timecode, int id ); +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 ); -- cgit v1.2.3