aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-06-27 10:34:45 +0200
committerLoek Le Blansch <loek@pipeframe.xyz>2024-06-27 10:34:50 +0200
commit2f698755fd93fe5f29533ddc11f8a879ccad7970 (patch)
treed9cd9c141a7c095511547f1f62c4447fc7db27be
parentd1e189722cbd49475c16d51d6dd3d7eef307aabf (diff)
`make format`
-rw-r--r--puzzle/neo/main.cpp131
1 files changed, 68 insertions, 63 deletions
diff --git a/puzzle/neo/main.cpp b/puzzle/neo/main.cpp
index 5958ea5..fce0874 100644
--- a/puzzle/neo/main.cpp
+++ b/puzzle/neo/main.cpp
@@ -44,15 +44,15 @@ pb_global_state_t puzzleState = PB_GS_NOINIT;
* @throws None.
*/
uint32_t scaleBrightness(uint32_t color, float scale) {
- uint8_t r = (color >> 16) & 0xFF;
- uint8_t g = (color >> 8) & 0xFF;
- uint8_t b = color & 0xFF;
+ uint8_t r = (color >> 16) & 0xFF;
+ uint8_t g = (color >> 8) & 0xFF;
+ uint8_t b = color & 0xFF;
- r = uint8_t(r * scale);
- g = uint8_t(g * scale);
- b = uint8_t(b * scale);
+ r = uint8_t(r * scale);
+ g = uint8_t(g * scale);
+ b = uint8_t(b * scale);
- return (uint32_t(r) << 16) | (uint32_t(g) << 8) | uint32_t(b);
+ return (uint32_t(r) << 16) | (uint32_t(g) << 8) | uint32_t(b);
}
/**
@@ -64,19 +64,21 @@ uint32_t scaleBrightness(uint32_t color, float scale) {
* @throws None
*/
void toggleAdjacentLEDs(int x, int y) {
- for (int dx = -1; dx <= 1; ++dx) {
- for (int dy = -1; dy <= 1; ++dy) {
- int nx = x + dx, ny = y + dy;
- if (nx >= 0 && nx < MATRIX_SIZE && ny >= 0 && ny < MATRIX_SIZE) {
- neoMatrix[nx][ny] = !neoMatrix[nx][ny]; // Toggle each adjacent LED
- uint32_t color = neoMatrix[nx][ny] ? LED_COLOR_ON : LED_COLOR_OFF;
- trellis.setPixelColor(nx * MATRIX_SIZE + ny, scaleBrightness(color, brightness));
- }
- }
- }
+ for (int dx = -1; dx <= 1; ++dx) {
+ for (int dy = -1; dy <= 1; ++dy) {
+ int nx = x + dx, ny = y + dy;
+ if (nx >= 0 && nx < MATRIX_SIZE && ny >= 0 && ny < MATRIX_SIZE) {
+ neoMatrix[nx][ny]
+ = !neoMatrix[nx][ny]; // Toggle each adjacent LED
+ uint32_t color
+ = neoMatrix[nx][ny] ? LED_COLOR_ON : LED_COLOR_OFF;
+ trellis.setPixelColor(nx * MATRIX_SIZE + ny,
+ scaleBrightness(color, brightness));
+ }
+ }
+ }
}
-
/**
* Checks if the NeoPuzzle is solved.
*
@@ -144,28 +146,28 @@ void setup() {
* @throws None
*/
void set_game_field() {
- if (!gamefield) {
- bool toggle = false;
- for (int i = 0; i < MATRIX_SIZE; i++) {
- for (int j = 0; j < MATRIX_SIZE; j++) {
- neoMatrix[i][j] = toggle;
- uint32_t color = neoMatrix[i][j] ? LED_COLOR_ON : LED_COLOR_OFF;
- trellis.setPixelColor(i * MATRIX_SIZE + j, scaleBrightness(color, brightness));
- toggle = !toggle;
- }
- toggle = !toggle;
- }
- trellis.show();
-
- for (int i = 0; i < MATRIX_SIZE * MATRIX_SIZE; i++) {
- trellis.activateKey(i, SEESAW_KEYPAD_EDGE_RISING, true);
- trellis.activateKey(i, SEESAW_KEYPAD_EDGE_FALLING, true);
- trellis.registerCallback(i, buttonCallback);
- }
- gamefield = true;
- }
-}
+ if (!gamefield) {
+ bool toggle = false;
+ for (int i = 0; i < MATRIX_SIZE; i++) {
+ for (int j = 0; j < MATRIX_SIZE; j++) {
+ neoMatrix[i][j] = toggle;
+ uint32_t color = neoMatrix[i][j] ? LED_COLOR_ON : LED_COLOR_OFF;
+ trellis.setPixelColor(i * MATRIX_SIZE + j,
+ scaleBrightness(color, brightness));
+ toggle = !toggle;
+ }
+ toggle = !toggle;
+ }
+ trellis.show();
+ for (int i = 0; i < MATRIX_SIZE * MATRIX_SIZE; i++) {
+ trellis.activateKey(i, SEESAW_KEYPAD_EDGE_RISING, true);
+ trellis.activateKey(i, SEESAW_KEYPAD_EDGE_FALLING, true);
+ trellis.registerCallback(i, buttonCallback);
+ }
+ gamefield = true;
+ }
+}
pb_global_state_t pb_hook_mod_state_read() { return puzzleState; }
@@ -181,30 +183,33 @@ void pb_hook_mod_state_write(pb_global_state_t state) { puzzleState = state; }
* @throws None
*/
void flashCorners(uint32_t color) {
- unsigned long currentMillis = millis();
- if (currentMillis - previousMillis >= interval) {
- previousMillis = currentMillis;
- ledState = !ledState;
- color = scaleBrightness(color, brightness); // Scale color brightness
-
- 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);
- trellis.setPixelColor(baseIndex + 3, color);
- trellis.setPixelColor(baseIndex + 3 * MATRIX_SIZE, color);
- trellis.setPixelColor(baseIndex + 3 * MATRIX_SIZE + 3, color);
- } 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;
+ color = scaleBrightness(color, brightness); // Scale color brightness
+
+ 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);
+ trellis.setPixelColor(baseIndex + 3, color);
+ trellis.setPixelColor(baseIndex + 3 * MATRIX_SIZE, color);
+ trellis.setPixelColor(baseIndex + 3 * MATRIX_SIZE + 3,
+ color);
+ } 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();
+ }
}
/**