From 0cc8bf80982cacebb3b8b5ed73f766410c5c5b9c Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Mon, 24 Jun 2024 15:43:25 +0200 Subject: fix indentation --- puzzle/neo/main.cpp | 160 ++++++++++++++++++++++++++-------------------------- 1 file changed, 80 insertions(+), 80 deletions(-) (limited to 'puzzle') diff --git a/puzzle/neo/main.cpp b/puzzle/neo/main.cpp index fe4c7e5..ece4e9b 100644 --- a/puzzle/neo/main.cpp +++ b/puzzle/neo/main.cpp @@ -11,8 +11,8 @@ #define LED_COLOR_ORANGE 0xFFA500 // Orange color for IDLE state Adafruit_NeoTrellis t_array[MATRIX_SIZE / 4][MATRIX_SIZE / 4] = { - {Adafruit_NeoTrellis(0x2E), Adafruit_NeoTrellis(0x2F)}, - {Adafruit_NeoTrellis(0x30), Adafruit_NeoTrellis(0x32)} + {Adafruit_NeoTrellis(0x2E), Adafruit_NeoTrellis(0x2F)}, + {Adafruit_NeoTrellis(0x30), Adafruit_NeoTrellis(0x32)} }; Adafruit_MultiTrellis trellis((Adafruit_NeoTrellis *)t_array, MATRIX_SIZE / 4, MATRIX_SIZE / 4); @@ -30,54 +30,53 @@ bool ledState = false; pb_global_state_t puzzleState = PB_GS_NOINIT; void toggleAdjacentLEDs(int x, int y) { - for (int dx = -1; dx <= 1; ++dx) { - for (int dy = -1; dy <= 1; ++dy) { - if (dx == 0 && dy == 0) continue; // Skip the center button itself - int nx = x + dx, ny = y + dy; - if (nx >= 0 && nx < MATRIX_SIZE && ny >= 0 && ny < MATRIX_SIZE) { - neoMatrix[nx][ny] = !neoMatrix[nx][ny]; - trellis.setPixelColor(nx * MATRIX_SIZE + ny, neoMatrix[nx][ny] ? LED_COLOR_ON : LED_COLOR_OFF); - } - } - } + for (int dx = -1; dx <= 1; ++dx) { + for (int dy = -1; dy <= 1; ++dy) { + if (dx == 0 && dy == 0) continue; // Skip the center button itself + int nx = x + dx, ny = y + dy; + if (nx >= 0 && nx < MATRIX_SIZE && ny >= 0 && ny < MATRIX_SIZE) { + neoMatrix[nx][ny] = !neoMatrix[nx][ny]; + trellis.setPixelColor(nx * MATRIX_SIZE + ny, neoMatrix[nx][ny] ? LED_COLOR_ON : LED_COLOR_OFF); + } + } + } } bool isNeoPuzzleSolved() { - for (int i = 0; i < MATRIX_SIZE; i++) { - for (int j = 0; j < MATRIX_SIZE; j++) { - if (neoMatrix[i][j]) return false; // If any LED is on, puzzle is not solved - } - } - return true; + for (int i = 0; i < MATRIX_SIZE; i++) { + for (int j = 0; j < MATRIX_SIZE; j++) { + if (neoMatrix[i][j]) return false; // If any LED is on, puzzle is not solved + } + } + return true; } TrellisCallback buttonCallback(keyEvent evt) { - int x = evt.bit.NUM / MATRIX_SIZE; - int y = evt.bit.NUM % MATRIX_SIZE; - - if (evt.bit.EDGE == SEESAW_KEYPAD_EDGE_RISING) { - toggleAdjacentLEDs(x, y); - trellis.show(); - if (isNeoPuzzleSolved()) { - pb_hook_mod_state_write(PB_GS_SOLVED); - Serial.println("The NeoTrellis puzzle is solved!"); - } - } - return 0; -} + int x = evt.bit.NUM / MATRIX_SIZE; + int y = evt.bit.NUM % MATRIX_SIZE; + if (evt.bit.EDGE == SEESAW_KEYPAD_EDGE_RISING) { + toggleAdjacentLEDs(x, y); + trellis.show(); + if (isNeoPuzzleSolved()) { + pb_hook_mod_state_write(PB_GS_SOLVED); + Serial.println("The NeoTrellis puzzle is solved!"); + } + } + return 0; +} void setup() { - Serial.begin(115200); - while (!Serial); // Wait for Serial to be read - if (!trellis.begin()) { - Serial.println("Failed to initialize NeoTrellis"); + Serial.begin(115200); + while (!Serial); // Wait for Serial to be read + if (!trellis.begin()) { + Serial.println("Failed to initialize NeoTrellis"); pb_hook_mod_state_write(PB_GS_NOINIT); - } + } } -void set_game_field(){ +void set_game_field() { if (gamefield == false){ // Initialize the matrix with a checkerboard pattern bool toggle = false; @@ -96,7 +95,7 @@ void set_game_field(){ trellis.activateKey(i, SEESAW_KEYPAD_EDGE_RISING, true); trellis.activateKey(i, SEESAW_KEYPAD_EDGE_FALLING, true); trellis.registerCallback(i, buttonCallback); - } + } gamefield = true; } } @@ -110,49 +109,50 @@ void pb_hook_mod_state_write(pb_global_state_t state) { } void flashCorners(uint32_t color) { - unsigned long currentMillis = millis(); - - if (currentMillis - previousMillis >= interval) { - previousMillis = currentMillis; - ledState = !ledState; - - for (int i = 0; i < MATRIX_SIZE / 4; i++) { - for (int j = 0; j < MATRIX_SIZE / 4; j++) { - int baseIndex = (i * 4 * MATRIX_SIZE) + (j * 4); - if (ledState) { - trellis.setPixelColor(baseIndex, color); // Top-left corner - trellis.setPixelColor(baseIndex + 3, color); // Top-right corner - trellis.setPixelColor(baseIndex + 3 * MATRIX_SIZE, color); // Bottom-left corner - trellis.setPixelColor(baseIndex + 3 * MATRIX_SIZE + 3, color); // Bottom-right corner - } else { - trellis.setPixelColor(baseIndex, LED_COLOR_OFF); - trellis.setPixelColor(baseIndex + 3, LED_COLOR_OFF); - trellis.setPixelColor(baseIndex + 3 * MATRIX_SIZE, LED_COLOR_OFF); - trellis.setPixelColor(baseIndex + 3 * MATRIX_SIZE + 3, LED_COLOR_OFF); - } - } - } - trellis.show(); - } + unsigned long currentMillis = millis(); + + if (currentMillis - previousMillis >= interval) { + previousMillis = currentMillis; + ledState = !ledState; + + for (int i = 0; i < MATRIX_SIZE / 4; i++) { + for (int j = 0; j < MATRIX_SIZE / 4; j++) { + int baseIndex = (i * 4 * MATRIX_SIZE) + (j * 4); + if (ledState) { + trellis.setPixelColor(baseIndex, color); // Top-left corner + trellis.setPixelColor(baseIndex + 3, color); // Top-right corner + trellis.setPixelColor(baseIndex + 3 * MATRIX_SIZE, color); // Bottom-left corner + trellis.setPixelColor(baseIndex + 3 * MATRIX_SIZE + 3, color); // Bottom-right corner + } else { + trellis.setPixelColor(baseIndex, LED_COLOR_OFF); + trellis.setPixelColor(baseIndex + 3, LED_COLOR_OFF); + trellis.setPixelColor(baseIndex + 3 * MATRIX_SIZE, LED_COLOR_OFF); + trellis.setPixelColor(baseIndex + 3 * MATRIX_SIZE + 3, LED_COLOR_OFF); + } + } + } + trellis.show(); + } } void loop() { - switch(puzzleState) { - case PB_GS_PLAYING: - set_game_field(); - trellis.read(); // Process button events - delay(20); - break; - case PB_GS_SOLVED: - Serial.println("STATE = PB_GS_SOLVED"); - break; - case PB_GS_NOINIT: - Serial.println("STATE = PB_GS_NOINIT"); - flashCorners(LED_COLOR_RED); - break; - case PB_GS_IDLE: - Serial.println("STATE = PB_GS_IDLE"); - flashCorners(LED_COLOR_ORANGE); - break; + switch(puzzleState) { + case PB_GS_PLAYING: + set_game_field(); + trellis.read(); // Process button events + delay(20); + break; + case PB_GS_SOLVED: + Serial.println("STATE = PB_GS_SOLVED"); + break; + case PB_GS_NOINIT: + Serial.println("STATE = PB_GS_NOINIT"); + flashCorners(LED_COLOR_RED); + break; + case PB_GS_IDLE: + Serial.println("STATE = PB_GS_IDLE"); + flashCorners(LED_COLOR_ORANGE); + break; + } } -} \ No newline at end of file + -- cgit v1.2.3