This commit is contained in:
Felix Pankratz 2024-12-27 16:58:55 +01:00
parent 34bf5e1c54
commit def486e7a7
4 changed files with 110 additions and 3 deletions

View File

@ -11,6 +11,8 @@ enum DisplayStyle {
Congress, Congress,
Supercomputer, Supercomputer,
Cyber, Cyber,
Plasma Plasma,
Flame,
NumStyles
}; };
#endif #endif

85
nametag/src/flame.cpp Normal file
View File

@ -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]]);
}
}

4
nametag/src/flame.h Normal file
View File

@ -0,0 +1,4 @@
#include "xtensa/core-macros.h"
#include <ESP32-HUB75-MatrixPanel-I2S-DMA.h>
#include "enums.h"
void draw_flame(MatrixPanel_I2S_DMA *matrix, enum Mode mode);

View File

@ -8,13 +8,18 @@
#include "rain.h" #include "rain.h"
#include "supercomputer.h" #include "supercomputer.h"
#include "cyber.h" #include "cyber.h"
#include "flame.h"
#include "pillowlava8pt7b.h" #include "pillowlava8pt7b.h"
#define CYCLE_TIME_MS 20000
MatrixPanel_I2S_DMA *matrix = nullptr; MatrixPanel_I2S_DMA *matrix = nullptr;
Mode mode = HighVis; Mode mode = HighVis;
DisplayStyle style = Rain; DisplayStyle style = Flame;
unsigned long last_switch;
void setup(){ void setup(){
pinMode(ONBOARD_LED, OUTPUT); 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::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); HUB75_I2S_CFG mxconfig(PANEL_WIDTH, PANEL_HEIGHT, PANELS_NUMBER, _pins);
last_switch = millis();
mxconfig.gpio.e = PIN_E; mxconfig.gpio.e = PIN_E;
mxconfig.driver = HUB75_I2S_CFG::FM6126A; // for panels using FM6126A chips mxconfig.driver = HUB75_I2S_CFG::FM6126A; // for panels using FM6126A chips
@ -47,6 +54,12 @@ void loop() {
matrix->clearScreen(); matrix->clearScreen();
delay(25); delay(25);
if (millis() - last_switch > CYCLE_TIME_MS) {
// next style
style = DisplayStyle((style + 1) % (NumStyles - 1));
last_switch = millis();
}
if(!digitalRead(BACK_BUTTON)) { if(!digitalRead(BACK_BUTTON)) {
switch(mode) { switch(mode) {
case Stealth: case Stealth:
@ -66,7 +79,6 @@ void loop() {
switch(style) { switch(style) {
case Rain: case Rain:
style = Congress; style = Congress;
matrix->setFont(&Pilowlava_Regular8pt7b);
break; break;
case Congress: case Congress:
style = Supercomputer; style = Supercomputer;
@ -86,6 +98,7 @@ void loop() {
draw_rain(matrix, mode); draw_rain(matrix, mode);
break; break;
case Congress: case Congress:
matrix->setFont(&Pilowlava_Regular8pt7b);
draw_congress(matrix, mode); draw_congress(matrix, mode);
break; break;
case Supercomputer: case Supercomputer:
@ -94,6 +107,9 @@ void loop() {
case Cyber: case Cyber:
draw_cyber(matrix, mode); draw_cyber(matrix, mode);
break; break;
case Flame:
draw_flame(matrix, mode);
break;
} }
} }