2017-01-03 09:00:38 +01:00
|
|
|
#ifndef borg_h
|
|
|
|
#define borg_h
|
|
|
|
|
|
|
|
#include "Arduino.h"
|
|
|
|
#include <FastLED.h>
|
|
|
|
|
2017-01-03 09:15:19 +01:00
|
|
|
struct LEDSelect {
|
|
|
|
byte side;
|
|
|
|
byte column;
|
|
|
|
byte row;
|
2017-01-03 09:00:38 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// Decodes side, column, row into n LED
|
|
|
|
int decodeLED(LEDSelect selection);
|
2017-01-16 09:18:45 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Set Color
|
|
|
|
** Takes a led selection,
|
|
|
|
** The last two propertries can be 255, meaning no information
|
|
|
|
** the property that is 255 will be inclusively filled with the CRGB color
|
|
|
|
*/
|
2017-01-03 09:00:38 +01:00
|
|
|
bool setColor(LEDSelect selection, CRGB* leds);
|
2017-01-16 09:18:45 +01:00
|
|
|
// Sets every color that isn't black
|
|
|
|
bool updateColors(LEDSelect selection, CRGB* leds);
|
|
|
|
// Mirrors one side to every other side
|
|
|
|
bool mirror(byte side, CRGB* leds);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-01-03 09:00:38 +01:00
|
|
|
|
|
|
|
int decodeLED(LEDSelect selection) {
|
|
|
|
return 9 * selection.side + 3 * selection.row + selection.column;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-16 09:18:45 +01:00
|
|
|
bool updateColors(LEDSelect selection, CRGB color, CRGB* leds) {
|
2017-01-03 09:00:38 +01:00
|
|
|
if (selection.side == 255) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-01-03 09:30:34 +01:00
|
|
|
|
|
|
|
|
2017-01-03 09:00:38 +01:00
|
|
|
if (selection.column == 255 && selection.row == 255) {
|
|
|
|
for (int n = 0; n < 9; n++) {
|
|
|
|
CRGB* led = &leds[selection.side * 9 + n];
|
2017-01-03 09:30:34 +01:00
|
|
|
if (*led != (CRGB) 0x000000) {
|
|
|
|
*led = color;
|
|
|
|
}
|
2017-01-03 09:00:38 +01:00
|
|
|
}
|
|
|
|
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 })];
|
2017-01-03 09:30:34 +01:00
|
|
|
if (*led != (CRGB)0x000000) {
|
|
|
|
*led = color;
|
|
|
|
}
|
2017-01-03 09:00:38 +01:00
|
|
|
}
|
|
|
|
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 })];
|
2017-01-03 09:30:34 +01:00
|
|
|
if (*led != (CRGB) 0x000000) {
|
|
|
|
*led = color;
|
|
|
|
}
|
2017-01-03 09:00:38 +01:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (selection.column != 255 && selection.row != 255) {
|
|
|
|
CRGB* led = &leds[decodeLED(selection)];
|
2017-01-03 09:30:34 +01:00
|
|
|
if (*led != (CRGB) 0x000000) {
|
2017-01-03 09:00:38 +01:00
|
|
|
*led = color;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-16 09:18:45 +01:00
|
|
|
bool mirror(byte side, CRGB* leds) {
|
|
|
|
/*TODO: figure out memory structure,
|
|
|
|
copy the nine leds to the the different memory parts,
|
|
|
|
should probably use some form of modulo
|
|
|
|
*/
|
|
|
|
}
|
2017-01-03 09:00:38 +01:00
|
|
|
|
2017-01-03 09:15:19 +01:00
|
|
|
#endif
|