From 898a9a5f242a1691e1c34062208b48cb0682b5d9 Mon Sep 17 00:00:00 2001 From: cnlohr Date: Fri, 16 Dec 2016 00:41:28 -0500 Subject: Remove dependency on Xinerama Improve camfinder a little Add data_recorder.c Closes #1 making libsurvive much more pluggable. --- src/survive.c | 58 ++++++++++++++++++++++++++++++++++++++++++++------ src/survive_data.c | 29 ++++++------------------- src/survive_internal.h | 37 ++++++++------------------------ src/survive_process.c | 54 ++++++---------------------------------------- 4 files changed, 72 insertions(+), 106 deletions(-) (limited to 'src') 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 ) { diff --git a/src/survive_data.c b/src/survive_data.c index c84ab09..88c9e7d 100644 --- a/src/survive_data.c +++ b/src/survive_data.c @@ -47,7 +47,7 @@ static void handle_lightcap( struct SurviveObject * so, struct LightcapElement * ct->total_photo_time = 0; ct->total_photos = 0; ct->total_pulsecode_time = 0; - survive_light_process( so, le->sensor_id, -1, 0, le->timestamp, deltat ); + ct->lightproc( so, le->sensor_id, -1, 0, le->timestamp, deltat ); } } else @@ -73,7 +73,7 @@ static void handle_lightcap( struct SurviveObject * so, struct LightcapElement * if( offset_from < 380000 ) { - survive_light_process( so, le->sensor_id, acode, offset_from, le->timestamp, le->length ); + ct->lightproc( so, le->sensor_id, acode, offset_from, le->timestamp, le->length ); } } else @@ -158,7 +158,7 @@ static void handle_watchman( struct SurviveObject * w, uint8_t * readdata ) if( ( ( type & 0xe8 ) == 0xe8 ) || doimu ) //Hmm, this looks kind of yucky... we can get e8's that are accelgyro's but, cleared by first propset. { propset |= 2; - survive_imu_process( w, (int16_t *)&readdata[1], (time1<<24)|(time2<<16)|readdata[0], 0 ); + w->ctx->imuproc( w, (int16_t *)&readdata[1], (time1<<24)|(time2<<16)|readdata[0], 0 ); int16_t * k = (int16_t *)readdata+1; //printf( "Match8 %d %d %d %d %d %3d %3d\n", qty, k[0], k[1], k[2], k[3], k[4], k[5] ); readdata += 13; qty -= 13; @@ -178,16 +178,6 @@ static void handle_watchman( struct SurviveObject * w, uint8_t * readdata ) readdata--; *readdata = type; -#if 1 - // good good maybe? probably wrong - printf( "POST %d: %4d (%02x%02x) - ", propset, qty, time1, time2 ); - for( i = 0; i < qty + 4; i++ ) - { - printf( "%02x ", readdata[i] ); - } - printf("\n"); -#endif - uint8_t * end = &readdata[qty]; uint32_t mytime = (end[1] << 0)|(end[2] << 8)|(end[3] << 16); @@ -289,7 +279,8 @@ static void handle_watchman( struct SurviveObject * w, uint8_t * readdata ) int i; for( i = lese-1; i >= 0; i-- ) { - printf( "%d: %d [%d]\n", les[i].sensor_id, les[i].length, les[i].timestamp ); + //printf( "%d: %d [%d]\n", les[i].sensor_id, les[i].length, les[i].timestamp ); + handle_lightcap( w, &les[i] ); } return; @@ -345,14 +336,6 @@ void survive_data_cb( struct SurviveUSBInterface * si ) //printf( "%d -> ", size ); for( i = 0; i < 3; i++ ) { -/* - for( i = 0; i < 17; i++ ) - { - printf( "%02x ", readdata[i] ); - } - printf( "\n" ); -*/ - //handle_lightdata( (struct LightpulseStructure *)readdata ); int16_t * acceldata = (int16_t*)readdata; readdata += 12; uint32_t timecode = POP4; @@ -363,7 +346,7 @@ void survive_data_cb( struct SurviveUSBInterface * si ) if( cd > 0 ) { ctx->oldcode = code; - survive_imu_process( &ctx->headset, acceldata, timecode, code ); + ctx->imuproc( &ctx->headset, acceldata, timecode, code ); } } diff --git a/src/survive_internal.h b/src/survive_internal.h index 40659e8..ac378a2 100644 --- a/src/survive_internal.h +++ b/src/survive_internal.h @@ -19,6 +19,7 @@ #include #include #include +#include #define SV_INFO( x... ) { char stbuff[1024]; sprintf( stbuff, x ); ctx->notefunction( ctx, stbuff ); } #define SV_ERROR( x... ) { char stbuff[1024]; sprintf( stbuff, x ); ctx->faultfunction( ctx, stbuff ); } @@ -26,8 +27,6 @@ //XXX TODO This one needs to be rewritten. #define SV_KILL() exit(0) -#define SV_FLOAT double - #define USB_DEV_HMD 0 #define USB_DEV_LIGHTHOUSE 1 #define USB_DEV_WATCHMAN1 2 @@ -61,33 +60,20 @@ struct SurviveUSBInterface const char * hname; //human-readable names }; - -struct SurviveObject -{ - struct SurviveContext * ctx; - char codename[4]; - int16_t buttonmask; - int16_t axis1; - int16_t axis2; - int16_t axis3; - int8_t charge; - int8_t charging:1; - int8_t ison:1; - int sensors; - - int nr_locations; - SV_FLOAT * sensor_locations; -}; +//This is defined in survive.h +struct SurviveObject; struct SurviveContext { //USB Subsystem struct libusb_context* usbctx; - void(*faultfunction)( struct SurviveContext * ctx, const char * fault ); - void(*notefunction)( struct SurviveContext * ctx, const char * fault ); struct libusb_device_handle * udev[MAX_USB_DEVS]; struct SurviveUSBInterface uiface[MAX_INTERFACES]; + text_feedback_fnptr faultfunction; + text_feedback_fnptr notefunction; + light_process_func lightproc; + imu_process_func imuproc; //Flood info, for calculating which laser is currently sweeping. int8_t oldcode; @@ -113,13 +99,8 @@ int survive_get_config( char ** config, struct SurviveContext * ctx, int devno, void survive_data_cb( struct SurviveUSBInterface * si ); //Accept higher-level data. -void survive_light_process( struct SurviveObject * so, int sensor_id, int acode, int timeinsweep, uint32_t timecode, uint32_t length ); -void survive_imu_process( struct SurviveObject * so, int16_t * accelgyro, uint32_t timecode, int id ); - - -//Util -int survive_simple_inflate( struct SurviveContext * ctx, const char * input, int inlen, char * output, int outlen ); - +void survive_default_light_process( struct SurviveObject * so, int sensor_id, int acode, int timeinsweep, uint32_t timecode, uint32_t length ); +void survive_default_imu_process( struct SurviveObject * so, int16_t * accelgyro, uint32_t timecode, int id ); #endif diff --git a/src/survive_process.c b/src/survive_process.c index 046971f..d3a8c4a 100644 --- a/src/survive_process.c +++ b/src/survive_process.c @@ -8,56 +8,14 @@ int bufferpts[32*2]; char buffermts[32*128]; int buffertimeto[32]; -void survive_light_process( struct SurviveObject * so, int sensor_id, int acode, int timeinsweep, uint32_t timecode, uint32_t length ) +void survive_default_light_process( struct SurviveObject * so, int sensor_id, int acode, int timeinsweep, uint32_t timecode, uint32_t length ) { - if( acode == -1 ) return; - - if( acode == 0 || acode == 2 ) //data = 0 - { - printf( "L X %s %d %d %d %d %d\n", so->codename, timecode, sensor_id, acode, timeinsweep, length ); - bufferpts[sensor_id*2+0] = (timeinsweep-100000)/500; - buffertimeto[sensor_id] = 0; - //printf( "X: %d\n",bufferpts[sensor_id*2+0] ); - //480-(timeinsweep)/1000; // Full scan - } - if( acode == 1 || acode == 3 ) //data = 1 - { - printf( "L Y %s %d %d %d %d %d\n", so->codename, timecode, sensor_id, acode, timeinsweep, length ); - bufferpts[sensor_id*2+1] = (timeinsweep-100000)/500; - //printf( "Y: %d\n",bufferpts[sensor_id*2+1] ); - buffertimeto[sensor_id] = 0; - - //480-(timeinsweep)/1000; //Full scan - } - - - if( acode == 4 || acode == 6 ) //data = 0 - { - printf( "R X %s %d %d %d %d %d\n", so->codename, timecode, sensor_id, acode, timeinsweep, length ); - bufferpts[sensor_id*2+0] = (timeinsweep-100000)/500; - buffertimeto[sensor_id] = 0; - //printf( "X: %d\n",bufferpts[sensor_id*2+0] ); - //480-(timeinsweep)/1000; // Full scan - } - if( acode == 5 || acode == 7 ) //data = 1 - { - printf( "R Y %s %d %d %d %d %d\n", so->codename, timecode, sensor_id, acode, timeinsweep, length ); - bufferpts[sensor_id*2+1] = (timeinsweep-100000)/500; - //printf( "Y: %d\n",bufferpts[sensor_id*2+1] ); - buffertimeto[sensor_id] = 0; - - //480-(timeinsweep)/1000; //Full scan - } - - - //timeinsweep = 200,000 1/48,000,000ths of a second is "center-of-image" + //TODO: Writeme! } -void survive_imu_process( struct SurviveObject * so, int16_t * accelgyro, uint32_t timecode, int id ) +void survive_default_imu_process( struct SurviveObject * so, int16_t * accelgyro, uint32_t timecode, int id ) { - //if( so->codename[0] == 'H' ) - if( 1 ) - { - printf( "I %s %d %d %d %d %d %d %d %d\n", so->codename, timecode, accelgyro[0], accelgyro[1], accelgyro[2], accelgyro[3], accelgyro[4], accelgyro[5], id ); - } + //TODO: Writeme! } + + -- cgit v1.2.3