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,
// 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 HEADERSIZE (MAGICSIZE + 3)
@ -135,18 +135,18 @@ void setup()
// 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.
uint8_t testcolor[] = { 0, 0, 0, 255, 0, 0 };
for(int i=0; i<4; i++){ //Start Frame
for(SPDR = 0x00; !(SPSR & _BV(SPIF)); );
for (int i = 0; i < 4; i++) { //Start Frame
for (SPDR = 0x00; !(SPSR & _BV(SPIF)); );
}
for(char n=3; n>=0; n--) {
for(c=0; c<25000; c++) {
for(SPDR = 0xFF; !(SPSR & _BV(SPIF)); ); //Brightness byte
for(i=0; i<3; i++) {
for(SPDR = testcolor[n + i]; !(SPSR & _BV(SPIF)); ); //BGR
for (char n = 3; n >= 0; n--) {
for (c = 0; c < 25000; c++) {
for (SPDR = 0xFF; !(SPSR & _BV(SPIF)); ); //Brightness byte
for (i = 0; i < 3; i++) {
for (SPDR = testcolor[n + i]; !(SPSR & _BV(SPIF)); ); //BGR
}
}
for(int i=0; i<4; i++){ //Stop Frame
for(SPDR = 0xFF; !(SPSR & _BV(SPIF)); );
for (int i = 0; i < 4; i++) { //Stop Frame
for (SPDR = 0xFF; !(SPSR & _BV(SPIF)); );
}
delay(1); // One millisecond pause = latch
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
// has a measurable impact on this code's overall throughput.
for(;;) {
for (;;) {
digitalWrite(DATA_LED, LOW);
digitalWrite(SPI_LED, LOW);
// Implementation is a simple finite-state machine.
// Regardless of mode, check for serial input each time:
t = millis();
if((bytesBuffered < 256) && ((c = Serial.read()) >= 0)) {
if ((bytesBuffered < 256) && ((c = Serial.read()) >= 0)) {
buffer[indexIn++] = c;
bytesBuffered++;
lastByteTime = lastAckTime = t; // Reset timeout counters
} else {
// No data received. If this persists, send an ACK packet
// 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
lastAckTime = t; // Reset counter
}
// If no data received for an extended time, turn off all LEDs.
if((t - lastByteTime) > serialTimeout) {
for(i=0;i<4;i++) { //Start Frame
for(SPDR = 0x00; !(SPSR & _BV(SPIF)); );
if ((t - lastByteTime) > serialTimeout) {
for (i = 0; i < 4; i++) { //Start Frame
for (SPDR = 0x00; !(SPSR & _BV(SPIF)); );
}
for(c=0; c<25000; c++) {
for(SPDR = 0xFF; !(SPSR & _BV(SPIF)); ); //Brightness Byte
for(i=0; i<3; i++) {
for(SPDR = 0x00; !(SPSR & _BV(SPIF)); ); //BGR
for (c = 0; c < 25000; c++) {
for (SPDR = 0xFF; !(SPSR & _BV(SPIF)); ); //Brightness Byte
for (i = 0; i < 3; i++) {
for (SPDR = 0x00; !(SPSR & _BV(SPIF)); ); //BGR
}
}
for(i=0;i<4;i++) { //Stop Frame
for(SPDR = 0xFF; !(SPSR & _BV(SPIF)); );
for (i = 0; i < 4; i++) { //Stop Frame
for (SPDR = 0xFF; !(SPSR & _BV(SPIF)); );
}
delay(1); // One millisecond pause = latch
lastByteTime = t; // Reset counter
}
}
switch(mode) {
switch (mode) {
case MODE_HEADER:
// In header-seeking mode. Is there enough data to check?
if(bytesBuffered >= HEADERSIZE) {
if (bytesBuffered >= HEADERSIZE) {
// Indeed. Check for a 'magic word' match.
for(i=0; (i<MAGICSIZE) && (buffer[indexOut++] == magic[i++]););
if(i == MAGICSIZE) {
for (i = 0; (i < MAGICSIZE) && (buffer[indexOut++] == magic[i++]););
if (i == MAGICSIZE) {
// Magic word matches. Now how about the checksum?
hi = buffer[indexOut++];
lo = 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
// (# 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;
spiFlag = 0; // No data out yet
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
// 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...
LED_PORT &= ~LED_PIN; // LED off
@ -240,9 +240,9 @@ void setup()
case MODE_DATA:
digitalWrite(SPI_LED, spi_out_led = !spi_out_led);
while(spiFlag && !(SPSR & _BV(SPIF))); // Wait for prior byte
if(bytesRemaining > 0) {
if(bytesBuffered > 0) {
while (spiFlag && !(SPSR & _BV(SPIF))); // Wait for prior byte
if (bytesRemaining > 0) {
if (bytesBuffered > 0) {
SPDR = buffer[indexOut++]; // Issue next byte
bytesBuffered--;
bytesRemaining--;
@ -255,7 +255,7 @@ void setup()
// startTime = micros();
// hold = 100 + (32 - bytesBuffered) * 10;
// mode = MODE_HOLD;
//}
//}
} else {
// End of data -- issue latch:
startTime = micros();