diff options
author | cnlohr <lohr85@gmail.com> | 2016-12-07 17:58:57 -0500 |
---|---|---|
committer | cnlohr <lohr85@gmail.com> | 2016-12-07 17:58:57 -0500 |
commit | f03580f15d4917db2fd0790ff3718ce5ff397a75 (patch) | |
tree | d092aae0ed98aec891e68fb03dd260fb8cd968b5 /src | |
parent | c059eb3c7d5a2e42cc7bcc93b0b1549e36e042d6 (diff) | |
download | libsurvive-f03580f15d4917db2fd0790ff3718ce5ff397a75.tar.gz libsurvive-f03580f15d4917db2fd0790ff3718ce5ff397a75.tar.bz2 |
Re-jigger code a little - seems to be more correct now.
Diffstat (limited to 'src')
-rw-r--r-- | src/survive_data.c | 53 |
1 files changed, 35 insertions, 18 deletions
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 ); + } } } } |