From d5c42c4951261c401c5f9148ce2d6bb1402ce75b Mon Sep 17 00:00:00 2001 From: Justin Berger Date: Sat, 24 Mar 2018 10:13:23 -0600 Subject: Some minor fixups around command line processing --- calibrate.c | 11 +++++++---- calibrate_client.c | 3 +++ include/libsurvive/survive.h | 15 +++++++++++---- simple_pose_test.c | 3 +++ src/survive.c | 5 ++++- test.c | 3 +++ 6 files changed, 31 insertions(+), 9 deletions(-) diff --git a/calibrate.c b/calibrate.c index e0426f7..569c5cb 100644 --- a/calibrate.c +++ b/calibrate.c @@ -393,9 +393,6 @@ char * const * gargv; void * SurviveThread(void *jnk) { - ctx = survive_init( gargc, gargv ); - - uint8_t i =0; for (i=0;i<32;++i) { sensor_name[i] = malloc(3); @@ -433,8 +430,14 @@ int main( int argc, char ** argv ) { gargc = argc; gargv = argv; + + ctx = survive_init(gargc, gargv); + if (ctx == 0) { // Implies --help or similiar + return -1; + } + // Create the survive thread - OGCreateThread( SurviveThread, 0 ); + OGCreateThread(SurviveThread, 0); // Wait for the survive thread to load while(!SurviveThreadLoaded){ OGUSleep(100); } diff --git a/calibrate_client.c b/calibrate_client.c index 43ab821..4471acf 100644 --- a/calibrate_client.c +++ b/calibrate_client.c @@ -162,6 +162,9 @@ int main( int argc, char ** argv ) */ ctx = survive_init( argc, argv ); + if (ctx == 0) { // Implies --help or similiar + return -1; + } survive_install_light_fn( ctx, my_light_process ); survive_install_imu_fn( ctx, my_imu_process ); diff --git a/include/libsurvive/survive.h b/include/libsurvive/survive.h index 0b85bf3..b1c32cd 100644 --- a/include/libsurvive/survive.h +++ b/include/libsurvive/survive.h @@ -202,11 +202,18 @@ struct SurviveContext void survive_verify_FLT_size(uint32_t user_size); // Baked in size of FLT to verify users of the library have the correct setting. - - - - SurviveContext * survive_init_internal( int argc, char * const * argv ); + +/** + * Call survive_init to get a populated SurviveContext pointer. + * + * This also sets up a number of configuration values based on command line + * arguments. Pass 0, 0 to this function if you specifically do not want + * command line processing. + * + * Note that this function _can_ return null based on command line arguments, + * notably if -h was passed in. + */ static inline SurviveContext * survive_init( int argc, char * const * argv ) { survive_verify_FLT_size(sizeof(FLT)); diff --git a/simple_pose_test.c b/simple_pose_test.c index 34c15de..0772abb 100644 --- a/simple_pose_test.c +++ b/simple_pose_test.c @@ -158,6 +158,9 @@ int main( int argc, char ** argv ) double Start = OGGetAbsoluteTime(); ctx = survive_init( argc, argv ); + if (ctx == 0) { // Implies --help or similiar + return -1; + } //survive_install_button_fn(ctx, testprog_button_process); survive_install_raw_pose_fn(ctx, testprog_raw_pose_process); diff --git a/src/survive.c b/src/survive.c index 1786d45..807e82f 100644 --- a/src/survive.c +++ b/src/survive.c @@ -177,7 +177,10 @@ SurviveContext *survive_init_internal(int argc, char *const *argv) { 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"); + fprintf(stderr, " --record [log file] - Write all events to the given record file.\n"); + fprintf(stderr, " --playback [log file] - Read events from the given file instead of USB devices.\n"); + fprintf(stderr, " --playback-factor [f] - Time factor of playback -- 1 is run at the same timing as " + "original, 0 is run as fast as possible.\n"); return 0; } diff --git a/test.c b/test.c index 8e620bc..ad7aaa0 100644 --- a/test.c +++ b/test.c @@ -142,6 +142,9 @@ int main( int argc, char ** argv ) double Start = OGGetAbsoluteTime(); ctx = survive_init( argc, argv ); + if (ctx == 0) { // Implies --help or similiar + return -1; + } survive_install_button_fn(ctx, testprog_button_process); survive_install_raw_pose_fn(ctx, testprog_raw_pose_process); -- cgit v1.2.3