reformated code

(Arduino IDE auto-reformat)


Former-commit-id: 8f94b2bb865337ba7b0538617857432ea0376aea
This commit is contained in:
Schöck, Florian 2015-11-29 19:24:01 +01:00
parent cf359e5182
commit f910c717bb

View File

@ -71,7 +71,7 @@
// XOR 0x55). LED data follows, 3 bytes per LED, in order R, G, B, // XOR 0x55). LED data follows, 3 bytes per LED, in order R, G, B,
// where 0 = off and 255 = max brightness. // where 0 = off and 255 = max brightness.
static const uint8_t magic[] = {'A','d','a'}; static const uint8_t magic[] = {'A', 'd', 'a'};
#define MAGICSIZE sizeof(magic) #define MAGICSIZE sizeof(magic)
#define HEADERSIZE (MAGICSIZE + 3) #define HEADERSIZE (MAGICSIZE + 3)
@ -135,18 +135,18 @@ void setup()
// green, blue, then off. Once you're confident everything is working // green, blue, then off. Once you're confident everything is working
// end-to-end, it's OK to comment this out and reprogram the Arduino. // end-to-end, it's OK to comment this out and reprogram the Arduino.
uint8_t testcolor[] = { 0, 0, 0, 255, 0, 0 }; uint8_t testcolor[] = { 0, 0, 0, 255, 0, 0 };
for(int i=0; i<4; i++){ //Start Frame for (int i = 0; i < 4; i++) { //Start Frame
for(SPDR = 0x00; !(SPSR & _BV(SPIF)); ); for (SPDR = 0x00; !(SPSR & _BV(SPIF)); );
} }
for(char n=3; n>=0; n--) { for (char n = 3; n >= 0; n--) {
for(c=0; c<25000; c++) { for (c = 0; c < 25000; c++) {
for(SPDR = 0xFF; !(SPSR & _BV(SPIF)); ); //Brightness byte for (SPDR = 0xFF; !(SPSR & _BV(SPIF)); ); //Brightness byte
for(i=0; i<3; i++) { for (i = 0; i < 3; i++) {
for(SPDR = testcolor[n + i]; !(SPSR & _BV(SPIF)); ); //BGR for (SPDR = testcolor[n + i]; !(SPSR & _BV(SPIF)); ); //BGR
} }
} }
for(int i=0; i<4; i++){ //Stop Frame for (int i = 0; i < 4; i++) { //Stop Frame
for(SPDR = 0xFF; !(SPSR & _BV(SPIF)); ); for (SPDR = 0xFF; !(SPSR & _BV(SPIF)); );
} }
delay(1); // One millisecond pause = latch delay(1); // One millisecond pause = latch
digitalWrite(SPI_LED, spi_out_led = !spi_out_led); digitalWrite(SPI_LED, spi_out_led = !spi_out_led);
@ -160,59 +160,59 @@ void setup()
// loop() is avoided as even that small bit of function overhead // loop() is avoided as even that small bit of function overhead
// has a measurable impact on this code's overall throughput. // has a measurable impact on this code's overall throughput.
for(;;) { for (;;) {
digitalWrite(DATA_LED, LOW); digitalWrite(DATA_LED, LOW);
digitalWrite(SPI_LED, LOW); digitalWrite(SPI_LED, LOW);
// Implementation is a simple finite-state machine. // Implementation is a simple finite-state machine.
// Regardless of mode, check for serial input each time: // Regardless of mode, check for serial input each time:
t = millis(); t = millis();
if((bytesBuffered < 256) && ((c = Serial.read()) >= 0)) { if ((bytesBuffered < 256) && ((c = Serial.read()) >= 0)) {
buffer[indexIn++] = c; buffer[indexIn++] = c;
bytesBuffered++; bytesBuffered++;
lastByteTime = lastAckTime = t; // Reset timeout counters lastByteTime = lastAckTime = t; // Reset timeout counters
} else { } else {
// No data received. If this persists, send an ACK packet // No data received. If this persists, send an ACK packet
// to host once every second to alert it to our presence. // to host once every second to alert it to our presence.
if((t - lastAckTime) > 1000) { if ((t - lastAckTime) > 1000) {
Serial.print("Ada\n"); // Send ACK string to host Serial.print("Ada\n"); // Send ACK string to host
lastAckTime = t; // Reset counter lastAckTime = t; // Reset counter
} }
// If no data received for an extended time, turn off all LEDs. // If no data received for an extended time, turn off all LEDs.
if((t - lastByteTime) > serialTimeout) { if ((t - lastByteTime) > serialTimeout) {
for(i=0;i<4;i++) { //Start Frame for (i = 0; i < 4; i++) { //Start Frame
for(SPDR = 0x00; !(SPSR & _BV(SPIF)); ); for (SPDR = 0x00; !(SPSR & _BV(SPIF)); );
} }
for(c=0; c<25000; c++) { for (c = 0; c < 25000; c++) {
for(SPDR = 0xFF; !(SPSR & _BV(SPIF)); ); //Brightness Byte for (SPDR = 0xFF; !(SPSR & _BV(SPIF)); ); //Brightness Byte
for(i=0; i<3; i++) { for (i = 0; i < 3; i++) {
for(SPDR = 0x00; !(SPSR & _BV(SPIF)); ); //BGR for (SPDR = 0x00; !(SPSR & _BV(SPIF)); ); //BGR
} }
} }
for(i=0;i<4;i++) { //Stop Frame for (i = 0; i < 4; i++) { //Stop Frame
for(SPDR = 0xFF; !(SPSR & _BV(SPIF)); ); for (SPDR = 0xFF; !(SPSR & _BV(SPIF)); );
} }
delay(1); // One millisecond pause = latch delay(1); // One millisecond pause = latch
lastByteTime = t; // Reset counter lastByteTime = t; // Reset counter
} }
} }
switch(mode) { switch (mode) {
case MODE_HEADER: case MODE_HEADER:
// In header-seeking mode. Is there enough data to check? // In header-seeking mode. Is there enough data to check?
if(bytesBuffered >= HEADERSIZE) { if (bytesBuffered >= HEADERSIZE) {
// Indeed. Check for a 'magic word' match. // Indeed. Check for a 'magic word' match.
for(i=0; (i<MAGICSIZE) && (buffer[indexOut++] == magic[i++]);); for (i = 0; (i < MAGICSIZE) && (buffer[indexOut++] == magic[i++]););
if(i == MAGICSIZE) { if (i == MAGICSIZE) {
// Magic word matches. Now how about the checksum? // Magic word matches. Now how about the checksum?
hi = buffer[indexOut++]; hi = buffer[indexOut++];
lo = buffer[indexOut++]; lo = buffer[indexOut++];
chk = buffer[indexOut++]; chk = buffer[indexOut++];
if(chk == (hi ^ lo ^ 0x55)) { if (chk == (hi ^ lo ^ 0x55)) {
// Checksum looks valid. Get 16-bit LED count, add 1 // Checksum looks valid. Get 16-bit LED count, add 1
// (# 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 = 4L * (256L * (long)hi + (long)lo) +4L + (256L *(long)hi + (long)lo +15)/16; bytesRemaining = 4L * (256L * (long)hi + (long)lo) + 4L + (256L * (long)hi + (long)lo + 15) / 16;
bytesBuffered -= 3; bytesBuffered -= 3;
spiFlag = 0; // No data out yet spiFlag = 0; // No data out yet
mode = MODE_HOLD; // Proceed to latch wait mode mode = MODE_HOLD; // Proceed to latch wait mode
@ -232,7 +232,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() - startTime) < hold) break; // Still holding; keep 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
@ -240,9 +240,9 @@ void setup()
case MODE_DATA: case MODE_DATA:
digitalWrite(SPI_LED, spi_out_led = !spi_out_led); digitalWrite(SPI_LED, spi_out_led = !spi_out_led);
while(spiFlag && !(SPSR & _BV(SPIF))); // Wait for prior byte while (spiFlag && !(SPSR & _BV(SPIF))); // Wait for prior byte
if(bytesRemaining > 0) { if (bytesRemaining > 0) {
if(bytesBuffered > 0) { if (bytesBuffered > 0) {
SPDR = buffer[indexOut++]; // Issue next byte SPDR = buffer[indexOut++]; // Issue next byte
bytesBuffered--; bytesBuffered--;
bytesRemaining--; bytesRemaining--;
@ -255,7 +255,7 @@ void setup()
// startTime = micros(); // startTime = micros();
// hold = 100 + (32 - bytesBuffered) * 10; // hold = 100 + (32 - bytesBuffered) * 10;
// mode = MODE_HOLD; // mode = MODE_HOLD;
//} //}
} else { } else {
// End of data -- issue latch: // End of data -- issue latch:
startTime = micros(); startTime = micros();