aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcnlohr <lohr85@gmail.com>2016-12-07 01:15:31 -0500
committercnlohr <lohr85@gmail.com>2016-12-07 01:15:31 -0500
commitc059eb3c7d5a2e42cc7bcc93b0b1549e36e042d6 (patch)
treeb58d236d22741671541ddd489bdce4d2586067dc
parente6c6675fd9da8b4ced425ec82e67140eedcd40e8 (diff)
downloadlibsurvive-c059eb3c7d5a2e42cc7bcc93b0b1549e36e042d6.tar.gz
libsurvive-c059eb3c7d5a2e42cc7bcc93b0b1549e36e042d6.tar.bz2
Update! Getting very close.
-rw-r--r--src/survive_data.c97
-rw-r--r--tools/avr_codegen/Makefile8
-rw-r--r--tools/avr_codegen/test.c15
-rwxr-xr-xtools/avr_codegen/test.elfbin9820 -> 6996 bytes
-rw-r--r--tools/avr_codegen/test.hex37
5 files changed, 126 insertions, 31 deletions
diff --git a/src/survive_data.c b/src/survive_data.c
index bb8836d..0a2b8b2 100644
--- a/src/survive_data.c
+++ b/src/survive_data.c
@@ -194,6 +194,7 @@ static void handle_watchman( struct SurviveObject * w, uint8_t * readdata )
if( qty )
{
+ int j;
qty++;
readdata--;
*readdata = type;
@@ -285,7 +286,99 @@ static void handle_watchman( struct SurviveObject * w, uint8_t * readdata )
SV_INFO( "Watchman code count doesn't match" );
return;
}
+#if 1
+ //This is getting very close.
+
+ const int M_LEDS = 32;
+ uint8_t onleds[M_LEDS];
+ uint32_t offtimes[M_LEDS];
+ memset( onleds, 0, sizeof( onleds ) );
+ int k = 0;
+
+ for( i = lightno-1; i >= 0; i-- )
+ {
+ int led = lights[i]>>3;
+ int ledtime = lights[i]&0x07;
+ int deltaA = k?parameters[k*2-1]:0;
+ int deltaB = parameters[k*2+0];
+
+ k++;
+
+ onleds[led] = ledtime+2;
+ offtimes[led] = mytime;
+ printf( "%d %d %d %d\n", led, ledtime, deltaA, deltaB );
+
+ mytime -= deltaA;
+
+ for( j = 0; j < M_LEDS; j++ )
+ {
+ if( onleds[j] )
+ {
+ 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 );
+ }
+ }
+ }
+ mytime -= deltaB;
+ for( j = 0; j < M_LEDS; j++ )
+ {
+ if( onleds[j] )
+ {
+ 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 );
+ }
+ }
+ }
+ }
+
+ for( j = 0; j < M_LEDS; j++ )
+ {
+ if( onleds[j] )
+ {
+ fprintf(stderr, "ERROR: Too many LEDs found (%d = %d)\n", j, onleds[j] );
+ }
+ }
+
+#endif
+
+
+/*
+ static int olddel = 0;
+ int lightmask = lights[0];
+ //Operting on mytime
+ printf( "Events (%10d): ", mytime );
+ for( i = 0; i < lightno; i++ )
+ {
+ int deltaA = parameters[parplace-i*2-1];
+ int deltaB = -1;
+ if( parplace-i*2-2 >= 0 )
+ deltaB = parameters[parplace-i*2-2];
+ printf( "%02x/(%5d/%5d)", lightmask, deltaA, deltaB );
+ if( lightno-i-2 >= 0 )
+ lightmask = lights[i+1];
+ }
+ printf( "\n");
+
+*/
//What I think I know:
// 2 pulses: mytime pulse? deltime? deltime? pulse? deltime?
// 3 pulses: mytime pulse? deltime? deltime? pulse? deltime? deltime? pulse deltime?
@@ -342,8 +435,8 @@ static void handle_watchman( struct SurviveObject * w, uint8_t * readdata )
// mask = LEDs on.
// parameter = delta
// mask = Led mask switching
+/*
static int olddel = 0;
-
int lightmask = lights[0];
//
@@ -364,7 +457,7 @@ static void handle_watchman( struct SurviveObject * w, uint8_t * readdata )
lightmask = lights[i+1];
}
printf( "\n");
-
+*/
//Three distinct motions.
// 40 nothing (long wait) 48 nothing 50 nothing (long pulse)
// 40/( 524/ 2262)48/( 522/ 570)50/( 874/ -1)
diff --git a/tools/avr_codegen/Makefile b/tools/avr_codegen/Makefile
index 2d3a17e..e7b8673 100644
--- a/tools/avr_codegen/Makefile
+++ b/tools/avr_codegen/Makefile
@@ -12,11 +12,11 @@ test.hex : test.elf
avr-objcopy -j .text -j .data -O ihex test.elf test.hex
avrdude -c usbtiny -p $(PROGPART) -V -U flash:w:test.hex
-test.elf : test.c avr_print.c
- avr-gcc -I -g $(CFLAGS) -mmcu=$(PART) -Wl,-Map,test.map -o $@ test.c avr_print.c -L/usr/lib/binutils/avr/2.18
+test.elf : test.c
+ avr-gcc -I -g $(CFLAGS) -mmcu=$(PART) -Wl,-Map,test.map -o $@ test.c -L/usr/lib/binutils/avr/2.18
-test.lst : test.c avr_print.c
- avr-gcc -c -g -Wa,-a,-ad $(CFLAGS) test.c avr_print.c > $@
+test.lst : test.c
+ avr-gcc -c -g -Wa,-a,-ad $(CFLAGS) test.c > $@
burn : test.hex
avrdude -c usbtiny -p $(PROGPART) -V -U flash:w:test.hex
diff --git a/tools/avr_codegen/test.c b/tools/avr_codegen/test.c
index 0215e09..87f0fc9 100644
--- a/tools/avr_codegen/test.c
+++ b/tools/avr_codegen/test.c
@@ -71,11 +71,18 @@ int main( )
#define DO_MARKER( time, LEDS ) \
marker = time; do { PORTB = LEDS; marker--; PORTB = 0; } while( marker );
+ DO_MARKER(20, LED50);
+ DO_MARKER(20, LED50|LED48);
+ DO_MARKER(20, LED48);
+ DO_MARKER(20, LED40|LED48);
DO_MARKER(20, LED40);
- DO_MARKER(35, LED50|LED40);
- DO_MARKER(25, LED50);
- DO_MARKER(45, LED50|LED48);
- DO_MARKER(60, LED50);
+ DO_MARKER(20, LED40|LED48);
+ DO_MARKER(20, LED40);
+ DO_MARKER(20, LED40|LED48);
+ DO_MARKER(20, LED40);
+ DO_MARKER(20, LED40|LED48);
+ DO_MARKER(20, LED48);
+ //DO_MARKER(60, LED50);
// sendhex2( 5 );
// sendchr('\n');
diff --git a/tools/avr_codegen/test.elf b/tools/avr_codegen/test.elf
index f9fd72e..248d6c2 100755
--- a/tools/avr_codegen/test.elf
+++ b/tools/avr_codegen/test.elf
Binary files differ
diff --git a/tools/avr_codegen/test.hex b/tools/avr_codegen/test.hex
index 1d0610e..e8e3c64 100644
--- a/tools/avr_codegen/test.hex
+++ b/tools/avr_codegen/test.hex
@@ -1,22 +1,17 @@
-:100000000EC028C027C026C025C024C023C022C0DF
-:1000100021C020C01FC01EC01DC01CC01BC0112499
-:100020001FBECFE5D2E0DEBFCDBF10E0A0E6B0E05E
-:10003000ECE3F1E002C005900D92AE36B107D9F7BE
-:1000400020E0AEE6B0E001C01D92A437B207E1F7B0
-:1000500047D072C0D5CF0F931F9300E010E09801F6
-:10006000061717072807390759F0EFECF7E0319723
-:10007000F1F700C000000F5F1F4F2F4F3F4FF0CF31
-:100080001F910F910895769BFECF8FB980E48EB9B2
-:100090000895F9DF80E090E008958A3010F4805DE3
-:1000A00001C0895CF0CFCF93C82F82958F70F5DFA8
-:1000B0008C2F8F70CF91F1CFCF93C82F892FF3DF83
-:1000C0008C2FCF91F0CF87B38A7F87BBB99A88E115
-:1000D0008DB980E690E09093710080937000089550
-:1000E000F89480E886BD16BC82E481BF8AE187BBB4
-:1000F00020E132E192E04AE084E128BB18BA815065
-:10010000E1F783E238BB18BA8150E1F789E198BB87
-:1001100018BA8150E1F78DE248BB18BA8150E1F777
-:100120008CE398BB18BA8150E1F7EFEFF9EF319704
-:0C013000F1F700C00000E0CFF894FFCF12
-:0E013C0000000002000000004900000000006A
+:100000000EC015C014C013C012C011C010C00FC064
+:100010000EC00DC00CC00BC00AC009C008C011241E
+:100020001FBECFE5D2E0DEBFCDBF1AD064C0E8CF9F
+:100030000F931F9300E010E0980106171707280799
+:10004000390759F0EFECF7E03197F1F700C0000005
+:100050000F5F1F4F2F4F3F4FF0CF1F910F9108950C
+:10006000F89480E886BD16BC82E481BF8AE187BB34
+:1000700042E05AE038E088E190E124E148BB18BA58
+:100080002150E1F724E158BB18BA2150E1F724E1EF
+:1000900038BB18BA2150E1F724E188BB18BA2150C7
+:1000A000E1F724E198BB18BA2150E1F724E188BBBD
+:1000B00018BA2150E1F724E198BB18BA2150E1F7B2
+:1000C00024E188BB18BA2150E1F724E198BB18BAA3
+:1000D0002150E1F724E188BB18BA2150E1F724E16F
+:1000E00038BB18BA2150E1F7EFEFF9EF3197F1F78C
+:0A00F00000C00000C2CFF894FFCF5B
:00000001FF