From 7930400aaca31089be48fe077d0c591294d727a5 Mon Sep 17 00:00:00 2001 From: cnlohr Date: Wed, 30 Nov 2016 23:55:04 -0500 Subject: Update the thing to get a specific tag --- src/survive.c | 3 +++ src/survive_data.c | 47 +++++++++++++++++++++++++++++++++++++++++++---- src/survive_internal.h | 13 +++++++++---- 3 files changed, 55 insertions(+), 8 deletions(-) diff --git a/src/survive.c b/src/survive.c index 6fa6fb3..97493a0 100644 --- a/src/survive.c +++ b/src/survive.c @@ -14,6 +14,9 @@ struct SurviveContext * survive_init( void(*ff)( struct SurviveContext * ctx, co return 0; } + ret->headset.sensors = 32; + ret->headset.ctx = ret; + //ret->headset->photos = malloc( ret->headset->sensors * sizeof(struct SurvivePhoto) ); return ret; } diff --git a/src/survive_data.c b/src/survive_data.c index c384b52..7f709a5 100644 --- a/src/survive_data.c +++ b/src/survive_data.c @@ -39,10 +39,49 @@ struct LightcapElement } __attribute__((packed)); -static void handle_lightcap( struct SurviveUSBInterface * si, struct LightcapElement * le ) +//XXX: TODO: Is the 'timestamp' in the middle of the pulse or beginning??? +static void handle_lightcap( struct SurviveObject * so, struct LightcapElement * le ) { - if( le->type != 0xfe || le->length < 1 ) return; - printf( "%3d %3d %6d %8d\n", le->sensor_id, le->type, le->length, le->timestamp ); + if( le->type != 0xfe || le->length < 50 ) return; + + //le->timestamp += (le->length/2); + + if( le->length > 900 ) //Pulse longer than 18us? + { + int32_t deltat = le->timestamp - so->last_photo_time; + if( deltat > 2000 ) //New pulse. + { + so->last_photo_time = le->timestamp; + so->total_photo_time = 0; + so->total_photos = 0; + } + else + { + so->total_photo_time += deltat; + so->total_photos++; + } + } + else if( le->length < 900 && le->length > 50 && so->total_photos ) + { + int32_t offset_from = le->timestamp - (so->total_photo_time/so->total_photos) - so->last_photo_time; + if( le->sensor_id == 9 ) + + if( offset_from > 200000 ) + printf( "%3d %3d %3d %3d\n", le->sensor_id, le->type, le->length, offset_from ); + } + else + { + //Runt pulse. + } +/* + struct SurviveContext * ctx; + int last_photo_time; + int total_photos; + float total_photo_time; + + int sensors; + + printf( "%3d %3d %6d %8d\n", le->sensor_id, le->type, le->length, le->timestamp );*/ } @@ -213,7 +252,7 @@ void survive_data_cb( struct SurviveUSBInterface * si ) int i; for( i = 0; i < 7; i++ ) { - handle_lightcap( si, &readdata[i*8] ); + handle_lightcap( &si->ctx->headset, (struct LightcapElement*)&readdata[i*8] ); } break; } diff --git a/src/survive_internal.h b/src/survive_internal.h index 394842b..a7d8ca9 100644 --- a/src/survive_internal.h +++ b/src/survive_internal.h @@ -45,11 +45,14 @@ struct SurviveUSBInterface const char * hname; //human-readable names }; -struct SurvivePhoto + +struct SurviveObject { - uint32_t last; - uint32_t lastcode; - uint32_t lastlength; + struct SurviveContext * ctx; + int32_t last_photo_time; + short total_photos; + int32_t total_photo_time; + int sensors; }; struct SurviveContext @@ -61,6 +64,8 @@ struct SurviveContext struct libusb_device_handle * udev[MAX_USB_DEVS]; struct SurviveUSBInterface uiface[MAX_INTERFACES]; + //Data Subsystem + struct SurviveObject headset; // struct SurvivePhoto }; -- cgit v1.2.3