Fixed bug where LED output would halt at ~70 minutes. Thanks, StringCheeseCR!

This commit is contained in:
Paint Your Dragon 2011-11-07 12:14:44 -08:00
parent efe5fd5cbd
commit fb1c294fda
1 changed files with 11 additions and 8 deletions

View File

@ -77,11 +77,12 @@ void setup()
hi, lo, chk, i, spiFlag;
int16_t
bytesBuffered = 0,
hold = 0,
c;
int32_t
bytesRemaining;
unsigned long
t = 0;
startTime = micros();
LED_DDR |= LED_PIN; // Enable output for LED
LED_PORT &= ~LED_PIN; // LED off
@ -145,8 +146,8 @@ void setup()
// (# LEDs is always > 0) and multiply by 3 for R,G,B.
bytesRemaining = 3L * (256L * (long)hi + (long)lo + 1L);
bytesBuffered -= 3;
mode = MODE_HOLD; // Proceed to latch wait mode
spiFlag = 0; // No data out yet
mode = MODE_HOLD; // Proceed to latch wait mode
} else {
// Checksum didn't match; search resumes after magic word.
indexOut -= 3; // Rewind
@ -162,7 +163,7 @@ void setup()
// to complete" mode, but may also revert to this mode when
// underrun prevention necessitates a delay.
if(micros() < t) break; // Still holding; continue buffering.
if((micros() - startTime) < hold) break; // Still holding; keep buffering
// Latch/delay complete. Advance to data-issuing mode...
LED_PORT &= ~LED_PIN; // LED off
@ -182,12 +183,14 @@ void setup()
// introducing progressively longer pauses to allow more
// data to arrive (up to a point).
if((bytesBuffered < 32) && (bytesRemaining > bytesBuffered)) {
startTime = micros();
hold = 100 + (32 - bytesBuffered) * 10;
mode = MODE_HOLD;
t = micros() + 60 + (32 - bytesBuffered) * 20;
}
} else {
// End of data -- issue latch:
t = micros() + 1000; // Latch duration = 1000 uS
startTime = micros();
hold = 1000; // Latch duration = 1000 uS
LED_PORT |= LED_PIN; // LED on
mode = MODE_HEADER; // Begin next header search
}