diff options
author | ultramn <dchapm2@umbc.edu> | 2016-12-16 13:52:44 -0800 |
---|---|---|
committer | ultramn <dchapm2@umbc.edu> | 2016-12-16 13:52:44 -0800 |
commit | cc05bcaf95b80dc89cbe1f8486c0ed14dc4d956c (patch) | |
tree | debf059c1f072e265254a5180e8fc06f74291ebf /src/survive.c | |
parent | 93ad6a810479a5cc09a809f2ea23d549c7cc9c2a (diff) | |
parent | 898a9a5f242a1691e1c34062208b48cb0682b5d9 (diff) | |
download | libsurvive-cc05bcaf95b80dc89cbe1f8486c0ed14dc4d956c.tar.gz libsurvive-cc05bcaf95b80dc89cbe1f8486c0ed14dc4d956c.tar.bz2 |
Merge branch 'master' of https://github.com/cnlohr/libsurvive
Diffstat (limited to 'src/survive.c')
-rw-r--r-- | src/survive.c | 58 |
1 files changed, 51 insertions, 7 deletions
diff --git a/src/survive.c b/src/survive.c index edcbb86..773f02a 100644 --- a/src/survive.c +++ b/src/survive.c @@ -17,13 +17,29 @@ static int jsoneq(const char *json, jsmntok_t *tok, const char *s) { return -1; } -struct SurviveContext * survive_init( void(*ff)( struct SurviveContext * ctx, const char * fault ), void(*notefunction)( struct SurviveContext * ctx, const char * note ) ) + +static void survivefault( struct SurviveContext * ctx, const char * fault ) +{ + fprintf( stderr, "Error: %s\n", fault ); + exit( -1 ); +} + +static void survivenote( struct SurviveContext * ctx, const char * fault ) +{ + fprintf( stderr, "Info: %s\n", fault ); +} + + +struct SurviveContext * survive_init() { int r = 0; - struct SurviveContext * ctx = calloc( 1, sizeof( struct SurviveContext ) ); + struct SurviveContext * ctx = calloc( 1, sizeof( struct SurviveContext ) ); + + ctx->faultfunction = survivefault; + ctx->notefunction = survivenote; - ctx->faultfunction = ff; - ctx->notefunction = notefunction; + ctx->lightproc = survive_default_light_process; + ctx->imuproc = survive_default_imu_process; ctx->headset.sensors = 32; ctx->headset.ctx = ctx; @@ -44,8 +60,6 @@ struct SurviveContext * survive_init( void(*ff)( struct SurviveContext * ctx, co return 0; } - -#if 1 //Next, pull out the config stuff. { char * ct0conf = 0; @@ -123,12 +137,42 @@ struct SurviveContext * survive_init( void(*ff)( struct SurviveContext * ctx, co } } -#endif //ctx->headset->photos = malloc( ctx->headset->sensors * sizeof(struct SurvivePhoto) ); return ctx; } +void survive_install_info_fn( struct SurviveContext * ctx, text_feedback_fnptr fbp ) +{ + if( fbp ) + ctx->notefunction = fbp; + else + ctx->notefunction = survivenote; +} + +void survive_install_error_fn( struct SurviveContext * ctx, text_feedback_fnptr fbp ) +{ + if( fbp ) + ctx->faultfunction = fbp; + else + ctx->faultfunction = survivefault; +} + +void survive_install_light_fn( struct SurviveContext * ctx, light_process_func fbp ) +{ + if( fbp ) + ctx->lightproc = fbp; + else + ctx->lightproc = survive_default_light_process; +} + +void survive_install_imu_fn( struct SurviveContext * ctx, imu_process_func fbp ) +{ + if( fbp ) + ctx->imuproc = fbp; + else + ctx->imuproc = survive_default_imu_process; +} void survive_close( struct SurviveContext * ctx ) { |