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 --- src/survive.c | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/survive.c b/src/survive.c index bafacad..e075423 100755 --- a/src/survive.c +++ b/src/survive.c @@ -50,7 +50,7 @@ static void *button_servicer(void * context) { OGLockSema(ctx->buttonQueue.buttonservicesem); - if (ctx->isClosing) + if (ctx->state != SURVIVE_RUNNING) { // we're shutting down. Close. return NULL; @@ -104,7 +104,9 @@ void survive_verify_FLT_size(uint32_t user_size) { } } -SurviveContext *survive_init_internal(int headless, htc_config_func configFunc) { +SurviveContext * survive_init_internal( SurviveInitData * initdata ) +{ + #ifdef RUNTIME_SYMNUM if( !did_runtime_symnum ) { @@ -121,18 +123,17 @@ SurviveContext *survive_init_internal(int headless, htc_config_func configFunc) MANUAL_DRIVER_REGISTRATION(PoserDaveOrtho) MANUAL_DRIVER_REGISTRATION(PoserDummy) MANUAL_DRIVER_REGISTRATION(DriverRegHTCVive) - #endif - int r = 0; - int i = 0; SurviveContext * ctx = calloc( 1, sizeof( SurviveContext ) ); - ctx->isClosing = 0; + ctx->state = SURVIVE_STOPPED; ctx->global_config_values = malloc( sizeof(config_group) ); ctx->lh_config = malloc( sizeof(config_group) * NUM_LIGHTHOUSES); + //initdata + // ->argc ->argp init_config_group(ctx->global_config_values,10); init_config_group(&ctx->lh_config[0],10); init_config_group(&ctx->lh_config[1],10); @@ -144,12 +145,18 @@ SurviveContext *survive_init_internal(int headless, htc_config_func configFunc) ctx->faultfunction = survivefault; ctx->notefunction = survivenote; - ctx->lightproc = survive_default_light_process; ctx->imuproc = survive_default_imu_process; ctx->angleproc = survive_default_angle_process; ctx->lighthouseposeproc = survive_default_lighthouse_pose_process; - ctx->configfunction = configFunc ? configFunc : survive_default_htc_config_process; + ctx->configfunction = survive_default_htc_config_process; + return ctx; +} + +int survive_startup( SurviveContext * ctx ) +{ + int r = 0; + int i = 0; // initialize the button queue memset(&(ctx->buttonQueue), 0, sizeof(ctx->buttonQueue)); @@ -160,7 +167,6 @@ SurviveContext *survive_init_internal(int headless, htc_config_func configFunc) survive_install_button_fn(ctx, NULL); survive_install_raw_pose_fn(ctx, NULL); - i = 0; const char * DriverName; //const char * PreferredPoser = config_read_str(ctx->global_config_values, "DefaultPoser", "PoserDummy"); @@ -190,8 +196,6 @@ SurviveContext *survive_init_internal(int headless, htc_config_func configFunc) r = dd( ctx ); printf( "Driver %s reports status %d\n", DriverName, r ); } -printf( "REGISTERING DRIVERS\n" ); - //Apply poser to objects. for( i = 0; i < ctx->objs_ct; i++ ) { @@ -201,10 +205,12 @@ printf( "REGISTERING DRIVERS\n" ); // saving the config extra to make sure that the user has a config file they can change. config_save(ctx, "config.json"); + ctx->state = SURVIVE_RUNNING; - return ctx; + return 0; } + void survive_install_info_fn( SurviveContext * ctx, text_feedback_func fbp ) { if( fbp ) @@ -328,7 +334,7 @@ void survive_close( SurviveContext * ctx ) const char * DriverName; int r = 0; - ctx->isClosing = 1; + ctx->state = SURVIVE_CLOSING; // unlock/ post to button service semaphore so the thread can kill itself OGUnlockSema(ctx->buttonQueue.buttonservicesem); @@ -380,8 +386,15 @@ void survive_close( SurviveContext * ctx ) int survive_poll( struct SurviveContext * ctx ) { - int oldct = ctx->driver_ct; int i, r; + if( ctx->state = SURVIVE_STOPPED ) + { + r = survive_startup( ctx ); + if( r ) + return r; + } + + int oldct = ctx->driver_ct; for( i = 0; i < oldct; i++ ) { -- 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. --- src/survive.c | 19 ++++++++++++------- src/survive_cal.c | 4 ++-- src/survive_config.c | 30 ++++++++++++++++++++++++++++++ src/survive_config.h | 7 +++++++ 4 files changed, 51 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/survive.c b/src/survive.c index e075423..327b7f8 100755 --- a/src/survive.c +++ b/src/survive.c @@ -104,7 +104,7 @@ void survive_verify_FLT_size(uint32_t user_size) { } } -SurviveContext * survive_init_internal( SurviveInitData * initdata ) +SurviveContext * survive_init_internal( int argc, char * const * argv ) { #ifdef RUNTIME_SYMNUM @@ -130,16 +130,19 @@ SurviveContext * survive_init_internal( SurviveInitData * initdata ) ctx->state = SURVIVE_STOPPED; ctx->global_config_values = malloc( sizeof(config_group) ); + ctx->temporary_config_values = malloc( sizeof(config_group) ); ctx->lh_config = malloc( sizeof(config_group) * NUM_LIGHTHOUSES); //initdata // ->argc ->argp init_config_group(ctx->global_config_values,10); + init_config_group(ctx->temporary_config_values,20); init_config_group(&ctx->lh_config[0],10); init_config_group(&ctx->lh_config[1],10); - config_read(ctx, "config.json"); - ctx->activeLighthouses = config_read_uint32(ctx->global_config_values, "LighthouseCount", 2); + config_read(ctx, survive_config_reads( ctx, "configfile", "config.json" ) ); + ctx->activeLighthouses = survive_config_readi( ctx, "lighthousecount", 2 ); + config_read_lighthouse(ctx->lh_config, &(ctx->bsd[0]), 0); config_read_lighthouse(ctx->lh_config, &(ctx->bsd[1]), 1); @@ -169,8 +172,8 @@ int survive_startup( SurviveContext * ctx ) const char * DriverName; - //const char * PreferredPoser = config_read_str(ctx->global_config_values, "DefaultPoser", "PoserDummy"); - const char * PreferredPoser = config_read_str(ctx->global_config_values, "DefaultPoser", "PoserTurveyTori"); + //const char * PreferredPoser = survive_config_reads(ctx->global_config_values, "defaultposer", "PoserDummy"); + const char * PreferredPoser = survive_config_reads( ctx, "defaultposer", "PoserTurveyTori"); PoserCB PreferredPoserCB = 0; const char * FirstPoser = 0; printf( "Available posers:\n" ); @@ -203,7 +206,7 @@ int survive_startup( SurviveContext * ctx ) } // saving the config extra to make sure that the user has a config file they can change. - config_save(ctx, "config.json"); + config_save(ctx, survive_config_reads( ctx, "configfile", "config.json" ) ); ctx->state = SURVIVE_RUNNING; @@ -364,9 +367,10 @@ void survive_close( SurviveContext * ctx ) } - config_save(ctx, "config.json"); + config_save(ctx, survive_config_reads( ctx, "configfile", "config.json" ) ); destroy_config_group(ctx->global_config_values); + destroy_config_group(ctx->temporary_config_values); destroy_config_group(ctx->lh_config); for (i = 0; i < ctx->objs_ct; i++) { @@ -379,6 +383,7 @@ void survive_close( SurviveContext * ctx ) free( ctx->drivermagics ); free( ctx->drivercloses ); free( ctx->global_config_values ); + free( ctx->temporary_config_values ); free( ctx->lh_config ); free( ctx ); diff --git a/src/survive_cal.c b/src/survive_cal.c index 2fd96ef..6f556f3 100755 --- a/src/survive_cal.c +++ b/src/survive_cal.c @@ -178,8 +178,8 @@ void survive_cal_install( struct SurviveContext * ctx ) } const char * DriverName; -// const char * PreferredPoser = config_read_str(ctx->global_config_values, "ConfigPoser", "PoserCharlesSlow"); - const char * PreferredPoser = config_read_str(ctx->global_config_values, "ConfigPoser", "PoserTurveyTori"); +// const char * PreferredPoser = survive_config_reads(ctx, "configposer", "PoserCharlesSlow"); + const char * PreferredPoser = survive_config_reads(ctx, "configposer", "PoserTurveyTori"); PoserCB PreferredPoserCB = 0; const char * FirstPoser = 0; printf( "Available posers:\n" ); diff --git a/src/survive_config.c b/src/survive_config.c index d923ba4..4ef2994 100644 --- a/src/survive_config.c +++ b/src/survive_config.c @@ -181,6 +181,36 @@ FLT config_read_float(config_group *cg, const char *tag, const FLT def) { return config_set_float(cg, tag, def); } +static config_entry * sc_search(SurviveContext * ctx, const char *tag ) +{ + config_entry *cv = find_config_entry(ctx->temporary_config_values, tag); + if( !cv ) cv = find_config_entry(ctx->global_config_values, tag); + return cv; +} + +FLT survive_config_readf( SurviveContext * ctx, const char *tag, FLT def ) +{ + config_entry * cv = sc_search( ctx, tag ); + if( !cv ) return def; + return cv->numeric.f; +} + +uint32_t survive_config_readi( SurviveContext * ctx, const char *tag, uint32_t def ) +{ + config_entry * cv = sc_search( ctx, tag ); + if( !cv ) return def; + return cv->numeric.i; +} + +const char * survive_config_reads( SurviveContext * ctx, const char *tag, const char *def ) +{ + config_entry * cv = sc_search( ctx, tag ); + if( !cv ) return def; + return cv->data; +} + + + // TODO: Do something better than this: #define CFG_MIN(x,y) ((x) < (y)? (x): (y)) diff --git a/src/survive_config.h b/src/survive_config.h index e2686e9..1ae124d 100644 --- a/src/survive_config.h +++ b/src/survive_config.h @@ -52,9 +52,16 @@ const FLT config_set_float(config_group *cg, const char *tag, const FLT value); const uint32_t config_set_uint32(config_group *cg, const char *tag, const uint32_t value); const char* config_set_str(config_group *cg, const char *tag, const char* value); +//These functions look for a parameter in a specific group, and then chose the best to return. If the parameter does not exist, default will be written. FLT config_read_float(config_group *cg, const char *tag, const FLT def); uint16_t config_read_float_array(config_group *cg, const char *tag, FLT* values, const FLT* def, uint8_t count); uint32_t config_read_uint32(config_group *cg, const char *tag, const uint32_t def); const char* config_read_str(config_group *cg, const char *tag, const char *def); +//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 ); +//They're actually defined in survive.h for users as well. + #endif -- 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. --- src/survive.c | 57 ++++++++++++++++++++++---- src/survive_cal.c | 6 ++- src/survive_config.c | 109 ++++++++++++++++++++++++++++++++++++------------- src/survive_config.h | 10 ++--- src/survive_playback.c | 5 +-- src/survive_vive.c | 2 +- 6 files changed, 141 insertions(+), 48 deletions(-) (limited to 'src') diff --git a/src/survive.c b/src/survive.c index 327b7f8..24bb7d3 100755 --- a/src/survive.c +++ b/src/survive.c @@ -106,7 +106,6 @@ void survive_verify_FLT_size(uint32_t user_size) { SurviveContext * survive_init_internal( int argc, char * const * argv ) { - #ifdef RUNTIME_SYMNUM if( !did_runtime_symnum ) { @@ -134,14 +133,58 @@ SurviveContext * survive_init_internal( int argc, char * const * argv ) ctx->lh_config = malloc( sizeof(config_group) * NUM_LIGHTHOUSES); //initdata - // ->argc ->argp init_config_group(ctx->global_config_values,10); init_config_group(ctx->temporary_config_values,20); init_config_group(&ctx->lh_config[0],10); init_config_group(&ctx->lh_config[1],10); - config_read(ctx, survive_config_reads( ctx, "configfile", "config.json" ) ); - ctx->activeLighthouses = survive_config_readi( ctx, "lighthousecount", 2 ); + //Process command-line parameters. + char * const * argvend = &argv[argc]; + char * const * av = argv+1; + int showhelp = 0; + for( ; av != argvend; av++ ) + { + if( (*av)[0] != '-' ) + showhelp = 1; + else + { + const char * vartoupdate = 0; + + switch( (*av)[1] ) + { + case '-': vartoupdate = &(*av)[2]; break; + case 'h': showhelp = 1; break; + case 'p': vartoupdate = "defaultposer"; break; + case 'l': vartoupdate = "lighthousecount"; break; + case 'c': vartoupdate = "configfile"; break; + default: + fprintf( stderr, "Error: unknown parameter %s\n", *av ); + showhelp = 1; + } + + if( vartoupdate ) + { + survive_configs( ctx, *av, SC_OVERRIDE, *(av+1) ); + av++; + } + } + } + if( showhelp ) + { + fprintf( stderr, "libsurvive - usage:\n" ); + fprintf( stderr, " --[parameter] [value] - sets parameter\n" ); + fprintf( stderr, " -h - shows help.\n" ); + fprintf( stderr, " -p [poser] - use a specific defaultposer.\n" ); + fprintf( stderr, " -l [lighthouse count] - use a specific number of lighthoses.\n" ); + fprintf( stderr, " -c [config file] - set config file\n" ); + fprintf( stderr, " -p [lighthouse count] - use a specific number of lighthoses.\n" ); + + //XXX: TODO: Should this just exit(-1)? + return 0; + } + + config_read(ctx, survive_configs( ctx, "configfile", SC_GET, "config.json" ) ); + ctx->activeLighthouses = survive_configi( ctx, "lighthousecount", SC_SETCONFIG, 2 ); config_read_lighthouse(ctx->lh_config, &(ctx->bsd[0]), 0); config_read_lighthouse(ctx->lh_config, &(ctx->bsd[1]), 1); @@ -173,7 +216,7 @@ int survive_startup( SurviveContext * ctx ) const char * DriverName; //const char * PreferredPoser = survive_config_reads(ctx->global_config_values, "defaultposer", "PoserDummy"); - const char * PreferredPoser = survive_config_reads( ctx, "defaultposer", "PoserTurveyTori"); + const char * PreferredPoser = survive_configs( ctx, "defaultposer", SC_SETCONFIG, "PoserTurveyTori"); PoserCB PreferredPoserCB = 0; const char * FirstPoser = 0; printf( "Available posers:\n" ); @@ -206,7 +249,7 @@ int survive_startup( SurviveContext * ctx ) } // saving the config extra to make sure that the user has a config file they can change. - config_save(ctx, survive_config_reads( ctx, "configfile", "config.json" ) ); + config_save(ctx, survive_configs( ctx, "configfile", SC_GET, "config.json" ) ); ctx->state = SURVIVE_RUNNING; @@ -367,7 +410,7 @@ void survive_close( SurviveContext * ctx ) } - config_save(ctx, survive_config_reads( ctx, "configfile", "config.json" ) ); + config_save(ctx, survive_configs( ctx, "configfile", SC_GET, "config.json" ) ); destroy_config_group(ctx->global_config_values); destroy_config_group(ctx->temporary_config_values); diff --git a/src/survive_cal.c b/src/survive_cal.c index 6f556f3..4b1df89 100755 --- a/src/survive_cal.c +++ b/src/survive_cal.c @@ -8,6 +8,7 @@ // to not include it at all on any stripped-down versions of libsurvive. // + #include "survive_cal.h" #include "survive_internal.h" #include "survive_reproject.h" @@ -178,8 +179,9 @@ void survive_cal_install( struct SurviveContext * ctx ) } const char * DriverName; -// const char * PreferredPoser = survive_config_reads(ctx, "configposer", "PoserCharlesSlow"); - const char * PreferredPoser = survive_config_reads(ctx, "configposer", "PoserTurveyTori"); +// const char * PreferredPoser = survive_configs(ctx, "configposer", "PoserCharlesSlow"); + const char * PreferredPoser = survive_configs(ctx, "configposer", SC_SETCONFIG, "PoserTurveyTori"); + PoserCB PreferredPoserCB = 0; const char * FirstPoser = 0; printf( "Available posers:\n" ); diff --git a/src/survive_config.c b/src/survive_config.c index 4ef2994..1a64828 100644 --- a/src/survive_config.c +++ b/src/survive_config.c @@ -181,34 +181,6 @@ FLT config_read_float(config_group *cg, const char *tag, const FLT def) { return config_set_float(cg, tag, def); } -static config_entry * sc_search(SurviveContext * ctx, const char *tag ) -{ - config_entry *cv = find_config_entry(ctx->temporary_config_values, tag); - if( !cv ) cv = find_config_entry(ctx->global_config_values, tag); - return cv; -} - -FLT survive_config_readf( SurviveContext * ctx, const char *tag, FLT def ) -{ - config_entry * cv = sc_search( ctx, tag ); - if( !cv ) return def; - return cv->numeric.f; -} - -uint32_t survive_config_readi( SurviveContext * ctx, const char *tag, uint32_t def ) -{ - config_entry * cv = sc_search( ctx, tag ); - if( !cv ) return def; - return cv->numeric.i; -} - -const char * survive_config_reads( SurviveContext * ctx, const char *tag, const char *def ) -{ - config_entry * cv = sc_search( ctx, tag ); - if( !cv ) return def; - return cv->data; -} - // TODO: Do something better than this: @@ -471,3 +443,84 @@ void config_read(SurviveContext* sctx, const char* path) { json_tag_value = NULL; } + + + +static config_entry * sc_search(SurviveContext * ctx, const char *tag ) +{ + config_entry *cv = find_config_entry(ctx->temporary_config_values, tag); + if( !cv ) cv = find_config_entry(ctx->global_config_values, tag); + return cv; +} + + + +FLT survive_configf( SurviveContext * ctx, const char *tag, char flags, FLT def ) +{ + if( !(flags & SC_OVERRIDE) ) + { + config_entry * cv = sc_search( ctx, tag ); + if( cv ) + return cv->numeric.f; + } + + //If override is flagged, or, we can't find the variable, ,continue on. + if( flags & SC_SETCONFIG ) + { + config_set_float( ctx->temporary_config_values, tag, def ); + config_set_float( ctx->global_config_values, tag, def ); + } + else if( flags & SC_SET ) + { + config_set_float( ctx->temporary_config_values, tag, def ); + } + + return def; +} + +uint32_t survive_configi( SurviveContext * ctx, const char *tag, char flags, uint32_t def ) +{ + if( !(flags & SC_OVERRIDE) ) + { + config_entry * cv = sc_search( ctx, tag ); + if( cv ) + return cv->numeric.i; + } + + //If override is flagged, or, we can't find the variable, ,continue on. + if( flags & SC_SETCONFIG ) + { + config_set_uint32( ctx->temporary_config_values, tag, def ); + config_set_uint32( ctx->global_config_values, tag, def ); + } + else if( flags & SC_SET ) + { + config_set_uint32( ctx->temporary_config_values, tag, def ); + } + + return def; +} + +const char * survive_configs( SurviveContext * ctx, const char *tag, char flags, const char *def ) +{ + if( !(flags & SC_OVERRIDE) ) + { + config_entry * cv = sc_search( ctx, tag ); + if( cv ) + return cv->data; + } + + //If override is flagged, or, we can't find the variable, ,continue on. + if( flags & SC_SETCONFIG ) + { + config_set_str( ctx->temporary_config_values, tag, def ); + config_set_str( ctx->global_config_values, tag, def ); + } + else if( flags & SC_SET ) + { + config_set_str( ctx->temporary_config_values, tag, def ); + } + + return def; +} + diff --git a/src/survive_config.h b/src/survive_config.h index 1ae124d..23d80c8 100644 --- a/src/survive_config.h +++ b/src/survive_config.h @@ -1,5 +1,7 @@ // (C) 2017 <>< Joshua Allen, Under MIT/x11 License. - +// +// This header is for handling internal parameter values. Most accesses should be done through functions like survive_config +// #ifndef _SURVIVE_CONFIG_H #define _SURVIVE_CONFIG_H @@ -58,10 +60,4 @@ uint16_t config_read_float_array(config_group *cg, const char *tag, FLT* values, uint32_t config_read_uint32(config_group *cg, const char *tag, const uint32_t def); const char* config_read_str(config_group *cg, const char *tag, const char *def); -//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 ); -//They're actually defined in survive.h for users as well. - #endif diff --git a/src/survive_playback.c b/src/survive_playback.c index df9fcaa..014542b 100644 --- a/src/survive_playback.c +++ b/src/survive_playback.c @@ -203,7 +203,7 @@ static int LoadConfig(SurvivePlaybackData *sv, SurviveObject *so) { } int DriverRegPlayback(SurviveContext *ctx) { - const char *playback_file = config_read_str(ctx->global_config_values, "PlaybackFile", ""); + const char *playback_file = survive_configs(ctx, "playbackfile", SC_SETCONFIG, ""); if (strlen(playback_file) == 0) { return 0; @@ -212,8 +212,7 @@ int DriverRegPlayback(SurviveContext *ctx) { SurvivePlaybackData *sp = calloc(1, sizeof(SurvivePlaybackData)); sp->ctx = ctx; sp->playback_dir = playback_file; - sp->time_factor = - config_read_float(ctx->global_config_values, "PlaybackFactor", 1.); + sp->time_factor = survive_configf(ctx, "playbackfactor", SC_SETCONFIG, 1.f); printf("%s\n", playback_file); diff --git a/src/survive_vive.c b/src/survive_vive.c index 4411efb..47af701 100755 --- a/src/survive_vive.c +++ b/src/survive_vive.c @@ -1712,7 +1712,7 @@ void init_SurviveObject(SurviveObject* so) { int DriverRegHTCVive( SurviveContext * ctx ) { - const char *playback_dir = config_read_str(ctx->global_config_values, "PlaybackFile", ""); + const char *playback_dir = survive_configs(ctx, "playbackfile", SC_SETCONFIG, ""); if(strlen(playback_dir) != 0) { SV_INFO("Playback is active; disabling USB driver"); return 0; -- 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. --- src/survive.c | 17 +++++++--- src/survive_cal.c | 30 ++++++++++++----- src/survive_config.c | 5 ++- src/survive_data.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++++--- src/survive_vive.c | 46 +++++++++++++------------- 5 files changed, 151 insertions(+), 40 deletions(-) (limited to 'src') diff --git a/src/survive.c b/src/survive.c index 24bb7d3..05c66d7 100755 --- a/src/survive.c +++ b/src/survive.c @@ -164,13 +164,22 @@ SurviveContext * survive_init_internal( int argc, char * const * argv ) if( vartoupdate ) { - survive_configs( ctx, *av, SC_OVERRIDE, *(av+1) ); - av++; + if( av+1 == argvend ) + { + fprintf( stderr, "Error: expected parameter after %s\n", *av ); + showhelp = 1; + } + else + { + survive_configs( ctx, *av+2, SC_OVERRIDE|SC_SET, *(av+1) ); + av++; + } } } } if( showhelp ) { + //Can't use SV_ERROR here since we don't have a context to send to yet. fprintf( stderr, "libsurvive - usage:\n" ); fprintf( stderr, " --[parameter] [value] - sets parameter\n" ); fprintf( stderr, " -h - shows help.\n" ); @@ -178,8 +187,6 @@ SurviveContext * survive_init_internal( int argc, char * const * argv ) fprintf( stderr, " -l [lighthouse count] - use a specific number of lighthoses.\n" ); fprintf( stderr, " -c [config file] - set config file\n" ); fprintf( stderr, " -p [lighthouse count] - use a specific number of lighthoses.\n" ); - - //XXX: TODO: Should this just exit(-1)? return 0; } @@ -435,7 +442,7 @@ void survive_close( SurviveContext * ctx ) int survive_poll( struct SurviveContext * ctx ) { int i, r; - if( ctx->state = SURVIVE_STOPPED ) + if( ctx->state == SURVIVE_STOPPED ) { r = survive_startup( ctx ); if( r ) diff --git a/src/survive_cal.c b/src/survive_cal.c index 4b1df89..cb242ae 100755 --- a/src/survive_cal.c +++ b/src/survive_cal.c @@ -119,6 +119,11 @@ void survive_cal_install( struct SurviveContext * ctx ) int i; struct SurviveCalData * cd = ctx->calptr = calloc( 1, sizeof( struct SurviveCalData ) ); + if( ctx->state != SURVIVE_RUNNING ) + { + SV_ERROR( "Error: You cannot install a calibrator until the system is running." ); + } + for( i = 0; i < NUM_LIGHTHOUSES; i++ ) { ootx_init_decoder_context(&cd->ootx_decoders[i]); @@ -182,19 +187,27 @@ void survive_cal_install( struct SurviveContext * ctx ) // const char * PreferredPoser = survive_configs(ctx, "configposer", "PoserCharlesSlow"); const char * PreferredPoser = survive_configs(ctx, "configposer", SC_SETCONFIG, "PoserTurveyTori"); - PoserCB PreferredPoserCB = 0; - const char * FirstPoser = 0; - printf( "Available posers:\n" ); + SV_INFO( "Trying to load poser %s for cal.", PreferredPoser ); + PoserCB SelectedPoserCB = 0; + const char * SelectedPoserName = 0; i = 0; while( ( DriverName = GetDriverNameMatching( "Poser", i++ ) ) ) { PoserCB p = GetDriver( DriverName ); - if( !PreferredPoserCB ) PreferredPoserCB = p; + if( !SelectedPoserCB ) + { + SelectedPoserCB = p; + SelectedPoserName = DriverName; + } int ThisPoser = strcmp( DriverName, PreferredPoser ) == 0; - if( ThisPoser ) PreferredPoserCB = p; + if( ThisPoser ) + { + SelectedPoserCB = p; + SelectedPoserName = DriverName; + } } - cd->ConfigPoserFn = PreferredPoserCB; - printf( "Got config poser: %p\n", cd->ConfigPoserFn ); + cd->ConfigPoserFn = SelectedPoserCB; + SV_INFO( "Got config poser: %s (%p)", SelectedPoserName, cd->ConfigPoserFn ); ootx_packet_clbk = ootx_packet_clbk_d; ctx->calptr = cd; @@ -207,7 +220,7 @@ void survive_cal_light( struct SurviveObject * so, int sensor_id, int acode, int struct SurviveCalData * cd = ctx->calptr; if( !cd ) return; - + switch( cd->stage ) { default: @@ -222,6 +235,7 @@ void survive_cal_light( struct SurviveObject * so, int sensor_id, int acode, int //fprintf(stderr, "%s\n", so->codename); int lhid = -sensor_id-1; // Take the OOTX data from the first device. (if using HMD, WM0, WM1 only, this will be HMD) + if( lhid < NUM_LIGHTHOUSES && so == cd->poseobjects[0] ) { uint8_t dbit = (acode & 2)>>1; diff --git a/src/survive_config.c b/src/survive_config.c index 1a64828..44933fa 100644 --- a/src/survive_config.c +++ b/src/survive_config.c @@ -449,7 +449,10 @@ void config_read(SurviveContext* sctx, const char* path) { static config_entry * sc_search(SurviveContext * ctx, const char *tag ) { config_entry *cv = find_config_entry(ctx->temporary_config_values, tag); - if( !cv ) cv = find_config_entry(ctx->global_config_values, tag); + if( !cv ) + { + cv = find_config_entry(ctx->global_config_values, tag); + } return cv; } diff --git a/src/survive_data.c b/src/survive_data.c index 0427659..cb6340b 100644 --- a/src/survive_data.c +++ b/src/survive_data.c @@ -6,9 +6,83 @@ #include #include /* for sqrt */ -#define USE_TURVEYBIGUATOR +//#define USE_TURVEYBIGUATOR +#define CHARLES_STATIBUATOR -#ifdef USE_TURVEYBIGUATOR +#if defined(USE_CHARLESSTATIBGUATOR) + +/* + The operating principle of + +*/ + + + +typedef struct +{ + uint32_t next_expected_time; +} statbiguator_beamtracker; + +typedef struct +{ + statbiguator_beamtracker * beams; + + //NUM_LIGHTHOUSES first, then so->nr_locations + +} statbiguator_data; + +void handle_lightcap2( SurviveObject * so, LightcapElement * le ) +{ + SurviveContext * ctx = so->ctx; + + if (so->disambiguator_data == NULL) + { + fprintf(stderr, "Initializing Disambiguator Data\n"); + so->disambiguator_data = malloc(sizeof(lightcap2_data)); + memset(so->disambiguator_data, 0, sizeof(lightcap2_data)); + } + + + if( disambiguator_data +} + +/* + + ctx->lightproc( so, le->sensor_id, acode, offset_from, le->timestamp, le->length, whichlh ); + // first, send out the sync pulse data for the last round (for OOTX decoding + { + if (lcd->per_sweep.lh_max_pulse_length[0] != 0) + { + so->ctx->lightproc( + so, + -1, + handle_lightcap2_getAcodeFromSyncPulse(so, lcd->per_sweep.lh_max_pulse_length[0]), + lcd->per_sweep.lh_max_pulse_length[0], + lcd->per_sweep.lh_start_time[0], + 0, + 0); + } + if (lcd->per_sweep.lh_max_pulse_length[1] != 0) + { + so->ctx->lightproc( + so, + -2, + handle_lightcap2_getAcodeFromSyncPulse(so, lcd->per_sweep.lh_max_pulse_length[1]), + lcd->per_sweep.lh_max_pulse_length[1], + lcd->per_sweep.lh_start_time[1], + 0, + 1); + } + } +*/ + + + + +// handle_lightcap2(so,le); + + +#elif defined( USE_TURVEYBIGUATOR ) static const float tau_table[33] = { 0, 0, 0, 1.151140982, 1.425, 1.5712213707, 1.656266074, 1.7110275587, 1.7490784054, 1.7770229476, 1.798410005, 1.8153056661, 1.8289916275, 1.8403044103, 1.8498129961, 1.8579178211, @@ -469,6 +543,11 @@ void handle_lightcap2( SurviveObject * so, LightcapElement * le ) #endif + + + + + int32_t decode_acode(uint32_t length, int32_t main_divisor) { //+50 adds a small offset and seems to help always get it right. //Check the +50 in the future to see how well this works on a variety of hardware. @@ -513,7 +592,7 @@ void handle_lightcap( SurviveObject * so, LightcapElement * le ) { SurviveContext * ctx = so->ctx; -#ifdef USE_TURVEYBIGUATOR +#if defined (USE_TURVEYBIGUATOR) || defined(USE_CHARLESSTATIBGUATOR) handle_lightcap2(so,le); return; @@ -605,7 +684,10 @@ void handle_lightcap( SurviveObject * so, LightcapElement * le ) { so->last_sync_length[1] = 0; } + + //This is triggered on the first full sync pulse. so->last_sync_time[ssn] = le->timestamp; + //printf( "A: %d\n", so->last_sync_time[ssn] ); so->last_sync_length[ssn] = le->length; } else if( so->sync_set_number == -1 ) @@ -623,7 +705,9 @@ void handle_lightcap( SurviveObject * so, LightcapElement * le ) } else { + //This is triggered on the slave base station's sync pulse. so->last_sync_time[ssn] = le->timestamp; + //printf( "B: %d\n", so->last_sync_time[ssn] ); so->last_sync_length[ssn] = le->length; } } @@ -635,6 +719,7 @@ void handle_lightcap( SurviveObject * so, LightcapElement * le ) { if( so->last_sync_time[ssn] > le->timestamp ) { + //printf( "C: %d\n", so->last_sync_time[ssn] ); so->last_sync_time[ssn] = le->timestamp; so->last_sync_length[ssn] = le->length; } @@ -683,7 +768,7 @@ void handle_lightcap( SurviveObject * so, LightcapElement * le ) { int whichlh; if( acode < 0 ) whichlh = 1; - else whichlh = !(acode>>2); + else whichlh = (acode>>2); ctx->lightproc( so, le->sensor_id, acode, offset_from, le->timestamp, le->length, whichlh ); } } diff --git a/src/survive_vive.c b/src/survive_vive.c index 47af701..cf068a3 100755 --- a/src/survive_vive.c +++ b/src/survive_vive.c @@ -339,6 +339,7 @@ int survive_usb_init( SurviveViveData * sv, SurviveObject * hmd, SurviveObject * { SurviveContext * ctx = sv->ctx; #ifdef HIDAPI + SV_INFO( "Vive starting in HIDAPI mode." ); if( !GlobalRXUSBMutx ) { GlobalRXUSBMutx = OGCreateMutex(); @@ -403,6 +404,8 @@ int survive_usb_init( SurviveViveData * sv, SurviveObject * hmd, SurviveObject * } #else + SV_INFO( "Vive starting in libusb mode." ); + int r = libusb_init( &sv->usbctx ); if( r ) { @@ -495,6 +498,13 @@ int survive_usb_init( SurviveViveData * sv, SurviveObject * hmd, SurviveObject * libusb_free_device_list( devs, 1 ); #endif + //Add the drivers - this must happen BEFORE we actually attach interfaces. + if( sv->udev[USB_DEV_HMD_IMU_LH] ) { survive_add_object( ctx, hmd ); } + if( sv->udev[USB_DEV_WATCHMAN1] ) { survive_add_object( ctx, wm0 ); } + if( sv->udev[USB_DEV_WATCHMAN2] ) { survive_add_object( ctx, wm1 ); } + if( sv->udev[USB_DEV_TRACKER0] ) { survive_add_object( ctx, tr0 ); } + if( sv->udev[USB_DEV_W_WATCHMAN1] ) { survive_add_object( ctx, ww0 ); } + if( sv->udev[USB_DEV_HMD] && AttachInterface( sv, hmd, USB_IF_HMD, sv->udev[USB_DEV_HMD], 0x81, survive_data_cb, "Mainboard" ) ) { return -6; } if( sv->udev[USB_DEV_HMD_IMU_LH] && AttachInterface( sv, hmd, USB_IF_HMD_IMU_LH, sv->udev[USB_DEV_HMD_IMU_LH], 0x81, survive_data_cb, "Lighthouse" ) ) { return -7; } if( sv->udev[USB_DEV_WATCHMAN1] && AttachInterface( sv, wm0, USB_IF_WATCHMAN1, sv->udev[USB_DEV_WATCHMAN1], 0x81, survive_data_cb, "Watchman 1" ) ) { return -8; } @@ -532,7 +542,6 @@ int survive_vive_send_magic(SurviveContext * ctx, void * drv, int magic_code, vo { int r; SurviveViveData * sv = drv; - printf( "*CALLING %p %p\n", ctx, sv ); //XXX TODO: Handle haptics, etc. int turnon = magic_code; @@ -700,6 +709,7 @@ int survive_vive_send_magic(SurviveContext * ctx, void * drv, int magic_code, vo int survive_vive_send_haptic(SurviveObject * so, uint8_t reserved, uint16_t pulseHigh, uint16_t pulseLow, uint16_t repeatCount) { SurviveViveData *sv = (SurviveViveData*)so->driver; + SurviveContext * ctx = so->ctx; if (NULL == sv) { @@ -719,7 +729,7 @@ int survive_vive_send_haptic(SurviveObject * so, uint8_t reserved, uint16_t puls //SV_INFO("UCR: %d", r); if (r != sizeof(vive_controller_haptic_pulse)) { - printf("HAPTIC FAILED **************************\n"); + SV_ERROR("HAPTIC FAILED **************************\n"); return -1; } @@ -1135,7 +1145,6 @@ SurviveObject *so; static void handle_watchman( SurviveObject * w, uint8_t * readdata ) { - uint8_t startread[29]; memcpy( startread, readdata, 29 ); @@ -1438,7 +1447,6 @@ void survive_data_cb( SurviveUSBInterface * si ) } #endif - switch( si->which_interface_am_i ) { case USB_IF_HMD: @@ -1673,7 +1681,7 @@ static int LoadConfig( SurviveViveData * sv, SurviveObject * so, int devno, int SurviveContext * ctx = sv->ctx; char * ct0conf = 0; int len = survive_get_config( &ct0conf, sv, devno, iface, extra_magic ); - printf( "Loading config: %d\n", len ); + SV_INFO( "Loading config: %d", len ); if( len < 0 ) { @@ -1736,11 +1744,21 @@ int DriverRegHTCVive( SurviveContext * ctx ) #endif //USB must happen last. - if (survive_usb_init(sv, hmd, wm0, wm1, tr0, ww0)) { + if (survive_usb_init(sv, hmd, wm0, wm1, tr0, ww0)) { // TODO: Cleanup any libUSB stuff sitting around. goto fail_gracefully; } + if( sv->udev[USB_DEV_HMD_IMU_LH] || + sv->udev[USB_DEV_WATCHMAN1] || + sv->udev[USB_DEV_WATCHMAN2] || + sv->udev[USB_DEV_TRACKER0] || + sv->udev[USB_DEV_W_WATCHMAN1] ) { + survive_add_driver( ctx, sv, survive_vive_usb_poll, survive_vive_close, survive_vive_send_magic ); + } else { + SV_ERROR("No USB devices detected"); + } + //Next, pull out the config stuff. if (sv->udev[USB_DEV_HMD_IMU_LH] && LoadConfig(sv, hmd, 1, 0, 0)) { SV_INFO("HMD config issue."); @@ -1750,22 +1768,6 @@ int DriverRegHTCVive( SurviveContext * ctx ) if( sv->udev[USB_DEV_TRACKER0] && LoadConfig( sv, tr0, 4, 0, 0 )) { SV_INFO( "Tracker 0 config issue." ); } if( sv->udev[USB_DEV_W_WATCHMAN1] && LoadConfig( sv, ww0, 5, 0, 0 )) { SV_INFO( "Wired Watchman 0 config issue." ); } - //Add the drivers. - if( sv->udev[USB_DEV_HMD_IMU_LH] ) { survive_add_object( ctx, hmd ); } - if( sv->udev[USB_DEV_WATCHMAN1] ) { survive_add_object( ctx, wm0 ); } - if( sv->udev[USB_DEV_WATCHMAN2] ) { survive_add_object( ctx, wm1 ); } - if( sv->udev[USB_DEV_TRACKER0] ) { survive_add_object( ctx, tr0 ); } - if( sv->udev[USB_DEV_W_WATCHMAN1] ) { survive_add_object( ctx, ww0 ); } - - if( sv->udev[USB_DEV_HMD_IMU_LH] || - sv->udev[USB_DEV_WATCHMAN1] || - sv->udev[USB_DEV_WATCHMAN2] || - sv->udev[USB_DEV_TRACKER0] || - sv->udev[USB_DEV_W_WATCHMAN1] ) { - survive_add_driver( ctx, sv, survive_vive_usb_poll, survive_vive_close, survive_vive_send_magic ); - } else { - fprintf(stderr, "No USB devices detected\n"); - } return 0; fail_gracefully: -- cgit v1.2.3 From 8e65bc97327b27014fc9507374a20bfc468e06ee Mon Sep 17 00:00:00 2001 From: Justin Berger Date: Sun, 18 Mar 2018 21:44:58 -0600 Subject: Took out installation after users could install hooks --- src/survive.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'src') diff --git a/src/survive.c b/src/survive.c index 05c66d7..f0c24f5 100755 --- a/src/survive.c +++ b/src/survive.c @@ -217,8 +217,6 @@ int survive_startup( SurviveContext * ctx ) // start the thread to process button data ctx->buttonservicethread = OGCreateThread(button_servicer, ctx); - survive_install_button_fn(ctx, NULL); - survive_install_raw_pose_fn(ctx, NULL); const char * DriverName; -- cgit v1.2.3