aboutsummaryrefslogtreecommitdiff
path: root/src/survive_data.c
diff options
context:
space:
mode:
authorcnlohr <lohr85@gmail.com>2016-12-07 17:58:57 -0500
committercnlohr <lohr85@gmail.com>2016-12-07 17:58:57 -0500
commitf03580f15d4917db2fd0790ff3718ce5ff397a75 (patch)
treed092aae0ed98aec891e68fb03dd260fb8cd968b5 /src/survive_data.c
parentc059eb3c7d5a2e42cc7bcc93b0b1549e36e042d6 (diff)
downloadlibsurvive-f03580f15d4917db2fd0790ff3718ce5ff397a75.tar.gz
libsurvive-f03580f15d4917db2fd0790ff3718ce5ff397a75.tar.bz2
Re-jigger code a little - seems to be more correct now.
Diffstat (limited to 'src/survive_data.c')
-rw-r--r--src/survive_data.c53
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 );
+ }
}
}
}