From def486e7a7596ab4ddc0c8efbbe6a4960cca001a Mon Sep 17 00:00:00 2001 From: Felix Pankratz Date: Fri, 27 Dec 2024 16:58:55 +0100 Subject: [PATCH] flamezz --- nametag/src/enums.h | 4 +- nametag/src/flame.cpp | 85 +++++++++++++++++++++++++++++++++++++++++++ nametag/src/flame.h | 4 ++ nametag/src/main.cpp | 20 +++++++++- 4 files changed, 110 insertions(+), 3 deletions(-) create mode 100644 nametag/src/flame.cpp create mode 100644 nametag/src/flame.h diff --git a/nametag/src/enums.h b/nametag/src/enums.h index fb5eeba..61a856e 100644 --- a/nametag/src/enums.h +++ b/nametag/src/enums.h @@ -11,6 +11,8 @@ enum DisplayStyle { Congress, Supercomputer, Cyber, - Plasma + Plasma, + Flame, + NumStyles }; #endif diff --git a/nametag/src/flame.cpp b/nametag/src/flame.cpp new file mode 100644 index 0000000..07476f4 --- /dev/null +++ b/nametag/src/flame.cpp @@ -0,0 +1,85 @@ +#include "constants.h" +#include "flame.h" + +#define FLAME_PALETTE_SIZE 36 + +uint16_t flame_palette[] = { + 0x0020, + 0x1820, + 0x2860, + 0x4060, + 0x50A0, + 0x60E0, + 0x70E0, + 0x8920, + 0x9960, + 0xA9E0, + 0xBA20, + 0xC220, + 0xDA60, + 0xDAA0, + 0xDAA0, + 0xD2E0, + 0xD321, + 0xCB61, + 0xCBA1, + 0xCBE1, + 0xCC23, + 0xC422, + 0xC462, + 0xC4A3, + 0xBCE3, + 0xBCE3, + 0xBD24, + 0xBD24, + 0xBD65, + 0xB565, + 0xB5A5, + 0xB5A6, + 0xCE6D, + 0xDEF3, + 0xEF78, + 0xFFFF +}; + +int framebuffer[PANEL_WIDTH * PANEL_HEIGHT]; +bool flame_ready = false; + +void spread_fire(int from) { + int rand = random(1, 4); + int to = from - PANEL_WIDTH - rand + 1; + if (to < 0) { + to = 0; + } + framebuffer[to] = framebuffer[from] - rand; + if (framebuffer[to] < 0) + framebuffer[to] = 0; +} + +void do_fire() { + for(int x = 0 ; x < PANEL_WIDTH; x++) { + for (int y = 1; y < PANEL_HEIGHT ; y++) { + spread_fire(y * PANEL_WIDTH + x); + } + } +} + + +void setup_flame() { + memset(framebuffer, 0, sizeof framebuffer); + for (int i = 0; i < PANEL_WIDTH; i++) { + framebuffer[(PANEL_WIDTH * PANEL_HEIGHT - i - 1)] = FLAME_PALETTE_SIZE - 1; + } +} + +void draw_flame(MatrixPanel_I2S_DMA *matrix, enum Mode mode) { + if(not flame_ready) { + setup_flame(); + flame_ready = true; + } + do_fire(); + for(int p = 0; p < PANEL_HEIGHT * PANEL_WIDTH; p++) { + matrix->drawPixel(p % PANEL_WIDTH, p / PANEL_WIDTH, flame_palette[framebuffer[p]]); + } + +} diff --git a/nametag/src/flame.h b/nametag/src/flame.h new file mode 100644 index 0000000..aa9d8b1 --- /dev/null +++ b/nametag/src/flame.h @@ -0,0 +1,4 @@ +#include "xtensa/core-macros.h" +#include +#include "enums.h" +void draw_flame(MatrixPanel_I2S_DMA *matrix, enum Mode mode); diff --git a/nametag/src/main.cpp b/nametag/src/main.cpp index d9e5354..5eae744 100644 --- a/nametag/src/main.cpp +++ b/nametag/src/main.cpp @@ -8,13 +8,18 @@ #include "rain.h" #include "supercomputer.h" #include "cyber.h" +#include "flame.h" #include "pillowlava8pt7b.h" +#define CYCLE_TIME_MS 20000 + MatrixPanel_I2S_DMA *matrix = nullptr; Mode mode = HighVis; -DisplayStyle style = Rain; +DisplayStyle style = Flame; + +unsigned long last_switch; void setup(){ pinMode(ONBOARD_LED, OUTPUT); @@ -25,6 +30,8 @@ void setup(){ HUB75_I2S_CFG::i2s_pins _pins={R1, G1, BL1, R2, G2, BL2, CH_A, CH_B, CH_C, CH_D, CH_E, LAT, OE, CLK}; HUB75_I2S_CFG mxconfig(PANEL_WIDTH, PANEL_HEIGHT, PANELS_NUMBER, _pins); + last_switch = millis(); + mxconfig.gpio.e = PIN_E; mxconfig.driver = HUB75_I2S_CFG::FM6126A; // for panels using FM6126A chips @@ -47,6 +54,12 @@ void loop() { matrix->clearScreen(); delay(25); + if (millis() - last_switch > CYCLE_TIME_MS) { + // next style + style = DisplayStyle((style + 1) % (NumStyles - 1)); + last_switch = millis(); + } + if(!digitalRead(BACK_BUTTON)) { switch(mode) { case Stealth: @@ -66,7 +79,6 @@ void loop() { switch(style) { case Rain: style = Congress; - matrix->setFont(&Pilowlava_Regular8pt7b); break; case Congress: style = Supercomputer; @@ -86,6 +98,7 @@ void loop() { draw_rain(matrix, mode); break; case Congress: + matrix->setFont(&Pilowlava_Regular8pt7b); draw_congress(matrix, mode); break; case Supercomputer: @@ -94,6 +107,9 @@ void loop() { case Cyber: draw_cyber(matrix, mode); break; + case Flame: + draw_flame(matrix, mode); + break; } }