Update borg.h
This commit is contained in:
parent
75c0d75c8c
commit
0411db7976
@ -33,9 +33,9 @@ byte ROTTODIR[6][6];
|
|||||||
// Initializing mapping for directions
|
// Initializing mapping for directions
|
||||||
void initMap(void);
|
void initMap(void);
|
||||||
// Encodes n led into a LEDSelect
|
// Encodes n led into a LEDSelect
|
||||||
void encodeLED(int n, LEDSelect* Result);
|
void encodeLED(byte n, LEDSelect* Result);
|
||||||
// Decodes side, column, row into n LED
|
// Decodes side, column, row into n LED
|
||||||
inline int decodeLED(LEDSelect selection);
|
inline byte decodeLED(LEDSelect selection);
|
||||||
// Compares two LEDSelects, returns true if equal, false if unequal
|
// Compares two LEDSelects, returns true if equal, false if unequal
|
||||||
inline bool LEDSelectCmp(LEDSelect a, LEDSelect b);
|
inline bool LEDSelectCmp(LEDSelect a, LEDSelect b);
|
||||||
|
|
||||||
@ -61,7 +61,7 @@ void translate(LEDSelect src, LEDSelect dst, CRGB* leds);
|
|||||||
// Rotates a side, in given direction, 0 - Clockwise, 1 - Anticlockwise
|
// Rotates a side, in given direction, 0 - Clockwise, 1 - Anticlockwise
|
||||||
void rotate(byte side, bool dir, byte n, CRGB* leds);
|
void rotate(byte side, bool dir, byte n, CRGB* leds);
|
||||||
// Mirrors one side to every other side
|
// Mirrors one side to every other side
|
||||||
bool mirror(byte side, CRGB* leds);
|
void mirror(byte side, CRGB* leds);
|
||||||
|
|
||||||
//Prints large X in a given color
|
//Prints large X in a given color
|
||||||
void printError(CRGB color, CRGB* leds);
|
void printError(CRGB color, CRGB* leds);
|
||||||
@ -133,32 +133,32 @@ void initMap(void)
|
|||||||
ROTTODIR[4][RIGHT] = 255;
|
ROTTODIR[4][RIGHT] = 255;
|
||||||
ROTTODIR[4][DOWN] = NORTH;
|
ROTTODIR[4][DOWN] = NORTH;
|
||||||
ROTTODIR[4][LEFT] = 255;
|
ROTTODIR[4][LEFT] = 255;
|
||||||
ROTTODIR[4][CLOCKW] = EAST;
|
ROTTODIR[4][CLOCKW] = WEST;
|
||||||
ROTTODIR[4][ACLOCKW] = WEST;
|
ROTTODIR[4][ACLOCKW] = EAST;
|
||||||
|
|
||||||
ROTTODIR[5][UP] = SOUTH;
|
ROTTODIR[5][UP] = SOUTH;
|
||||||
ROTTODIR[5][RIGHT] = 255;
|
ROTTODIR[5][RIGHT] = 255;
|
||||||
ROTTODIR[5][DOWN] = NORTH;
|
ROTTODIR[5][DOWN] = NORTH;
|
||||||
ROTTODIR[5][LEFT] = 255;
|
ROTTODIR[5][LEFT] = 255;
|
||||||
ROTTODIR[5][CLOCKW] = WEST;
|
ROTTODIR[5][CLOCKW] = EAST;
|
||||||
ROTTODIR[5][ACLOCKW] = EAST;
|
ROTTODIR[5][ACLOCKW] = WEST;
|
||||||
}
|
}
|
||||||
|
|
||||||
void encodeLED(int n, LEDSelect* Result)
|
void encodeLED(byte n, LEDSelect* Result)
|
||||||
{
|
{
|
||||||
Result->side = n / 9;
|
Result->side = n / 9;
|
||||||
Result->column = n % 9 / 3;
|
Result->column = n % 9 / 3;
|
||||||
Result->row = n % 9 % 3;
|
Result->row = n % 9 % 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int decodeLED(LEDSelect selection)
|
inline byte decodeLED(LEDSelect selection)
|
||||||
{
|
{
|
||||||
return 9 * selection.side + 3 * selection.row + selection.column;
|
return 9 * selection.side + 3 * selection.row + selection.column;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool LEDSelectCmp(LEDSelect a, LEDSelect b)
|
inline bool LEDSelectCmp(LEDSelect a, LEDSelect b)
|
||||||
{
|
{
|
||||||
return a.side != b.side || a.column !=b.column || a.row != b.row;
|
return a.side == b.side && a.column == b.column && a.row == b.row;
|
||||||
}
|
}
|
||||||
|
|
||||||
void forceMove(LEDSelect* selection, byte direction)
|
void forceMove(LEDSelect* selection, byte direction)
|
||||||
@ -448,6 +448,9 @@ void translate(LEDSelect src, LEDSelect dst, CRGB* leds){
|
|||||||
leds[decodeLED(dst)] = leds[decodeLED(src)];
|
leds[decodeLED(dst)] = leds[decodeLED(src)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// COUNTER CLOCKWISE ROTATION IS BROKEN
|
||||||
|
// DIRTY FIX IS TO JUST ROTATE 3 TIMES INSTEAD OF THIS WEIRD SHIT
|
||||||
void rotate(byte side, bool direction, byte n, CRGB* leds)
|
void rotate(byte side, bool direction, byte n, CRGB* leds)
|
||||||
{
|
{
|
||||||
int firstLED = decodeLED({side, 0, 0});
|
int firstLED = decodeLED({side, 0, 0});
|
||||||
@ -473,25 +476,27 @@ void rotate(byte side, bool direction, byte n, CRGB* leds)
|
|||||||
|
|
||||||
void new_rotaterot(LEDSelect selection, byte dir, byte n, CRGB* leds)
|
void new_rotaterot(LEDSelect selection, byte dir, byte n, CRGB* leds)
|
||||||
{
|
{
|
||||||
|
LEDSelect head[2] = {selection, selection};
|
||||||
for (byte i = 0; i < n; i++) {
|
for (byte i = 0; i < n; i++) {
|
||||||
LEDSelect head[2] = {selection, selection};
|
|
||||||
CRGB saved = leds[decodeLED(head[0])];
|
CRGB saved = leds[decodeLED(head[0])];
|
||||||
do {
|
do {
|
||||||
|
head[1] = head[0];
|
||||||
getRotNeighborLED(&head[1], (dir > 3) ? 4 + !(dir - 4) : (dir + 2) % 4, &head[0]);
|
getRotNeighborLED(&head[1], (dir > 3) ? 4 + !(dir - 4) : (dir + 2) % 4, &head[0]);
|
||||||
leds[decodeLED(head[1])] = leds[decodeLED(head[0])];
|
leds[decodeLED(head[1])] = leds[decodeLED(head[0])];
|
||||||
}
|
}
|
||||||
while (!LEDSelectCmp(head[0], selection));
|
while (!LEDSelectCmp(head[0], selection));
|
||||||
leds[decodeLED(head[1])] = saved;
|
leds[decodeLED(head[1])] = saved;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool mirror(byte side, CRGB* leds)
|
void mirror(byte side, CRGB* leds)
|
||||||
{
|
{
|
||||||
/*TODO: figure out memory structure,
|
/*TODO: figure out memory structure,
|
||||||
copy the nine leds to the the different memory parts, so it the text is displayed on all sides.
|
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
|
should probably use some form of modulo
|
||||||
*/
|
*/
|
||||||
for(int i = 0; i < sizeof(leds) / sizeof(CRGB); i += 9) {
|
for (byte i = 0; i < 54; i += 9) {
|
||||||
memcpy(&leds[i], &leds[decodeLED({side, 0, 0})], sizeof(CRGB) * 9);
|
memcpy(&leds[i], &leds[decodeLED({side, 0, 0})], sizeof(CRGB) * 9);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user