From a978c195a8b0cbf9ff1330ab8c6af1deb79a8b83 Mon Sep 17 00:00:00 2001 From: cnlohr Date: Sun, 18 Mar 2018 02:11:20 -0400 Subject: trying new config mode --- include/libsurvive/survive.h | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'include') diff --git a/include/libsurvive/survive.h b/include/libsurvive/survive.h index ed2f8d1..ee46862 100644 --- a/include/libsurvive/survive.h +++ b/include/libsurvive/survive.h @@ -150,6 +150,8 @@ typedef struct ButtonQueueEntry entry[BUTTON_QUEUE_MAX_LEN]; } ButtonQueue; +typedef enum { SURVIVE_STOPPED = 0, SURVIVE_RUNNING, SURVIVE_CLOSING, SURVIVE_STATE_MAX } SurviveState; + struct SurviveContext { text_feedback_func faultfunction; @@ -179,29 +181,28 @@ struct SurviveContext DeviceDriverMagicCb * drivermagics; int driver_ct; - uint8_t isClosing; // flag to indicate if threads should terminate themselves + SurviveState state; void* buttonservicethread; ButtonQueue buttonQueue; void *user_ptr; - }; -SurviveContext *survive_init_internal(int headless, htc_config_func cfcb); +void survive_verify_FLT_size(uint32_t user_size); // Baked in size of FLT to verify users of the library have the correct setting. -// Baked in size of FLT to verify users of the library have the correct setting. -void survive_verify_FLT_size(uint32_t user_size); - -static inline SurviveContext * survive_init( int headless ) { - survive_verify_FLT_size(sizeof(FLT)); - return survive_init_internal(headless, 0); -} -static inline SurviveContext *survive_init_with_config_cb(int headless, htc_config_func cfcb) { + + + + +SurviveContext * survive_init_internal( int argc, char ** argv ); +static inline SurviveContext * survive_init( int argc, char ** argv ) +{ survive_verify_FLT_size(sizeof(FLT)); - return survive_init_internal(headless, cfcb); + return survive_init_internal(initdata); } + //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 ); @@ -212,7 +213,7 @@ void survive_install_angle_fn( SurviveContext * ctx, angle_process_func fbp ); void survive_install_button_fn(SurviveContext * ctx, button_process_func fbp); void survive_install_raw_pose_fn(SurviveContext * ctx, raw_pose_func fbp); void survive_install_lighthouse_pose_fn(SurviveContext *ctx, lighthouse_pose_func fbp); - +int survive_startup( SurviveContext * ctx ); void survive_close( SurviveContext * ctx ); int survive_poll( SurviveContext * ctx ); @@ -227,7 +228,7 @@ int survive_send_magic( SurviveContext * ctx, int magic_code, void * data, int d void survive_cal_install( SurviveContext * ctx ); //XXX This will be removed if not already done so. // Read back a human-readable string description of the calibration status -int survive_cal_get_status( struct SurviveContext * ctx, char * description, int description_length ); +int survive_cal_get_status( SurviveContext * ctx, char * description, int description_length ); // Induce haptic feedback int survive_haptic(SurviveObject * so, uint8_t reserved, uint16_t pulseHigh, uint16_t pulseLow, uint16_t repeatCount); -- cgit v1.2.3 From 5aa20d099b9fe7539050a5baa4c70b678aeab64e Mon Sep 17 00:00:00 2001 From: cnlohr Date: Sun, 18 Mar 2018 02:45:09 -0400 Subject: Moving things over... still todo: * Make functions for changing temp configs. * Make functions for config_read_str but where it checks the temp one first. * Parse command-line options. --- include/libsurvive/survive.h | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/libsurvive/survive.h b/include/libsurvive/survive.h index ee46862..2935c9e 100644 --- a/include/libsurvive/survive.h +++ b/include/libsurvive/survive.h @@ -166,6 +166,7 @@ struct SurviveContext struct config_group* global_config_values; struct config_group* lh_config; //lighthouse configs + struct config_group* temporary_config_values; //Set per-session, from command-line. Not saved but override global_config_values //Calibration data: int activeLighthouses; @@ -195,16 +196,17 @@ void survive_verify_FLT_size(uint32_t user_size); // Baked in size of FLT to ver -SurviveContext * survive_init_internal( int argc, char ** argv ); -static inline SurviveContext * survive_init( int argc, char ** argv ) +SurviveContext * survive_init_internal( int argc, char * const * argv ); +static inline SurviveContext * survive_init( int argc, char * const * argv ) { survive_verify_FLT_size(sizeof(FLT)); - return survive_init_internal(initdata); + return survive_init_internal(argc, argv); } //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_htc_config_fn( SurviveContext *ctx, htc_config_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 ); @@ -221,9 +223,14 @@ SurviveObject * survive_get_so_by_name( SurviveContext * ctx, const char * name //Utilitiy functions. int survive_simple_inflate( SurviveContext * ctx, const char * input, int inlen, char * output, int outlen ); - int survive_send_magic( SurviveContext * ctx, int magic_code, void * data, int datalen ); +//These functions search both the stored-general and temporary sections for a parameter and return it. +FLT survive_config_readf( SurviveContext * ctx, const char *tag, FLT def ); +uint32_t survive_config_readi( SurviveContext * ctx, const char *tag, uint32_t def ); +const char * survive_config_reads( SurviveContext * ctx, const char *tag, const char *def ); + + //Install the calibrator. void survive_cal_install( SurviveContext * ctx ); //XXX This will be removed if not already done so. @@ -243,6 +250,8 @@ void survive_default_raw_pose_process(SurviveObject *so, uint8_t lighthouse, Sur void survive_default_lighthouse_pose_process(SurviveContext *ctx, uint8_t lighthouse, SurvivePose *pose); int survive_default_htc_config_process(SurviveObject *so, char *ct0conf, int len); + + ////////////////////// Survive Drivers //////////////////////////// void RegisterDriver(const char * name, void * data); -- cgit v1.2.3 From c44cca299fbea4196af125dfedd8e4d60f3ae0cc Mon Sep 17 00:00:00 2001 From: cnlohr Date: Sun, 18 Mar 2018 19:48:25 -0400 Subject: Almost at a config interface. --- include/libsurvive/survive.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/libsurvive/survive.h b/include/libsurvive/survive.h index 2935c9e..41f938d 100644 --- a/include/libsurvive/survive.h +++ b/include/libsurvive/survive.h @@ -226,9 +226,14 @@ int survive_simple_inflate( SurviveContext * ctx, const char * input, int inlen, int survive_send_magic( SurviveContext * ctx, int magic_code, void * data, int datalen ); //These functions search both the stored-general and temporary sections for a parameter and return it. -FLT survive_config_readf( SurviveContext * ctx, const char *tag, FLT def ); -uint32_t survive_config_readi( SurviveContext * ctx, const char *tag, uint32_t def ); -const char * survive_config_reads( SurviveContext * ctx, const char *tag, const char *def ); +#define SC_GET 0 //Get, only. +#define SC_SET 1 //Set, if not present +#define SC_OVERRIDE 2 //Set, to new default value. +#define SC_SETCONFIG 4 //Set, both in-memory and config file. Use in conjunction with SC_OVERRIDE. + +FLT survive_configf( SurviveContext * ctx, const char *tag, char flags, FLT def ); +uint32_t survive_configi( SurviveContext * ctx, const char *tag, char flags, uint32_t def ); +const char * survive_configs( SurviveContext * ctx, const char *tag, char flags, const char *def ); //Install the calibrator. @@ -248,7 +253,7 @@ 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); void survive_default_raw_pose_process(SurviveObject *so, uint8_t lighthouse, SurvivePose *pose); void survive_default_lighthouse_pose_process(SurviveContext *ctx, uint8_t lighthouse, SurvivePose *pose); -int survive_default_htc_config_process(SurviveObject *so, char *ct0conf, int len); +int survive_default_htc_config_process(SurviveObject *so, char *ct0conf, int len); -- cgit v1.2.3 From 0996cfcee351bfd665f48a205d2f7fe37dec336c Mon Sep 17 00:00:00 2001 From: cnlohr Date: Sun, 18 Mar 2018 22:00:55 -0400 Subject: Fix configuration system and fix race condition in survive_vive. --- include/libsurvive/survive.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/libsurvive/survive.h b/include/libsurvive/survive.h index 41f938d..180d83c 100644 --- a/include/libsurvive/survive.h +++ b/include/libsurvive/survive.h @@ -216,8 +216,8 @@ void survive_install_button_fn(SurviveContext * ctx, button_process_func fbp); void survive_install_raw_pose_fn(SurviveContext * ctx, raw_pose_func fbp); void survive_install_lighthouse_pose_fn(SurviveContext *ctx, lighthouse_pose_func fbp); int survive_startup( SurviveContext * ctx ); -void survive_close( SurviveContext * ctx ); int survive_poll( SurviveContext * ctx ); +void survive_close( SurviveContext * ctx ); SurviveObject * survive_get_so_by_name( SurviveContext * ctx, const char * name ); -- cgit v1.2.3