From d21999e85f29edae7de8abdfb293da870e7fad47 Mon Sep 17 00:00:00 2001 From: cnlohr Date: Sun, 18 Mar 2018 02:11:20 -0400 Subject: trying new config mode --- data_recorder.c | 5 ++++- include/libsurvive/survive.h | 29 +++++++++++++++-------------- redist/Makefile | 2 +- redist/test_dcl.c | 2 +- src/survive.c | 41 +++++++++++++++++++++++++++-------------- 5 files changed, 48 insertions(+), 31 deletions(-) diff --git a/data_recorder.c b/data_recorder.c index 271b996..47c4010 100644 --- a/data_recorder.c +++ b/data_recorder.c @@ -128,8 +128,9 @@ int main(int argc, char **argv) { output_file = stdout; } - ctx = survive_init_with_config_cb(0, my_config_process); + ctx = survive_init( argc, argv ); + survive_install_htc_config_fn(ctx,my_config_process ); survive_install_light_fn(ctx, my_light_process); survive_install_imu_fn(ctx, my_imu_process); survive_install_lighthouse_pose_fn(ctx, my_lighthouse_process); @@ -139,6 +140,8 @@ int main(int argc, char **argv) { survive_cal_install(ctx); + survive_startup(ctx); + if (!ctx) { fprintf(stderr, "Fatal. Could not start\n"); exit(1); 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); diff --git a/redist/Makefile b/redist/Makefile index 0d74106..1437758 100644 --- a/redist/Makefile +++ b/redist/Makefile @@ -7,7 +7,7 @@ lintest : lintest.c linmath.c linmath.h gcc -g -O0 -o $@ $^ -lm test_dcl : test_dcl.c dclhelpers.c minimal_opencv.c ../src/epnp/epnp.c - gcc -o $@ $^ os_generic.c -DFLT=double -lpthread -lcblas -lm -llapacke + gcc -o $@ $^ os_generic.c -DFLT=double -lpthread -lcblas -lm -llapacke -O3 -msse2 -ftree-vectorize clean : rm -rf *.o *~ jsmntest lintest diff --git a/redist/test_dcl.c b/redist/test_dcl.c index ded2863..cc120ac 100644 --- a/redist/test_dcl.c +++ b/redist/test_dcl.c @@ -91,7 +91,7 @@ void compareToCblasTrans() { cvMulTransposed(&Em1, &Em1tEm1, 1, 0, 1); print_mat(&Em1tEm1); - test_dcldgemm_speed("Trans", 1, 0, + test_dcldgemm_speed("Trans", 0, 0, n, // # of rows in OP(A) == em1' -- 20 n, // # of cols in OP(B) == em1 -- 20 m, // # of cols in OP(A) == em1' -- 12 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