From 2d79caa41303222a8bd04075da40320398a57e0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20L=C3=B8vbr=C3=B8tte=20Olsen?= Date: Thu, 23 Mar 2017 08:48:30 +0100 Subject: [PATCH] Update borg.h --- School/vg2/borg/borg.h | 180 ++++++++++++++++++++--------------------- 1 file changed, 90 insertions(+), 90 deletions(-) diff --git a/School/vg2/borg/borg.h b/School/vg2/borg/borg.h index b2cf0a4..183fd8e 100644 --- a/School/vg2/borg/borg.h +++ b/School/vg2/borg/borg.h @@ -5,9 +5,9 @@ #include struct LEDSelect { - byte side; - byte column; - byte row; + byte side; + byte column; + byte row; }; // Decodes side, column, row into n LED @@ -32,109 +32,109 @@ void printError(CRGB color, CRGB* leds); int decodeLED(LEDSelect selection) { - return 9 * selection.side + 3 * selection.row + selection.column; + return 9 * selection.side + 3 * selection.row + selection.column; } void encodeLED(int n, LEDSelect* Result) { - Result->side = n / 9; - Result->column = n % 9 / 3; - Result->row = n % 9 % 3; + Result->side = n / 9; + Result->column = n % 9 / 3; + Result->row = n % 9 % 3; } bool setColor(LEDSelect selection, CRGB color, CRGB* leds) { - if (selection.side == 255) { - return false; - } - if (selection.column == 255 && selection.row == 255) { - for (byte n = 0; n < 9; n++) { - leds[selection.side * 9 + n] = color; - } - return true; - } - else if (selection.column == 255 && selection.row != 255) { - for (byte n = 0; n < 3; n++) { - leds[decodeLED({ selection.side, n, selection.row })] = color; - } - return true; - } - else if (selection.column != 255 && selection.row == 255) { - for (byte n = 0; n < 3; n++) { - leds[decodeLED({ selection.side, selection.column, n })] = color; - } - return true; - } - else if (selection.column != 255 && selection.row != 255) { - leds[decodeLED(selection)] = color; - return true; - } - else { - return false; - } + if (selection.side == 255) { + return false; + } + if (selection.column == 255 && selection.row == 255) { + for (byte n = 0; n < 9; n++) { + leds[selection.side * 9 + n] = color; + } + return true; + } + else if (selection.column == 255 && selection.row != 255) { + for (byte n = 0; n < 3; n++) { + leds[decodeLED({ selection.side, n, selection.row })] = color; + } + return true; + } + else if (selection.column != 255 && selection.row == 255) { + for (byte n = 0; n < 3; n++) { + leds[decodeLED({ selection.side, selection.column, n })] = color; + } + return true; + } + else if (selection.column != 255 && selection.row != 255) { + leds[decodeLED(selection)] = color; + return true; + } + else { + return false; + } } bool updateColors(LEDSelect selection, CRGB color, CRGB* leds) { - if (selection.side == 255) { - return false; - } - - - if (selection.column == 255 && selection.row == 255) { - for (int n = 0; n < 9; n++) { - CRGB* led = &leds[selection.side * 9 + n]; - if (*led != (CRGB) 0x000000) { - *led = color; - } - } - return true; - } - else if (selection.column == 255 && selection.row != 255) { - for (int n = 0; n < 3; n++) { - CRGB* led = &leds[decodeLED({ selection.side, n, selection.row })]; - if (*led != (CRGB)0x000000) { - *led = color; - } - } - return true; - } - else if (selection.column != 255 && selection.row == 255) { - for (int n = 0; n < 3; n++) { - CRGB* led = &leds[decodeLED({ selection.side, selection.column, n })]; - if (*led != (CRGB) 0x000000) { - *led = color; - } - } - return true; - } - else if (selection.column != 255 && selection.row != 255) { - CRGB* led = &leds[decodeLED(selection)]; - if (*led != (CRGB) 0x000000) { - *led = color; - } - return true; - } - else { - return false; - } + if (selection.side == 255) { + return false; + } + + + if (selection.column == 255 && selection.row == 255) { + for (int n = 0; n < 9; n++) { + CRGB* led = &leds[selection.side * 9 + n]; + if (*led != (CRGB) 0x000000) { + *led = color; + } + } + return true; + } + else if (selection.column == 255 && selection.row != 255) { + for (int n = 0; n < 3; n++) { + CRGB* led = &leds[decodeLED({ selection.side, n, selection.row })]; + if (*led != (CRGB)0x000000) { + *led = color; + } + } + return true; + } + else if (selection.column != 255 && selection.row == 255) { + for (int n = 0; n < 3; n++) { + CRGB* led = &leds[decodeLED({ selection.side, selection.column, n })]; + if (*led != (CRGB) 0x000000) { + *led = color; + } + } + return true; + } + else if (selection.column != 255 && selection.row != 255) { + CRGB* led = &leds[decodeLED(selection)]; + if (*led != (CRGB) 0x000000) { + *led = color; + } + return true; + } + else { + return false; + } } bool mirror(byte side, CRGB* leds) { - /*TODO: figure out memory structure, - copy the nine leds to the the different memory parts, so it the text is displayed on all sides. - should probably use some form of modulo - */ - for(int i = 0; i < sizeof(leds) / sizeof(CRGB); i+=9) { - memcpy(&leds[i], &leds[decodeLED({side, 0, 0})], sizeof(CRGB) * 9); - } + /*TODO: figure out memory structure, + copy the nine leds to the the different memory parts, so it the text is displayed on all sides. + should probably use some form of modulo + */ + for(int i = 0; i < sizeof(leds) / sizeof(CRGB); i+=9) { + memcpy(&leds[i], &leds[decodeLED({side, 0, 0})], sizeof(CRGB) * 9); + } } void printError(CRGB color, CRGB* leds) { - setColor({0, 255, 255}, (CRGB) color, leds); - setColor({0, 0, 1}, (CRGB) 0, leds); - setColor({0, 1, 0}, (CRGB) 0, leds); - setColor({0, 1, 2}, (CRGB) 0, leds); - setColor({0, 2, 1}, (CRGB) 0, leds); - mirror(0, leds); + setColor({0, 255, 255}, (CRGB) color, leds); + setColor({0, 0, 1}, (CRGB) 0, leds); + setColor({0, 1, 0}, (CRGB) 0, leds); + setColor({0, 1, 2}, (CRGB) 0, leds); + setColor({0, 2, 1}, (CRGB) 0, leds); + mirror(0, leds); } #endif