From 64346ba9b6861c65b31769c1ca8277b13cd5cb57 Mon Sep 17 00:00:00 2001 From: Felix Pankratz Date: Sun, 8 Dec 2024 15:11:55 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20refactor=20things=20into=20their?= =?UTF-8?q?=20own=20files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nametag/platformio.ini | 1 + nametag/src/congress.cpp | 47 ++++++++++ nametag/src/congress.h | 4 + nametag/src/constants.h | 29 +++++++ nametag/src/enums.h | 13 +++ nametag/src/main.cpp | 181 ++------------------------------------- nametag/src/rain.cpp | 87 +++++++++++++++++++ nametag/src/rain.h | 4 + 8 files changed, 191 insertions(+), 175 deletions(-) create mode 100644 nametag/src/congress.cpp create mode 100644 nametag/src/congress.h create mode 100644 nametag/src/constants.h create mode 100644 nametag/src/enums.h create mode 100644 nametag/src/rain.cpp create mode 100644 nametag/src/rain.h diff --git a/nametag/platformio.ini b/nametag/platformio.ini index 0e62411..aada770 100644 --- a/nametag/platformio.ini +++ b/nametag/platformio.ini @@ -13,6 +13,7 @@ platform = espressif32 board = adafruit_matrixportal_esp32s3 framework = arduino monitor_speed = 115200 +build_flags = -Ilib -Isrc lib_deps = adafruit/Adafruit GFX Library diff --git a/nametag/src/congress.cpp b/nametag/src/congress.cpp new file mode 100644 index 0000000..f0ac71d --- /dev/null +++ b/nametag/src/congress.cpp @@ -0,0 +1,47 @@ +#include "constants.h" +#include "congress.h" + +int running_text_pos = 21; + +void draw_congress(MatrixPanel_I2S_DMA *matrix, enum Mode mode) { + uint16_t grid_color = matrix->color565(25, 11, 47); + matrix->fillScreenRGB888(15, 0, 10); + + matrix->drawFastHLine(0, 0, PANEL_WIDTH, grid_color); + matrix->drawFastHLine(0, 7, PANEL_WIDTH, grid_color); + matrix->drawFastHLine(0, 24, PANEL_WIDTH, grid_color); + matrix->drawFastHLine(0, 31, PANEL_WIDTH, grid_color); + + matrix->drawFastVLine(0, 0, PANEL_HEIGHT, grid_color); + matrix->drawFastVLine(63, 0, PANEL_HEIGHT, grid_color); + int v_lines = PANEL_WIDTH / 7; + for(int v; v < v_lines; v++) { + matrix->drawFastVLine(v * 7, 0, 7, grid_color); + matrix->drawFastVLine(v * 7, 24, 7, grid_color); + } + matrix->setTextWrap(false); + matrix->setTextColor(matrix->color565(255, 80, 83)); + + if (mode == Stealth) { + matrix->setCursor(7, 21); + matrix->print("38C3"); + } else if (mode == LowVis) { + matrix->setCursor(2, 21); + matrix->print("Panki"); + } else if (mode == HighVis) { + matrix->setCursor(running_text_pos, 21); + String message = "38C3 - Panki - DECT - 3389 - 38C3"; + matrix->print(message); + if ((running_text_pos == 7) or (running_text_pos == - 70) or (running_text_pos == -146 ) or (running_text_pos == -216) ) { + delay(2000); + } + running_text_pos -= 1; + + if (running_text_pos < - 286 ) { // (0 - (13 * message.length()))) { + running_text_pos = 7; + }; + matrix->drawFastVLine(0, 0, PANEL_HEIGHT, grid_color); + matrix->drawFastVLine(63, 0, PANEL_HEIGHT, grid_color); + delay(10); + } +} diff --git a/nametag/src/congress.h b/nametag/src/congress.h new file mode 100644 index 0000000..a179aaa --- /dev/null +++ b/nametag/src/congress.h @@ -0,0 +1,4 @@ +#include "xtensa/core-macros.h" +#include +#include "enums.h" +void draw_congress(MatrixPanel_I2S_DMA *matrix, enum Mode mode); diff --git a/nametag/src/constants.h b/nametag/src/constants.h new file mode 100644 index 0000000..0f1a12f --- /dev/null +++ b/nametag/src/constants.h @@ -0,0 +1,29 @@ +#define R1 42 +#define G1 40 +#define BL1 41 +#define R2 38 +#define G2 37 +#define BL2 39 +#define CH_A 45 +#define CH_B 36 +#define CH_C 48 +#define CH_D 35 +#define CH_E 21 +#define CLK 2 +#define LAT 47 +#define OE 14 + +#define PIN_E 21 +#define PANEL_WIDTH 64 +#define PANEL_HEIGHT 32 // Panel height of 64 will required PIN_E to be defined. + +#define PANELS_NUMBER 1 + +#define PANE_WIDTH PANEL_WIDTH * PANELS_NUMBER +#define PANE_HEIGHT PANEL_HEIGHT +#define NUM_LEDS PANE_WIDTH*PANE_HEIGHT + +#define ONBOARD_LED 13 +#define BACK_BUTTON 6 +#define NEXT_BUTTON 7 + diff --git a/nametag/src/enums.h b/nametag/src/enums.h new file mode 100644 index 0000000..34928b6 --- /dev/null +++ b/nametag/src/enums.h @@ -0,0 +1,13 @@ +#ifndef INCLUDED_ENUMS +#define INCLUDED_ENUMS +enum Mode { + Stealth, + LowVis, + HighVis +}; + +enum DisplayStyle { + Rain, + Congress +}; +#endif diff --git a/nametag/src/main.cpp b/nametag/src/main.cpp index a660d5e..aab3099 100644 --- a/nametag/src/main.cpp +++ b/nametag/src/main.cpp @@ -3,86 +3,23 @@ #include #include "main.h" +#include "constants.h" +#include "congress.h" +#include "rain.h" -#include "caveatbrush9pt7b.h" #include "pillowlava8pt7b.h" -#include "overlay.h" - -#define R1 42 -#define G1 40 -#define BL1 41 -#define R2 38 -#define G2 37 -#define BL2 39 -#define CH_A 45 -#define CH_B 36 -#define CH_C 48 -#define CH_D 35 -#define CH_E 21 -#define CLK 2 -#define LAT 47 -#define OE 14 - -#define PIN_E 21 -#define PANEL_WIDTH 64 -#define PANEL_HEIGHT 32 // Panel height of 64 will required PIN_E to be defined. - -#define PANELS_NUMBER 1 - -#define PANE_WIDTH PANEL_WIDTH * PANELS_NUMBER -#define PANE_HEIGHT PANEL_HEIGHT -#define NUM_LEDS PANE_WIDTH*PANE_HEIGHT - -#define ONBOARD_LED 13 -#define BACK_BUTTON 6 -#define NEXT_BUTTON 7 - MatrixPanel_I2S_DMA *matrix = nullptr; -int line_pos[PANEL_WIDTH]; // where a rain marker is (y coordinate) -int line_length[PANEL_WIDTH]; // how long a line is for a given x coord -int line_speed[PANEL_WIDTH]; // how fast each line moves -unsigned long line_last_moved[PANEL_WIDTH]; - -typedef struct { - bool reached_bottom = false; - int y; - int length; - int speed; - unsigned long last_moved; -} Raindrop; - -Raindrop raindrops[PANEL_WIDTH]; - -enum Mode { - Stealth, - LowVis, - HighVis -}; - -enum DisplayStyle { - Rain, - Congress -}; - Mode mode = HighVis; DisplayStyle style = Congress; void setup(){ - Serial.begin(BAUD_RATE); pinMode(ONBOARD_LED, OUTPUT); pinMode(BACK_BUTTON, INPUT_PULLUP); pinMode(NEXT_BUTTON, INPUT_PULLUP); - for (int i = 0; ibegin(); matrix->setBrightness8(64); matrix->fillScreenRGB888(0, 0, 0); - //matrix->setFont(&CaveatBrush_Regular9pt7b); matrix->setFont(&Pilowlava_Regular8pt7b); } -void draw_rain() { - //matrix ->drawBitmap(0, 0, overlay, 64, 32, matrix->color565(64, 0, 0)); - unsigned long timestamp = millis(); - for (int x = 0; x < PANEL_WIDTH; x++) { - if ((timestamp - raindrops[x].last_moved) > raindrops[x].speed) { - // step down a pixel - raindrops[x].y++; - raindrops[x].last_moved = timestamp; - } - if (raindrops[x].y > PANEL_HEIGHT) { - raindrops[x].y = 0; - raindrops[x].reached_bottom = true; - } - if (raindrops[x].y >= 0) { - //draw our pixel - matrix->drawPixel(x, raindrops[x].y, matrix->color565(128, 255, 128)); - // draw our trail - for (int trail_offset = 1; trail_offset < raindrops[x].length; trail_offset++) { - int trail_y = raindrops[x].y - trail_offset; - if (trail_y >= 0) { - int pixel_num = (trail_y * PANEL_WIDTH) + x; - if (overlay[ pixel_num / 8 ] & (1 << (7 - (pixel_num % 8)) ) and mode != Stealth) { - if (mode == HighVis) { - matrix->drawPixel(x, trail_y, matrix->color565(128, 255, 128)); - } else { - matrix->drawPixel(x, trail_y, matrix->color565( - (128 / raindrops[x].length) * (raindrops[x].length - trail_offset), - (255 / raindrops[x].length) * (raindrops[x].length - trail_offset), - (128 / raindrops[x].length) * (raindrops[x].length - trail_offset)) - ); - } - } else { - matrix->drawPixel(x, trail_y, matrix->color565(0, (255 / raindrops[x].length) * (raindrops[x].length - trail_offset), 0)); - } - } else if (raindrops[x].reached_bottom) { - int pixel_num = ((PANEL_HEIGHT + trail_y) * PANEL_WIDTH) + x; - if (line_pos[x] >= 0) { - - if (overlay[ pixel_num / 8 ] & (1 << (7 - (pixel_num % 8)) ) and mode != Stealth) { - if (mode == HighVis) { - matrix->drawPixel(x, PANEL_HEIGHT + trail_y, matrix->color565(128, 255, 128)); - } else { - matrix->drawPixel(x, PANEL_HEIGHT + trail_y, matrix->color565( - (128 / raindrops[x].length) * (raindrops[x].length - trail_offset), - (255 / raindrops[x].length) * (raindrops[x].length - trail_offset), - (128 / raindrops[x].length) * (raindrops[x].length - trail_offset)) - ); - } - } else { - matrix->drawPixel(x, PANEL_HEIGHT + trail_y, matrix->color565(0,(255 / raindrops[x].length) * (raindrops[x].length - trail_offset), 0)); - } - } else { - break; - } - } - } - } - } -} - -int running_text_pos = 21; - -void draw_congress() { - matrix->fillScreenRGB888(15, 0, 10); - uint16_t grid_color = matrix->color565(25, 11, 47); - - matrix->drawFastHLine(0, 0, PANEL_WIDTH, grid_color); - matrix->drawFastHLine(0, 7, PANEL_WIDTH, grid_color); - matrix->drawFastHLine(0, 24, PANEL_WIDTH, grid_color); - matrix->drawFastHLine(0, 31, PANEL_WIDTH, grid_color); - - matrix->drawFastVLine(0, 0, PANEL_HEIGHT, grid_color); - matrix->drawFastVLine(63, 0, PANEL_HEIGHT, grid_color); - int v_lines = PANEL_WIDTH / 7; - for(int v; v < v_lines; v++) { - matrix->drawFastVLine(v * 7, 0, 7, grid_color); - matrix->drawFastVLine(v * 7, 24, 7, grid_color); - } - matrix->setTextWrap(false); - matrix->setTextColor(matrix->color565(255, 80, 83)); - - if (mode == Stealth) { - matrix->setCursor(7, 21); - matrix->print("38C3"); - } else if (mode == LowVis) { - matrix->setCursor(2, 21); - matrix->print("Panki"); - } else if (mode == HighVis) { - matrix->setCursor(running_text_pos, 21); - String message = "38C3 - Panki - DECT - 3389 - 38C3"; - matrix->print(message); - if ((running_text_pos == 7) or (running_text_pos == - 70) or (running_text_pos == -146 ) or (running_text_pos == -216) ) { - delay(2000); - } - running_text_pos -= 1; - - if (running_text_pos < - 286 ) { // (0 - (13 * message.length()))) { - running_text_pos = 7; - }; - matrix->drawFastVLine(0, 0, PANEL_HEIGHT, grid_color); - matrix->drawFastVLine(63, 0, PANEL_HEIGHT, grid_color); - delay(10); - } -} - void loop() { matrix ->flipDMABuffer(); matrix->clearScreen(); @@ -242,10 +73,10 @@ void loop() { switch(style) { case Rain: - draw_rain(); + draw_rain(matrix, mode); break; case Congress: - draw_congress(); + draw_congress(matrix, mode); break; } } diff --git a/nametag/src/rain.cpp b/nametag/src/rain.cpp new file mode 100644 index 0000000..21348d5 --- /dev/null +++ b/nametag/src/rain.cpp @@ -0,0 +1,87 @@ +#include "rain.h" +#include "constants.h" +#include "overlay.h" + +typedef struct { + bool reached_bottom = false; + int y; + int length; + int speed; + unsigned long last_moved; +} Raindrop; + +Raindrop raindrops[PANEL_WIDTH]; +bool rain_initialized = false; + +void setup_rain() { + for (int i = 0; idrawBitmap(0, 0, overlay, 64, 32, matrix->color565(64, 0, 0)); + if (!rain_initialized) { + setup_rain(); + rain_initialized = true; + } + unsigned long timestamp = millis(); + for (int x = 0; x < PANEL_WIDTH; x++) { + if ((timestamp - raindrops[x].last_moved) > raindrops[x].speed) { + // step down a pixel + raindrops[x].y++; + raindrops[x].last_moved = timestamp; + } + if (raindrops[x].y > PANEL_HEIGHT) { + raindrops[x].y = 0; + raindrops[x].reached_bottom = true; + } + if (raindrops[x].y >= 0) { + //draw our pixel + matrix->drawPixel(x, raindrops[x].y, matrix->color565(128, 255, 128)); + // draw our trail + for (int trail_offset = 1; trail_offset < raindrops[x].length; trail_offset++) { + int trail_y = raindrops[x].y - trail_offset; + if (trail_y >= 0) { + int pixel_num = (trail_y * PANEL_WIDTH) + x; + if (overlay[ pixel_num / 8 ] & (1 << (7 - (pixel_num % 8)) ) and mode != Stealth) { + if (mode == HighVis) { + matrix->drawPixel(x, trail_y, matrix->color565(128, 255, 128)); + } else { + matrix->drawPixel(x, trail_y, matrix->color565( + (128 / raindrops[x].length) * (raindrops[x].length - trail_offset), + (255 / raindrops[x].length) * (raindrops[x].length - trail_offset), + (128 / raindrops[x].length) * (raindrops[x].length - trail_offset)) + ); + } + } else { + matrix->drawPixel(x, trail_y, matrix->color565(0, (255 / raindrops[x].length) * (raindrops[x].length - trail_offset), 0)); + } + } else if (raindrops[x].reached_bottom) { + int pixel_num = ((PANEL_HEIGHT + trail_y) * PANEL_WIDTH) + x; + if (raindrops[x].y >= 0) { + + if (overlay[ pixel_num / 8 ] & (1 << (7 - (pixel_num % 8)) ) and mode != Stealth) { + if (mode == HighVis) { + matrix->drawPixel(x, PANEL_HEIGHT + trail_y, matrix->color565(128, 255, 128)); + } else { + matrix->drawPixel(x, PANEL_HEIGHT + trail_y, matrix->color565( + (128 / raindrops[x].length) * (raindrops[x].length - trail_offset), + (255 / raindrops[x].length) * (raindrops[x].length - trail_offset), + (128 / raindrops[x].length) * (raindrops[x].length - trail_offset)) + ); + } + } else { + matrix->drawPixel(x, PANEL_HEIGHT + trail_y, matrix->color565(0,(255 / raindrops[x].length) * (raindrops[x].length - trail_offset), 0)); + } + } else { + break; + } + } + } + } + } +} diff --git a/nametag/src/rain.h b/nametag/src/rain.h new file mode 100644 index 0000000..526f2d1 --- /dev/null +++ b/nametag/src/rain.h @@ -0,0 +1,4 @@ +#include "xtensa/core-macros.h" +#include +#include "enums.h" +void draw_rain(MatrixPanel_I2S_DMA *matrix, enum Mode mode);