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