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 ++++++++++++++++++++++++++++++--------------- tools/avr_codegen/test.c | 14 +++++++++++- tools/avr_codegen/test.elf | Bin 6996 -> 7040 bytes tools/avr_codegen/test.hex | 13 ++++++----- 4 files changed, 55 insertions(+), 25 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 ); + } } } } diff --git a/tools/avr_codegen/test.c b/tools/avr_codegen/test.c index 87f0fc9..d245e16 100644 --- a/tools/avr_codegen/test.c +++ b/tools/avr_codegen/test.c @@ -71,6 +71,7 @@ int main( ) #define DO_MARKER( time, LEDS ) \ marker = time; do { PORTB = LEDS; marker--; PORTB = 0; } while( marker ); +#if 1 //this breaks it? DO_MARKER(20, LED50); DO_MARKER(20, LED50|LED48); DO_MARKER(20, LED48); @@ -81,7 +82,18 @@ int main( ) DO_MARKER(20, LED40|LED48); DO_MARKER(20, LED40); DO_MARKER(20, LED40|LED48); - DO_MARKER(20, LED48); + DO_MARKER(20, LED40); + DO_MARKER(20, LED40|LED48); + DO_MARKER(20, LED40); +#endif + +#if 0 + DO_MARKER(10, LED50); + DO_MARKER(50, LED50|LED48); + DO_MARKER(12, LED48); +#endif + + //DO_MARKER(60, LED50); // sendhex2( 5 ); diff --git a/tools/avr_codegen/test.elf b/tools/avr_codegen/test.elf index 248d6c2..3d55c28 100755 Binary files a/tools/avr_codegen/test.elf and b/tools/avr_codegen/test.elf differ diff --git a/tools/avr_codegen/test.hex b/tools/avr_codegen/test.hex index e8e3c64..2038204 100644 --- a/tools/avr_codegen/test.hex +++ b/tools/avr_codegen/test.hex @@ -1,17 +1,18 @@ :100000000EC015C014C013C012C011C010C00FC064 :100010000EC00DC00CC00BC00AC009C008C011241E -:100020001FBECFE5D2E0DEBFCDBF1AD064C0E8CF9F +:100020001FBECFE5D2E0DEBFCDBF1AD06EC0E8CF95 :100030000F931F9300E010E0980106171707280799 :10004000390759F0EFECF7E03197F1F700C0000005 :100050000F5F1F4F2F4F3F4FF0CF1F910F9108950C :10006000F89480E886BD16BC82E481BF8AE187BB34 -:1000700042E05AE038E088E190E124E148BB18BA58 -:100080002150E1F724E158BB18BA2150E1F724E1EF -:1000900038BB18BA2150E1F724E188BB18BA2150C7 +:1000700032E04AE058E088E190E124E138BB18BA68 +:100080002150E1F724E148BB18BA2150E1F724E1FF +:1000900058BB18BA2150E1F724E188BB18BA2150A7 :1000A000E1F724E198BB18BA2150E1F724E188BBBD :1000B00018BA2150E1F724E198BB18BA2150E1F7B2 :1000C00024E188BB18BA2150E1F724E198BB18BAA3 :1000D0002150E1F724E188BB18BA2150E1F724E16F -:1000E00038BB18BA2150E1F7EFEFF9EF3197F1F78C -:0A00F00000C00000C2CFF894FFCF5B +:1000E00098BB18BA2150E1F724E188BB18BA215017 +:1000F000E1F724E198BB18BA2150E1F7EFEFF9EFEF +:0E0100003197F1F700C00000B8CFF894FFCFA0 :00000001FF -- cgit v1.2.3