From f03580f15d4917db2fd0790ff3718ce5ff397a75 Mon Sep 17 00:00:00 2001 From: cnlohr Date: Wed, 7 Dec 2016 17:58:57 -0500 Subject: Re-jigger code a little - seems to be more correct now. --- src/survive_data.c | 53 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 18 deletions(-) (limited to 'src/survive_data.c') diff --git a/src/survive_data.c b/src/survive_data.c index 0a2b8b2..9bc934a 100644 --- a/src/survive_data.c +++ b/src/survive_data.c @@ -304,27 +304,37 @@ static void handle_watchman( struct SurviveObject * w, uint8_t * readdata ) k++; - onleds[led] = ledtime+2; + onleds[led] = ledtime+1; offtimes[led] = mytime; printf( "%d %d %d %d\n", led, ledtime, deltaA, deltaB ); - mytime -= deltaA; - - for( j = 0; j < M_LEDS; j++ ) + if( deltaA ) { - if( onleds[j] ) + mytime -= deltaA; + + for( j = 0; j < M_LEDS; j++ ) { - onleds[j]--; - if( !onleds[j] ) + if( onleds[j] ) { - //Got a light event. - struct LightcapElement le; - le.type = 0xfe; - le.sensor_id = j; - le.timestamp = mytime; - le.length = offtimes[j] - mytime; - handle_lightcap( w, &le ); - printf( "Light Event: LED %d @ %d, len %d (%d)\n", j, mytime, le.length, deltaB ); + onleds[j]--; + if( !onleds[j] ) + { + //Got a light event. + struct LightcapElement le; + le.type = 0xfe; + le.sensor_id = j; + le.timestamp = mytime; + if( offtimes[j] - mytime > 65535 ) + { + printf( "OFLOW: LED %d @ %d, len %d\n", j, mytime, offtimes[j] - mytime ); + } + else + { + le.length = offtimes[j] - mytime; + handle_lightcap( w, &le ); + printf( "Light Event: LED %d @ %d, len %d\n", j, mytime, le.length ); + } + } } } } @@ -341,9 +351,16 @@ static void handle_watchman( struct SurviveObject * w, uint8_t * readdata ) le.type = 0xfe; le.sensor_id = j; le.timestamp = mytime; - le.length = offtimes[j] - mytime; - handle_lightcap( w, &le ); - printf( "Light Event: LED %d @ %d, len %d (%d)\n", j, mytime, le.length, deltaB ); + if( offtimes[j] - mytime > 65535 ) + { + printf( "OFLOW: LED %d @ %d, len %d\n", j, mytime, offtimes[j] - mytime ); + } + else + { + le.length = offtimes[j] - mytime; + handle_lightcap( w, &le ); + printf( "Light Event: LED %d @ %d, len %d\n", j, mytime, le.length ); + } } } } -- cgit v1.2.3