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