aboutsummaryrefslogtreecommitdiff
path: root/src/survive_data.c
diff options
context:
space:
mode:
authorcnlohr <lohr85@gmail.com>2016-11-30 23:55:04 -0500
committercnlohr <lohr85@gmail.com>2016-11-30 23:55:04 -0500
commit7930400aaca31089be48fe077d0c591294d727a5 (patch)
tree8f9119efa9ce24dc12e23eb0d564ba9281e10411 /src/survive_data.c
parent8b77db6280c6d832eb89455e1b30877454a9a5a1 (diff)
downloadlibsurvive-7930400aaca31089be48fe077d0c591294d727a5.tar.gz
libsurvive-7930400aaca31089be48fe077d0c591294d727a5.tar.bz2
Update the thing to get a specific tag
Diffstat (limited to 'src/survive_data.c')
-rw-r--r--src/survive_data.c47
1 files changed, 43 insertions, 4 deletions
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;
}