From 0411db7976c7cf42c73bddf022dec7ecbf4d5cd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20L=C3=B8vbr=C3=B8tte=20Olsen?= Date: Tue, 20 Jun 2017 23:28:46 +0200 Subject: [PATCH] Update borg.h --- School/vg2/borg/borg.h | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/School/vg2/borg/borg.h b/School/vg2/borg/borg.h index a257dc3..087e69e 100644 --- a/School/vg2/borg/borg.h +++ b/School/vg2/borg/borg.h @@ -33,9 +33,9 @@ byte ROTTODIR[6][6]; // Initializing mapping for directions void initMap(void); // 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 -inline int decodeLED(LEDSelect selection); +inline byte decodeLED(LEDSelect selection); // Compares two LEDSelects, returns true if equal, false if unequal 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 void rotate(byte side, bool dir, byte n, CRGB* leds); // 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 void printError(CRGB color, CRGB* leds); @@ -133,32 +133,32 @@ void initMap(void) ROTTODIR[4][RIGHT] = 255; ROTTODIR[4][DOWN] = NORTH; ROTTODIR[4][LEFT] = 255; - ROTTODIR[4][CLOCKW] = EAST; - ROTTODIR[4][ACLOCKW] = WEST; + ROTTODIR[4][CLOCKW] = WEST; + ROTTODIR[4][ACLOCKW] = EAST; ROTTODIR[5][UP] = SOUTH; ROTTODIR[5][RIGHT] = 255; ROTTODIR[5][DOWN] = NORTH; ROTTODIR[5][LEFT] = 255; - ROTTODIR[5][CLOCKW] = WEST; - ROTTODIR[5][ACLOCKW] = EAST; + ROTTODIR[5][CLOCKW] = EAST; + ROTTODIR[5][ACLOCKW] = WEST; } -void encodeLED(int n, LEDSelect* Result) +void encodeLED(byte n, LEDSelect* Result) { Result->side = n / 9; Result->column = 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; } 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) @@ -448,6 +448,9 @@ void translate(LEDSelect src, LEDSelect dst, CRGB* leds){ 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) { 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) { + LEDSelect head[2] = {selection, selection}; for (byte i = 0; i < n; i++) { - LEDSelect head[2] = {selection, selection}; CRGB saved = leds[decodeLED(head[0])]; do { + head[1] = head[0]; getRotNeighborLED(&head[1], (dir > 3) ? 4 + !(dir - 4) : (dir + 2) % 4, &head[0]); leds[decodeLED(head[1])] = leds[decodeLED(head[0])]; } while (!LEDSelectCmp(head[0], selection)); leds[decodeLED(head[1])] = saved; + } } -bool mirror(byte side, CRGB* leds) +void 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) { + for (byte i = 0; i < 54; i += 9) { memcpy(&leds[i], &leds[decodeLED({side, 0, 0})], sizeof(CRGB) * 9); } }