struct-rain #2

Merged
panki merged 8 commits from struct-rain into master 2024-12-08 15:16:40 +01:00
8 changed files with 191 additions and 175 deletions
Showing only changes of commit 64346ba9b6 - Show all commits

View File

@ -13,6 +13,7 @@ platform = espressif32
board = adafruit_matrixportal_esp32s3 board = adafruit_matrixportal_esp32s3
framework = arduino framework = arduino
monitor_speed = 115200 monitor_speed = 115200
build_flags = -Ilib -Isrc
lib_deps = lib_deps =
adafruit/Adafruit GFX Library adafruit/Adafruit GFX Library

47
nametag/src/congress.cpp Normal file
View File

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

4
nametag/src/congress.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_congress(MatrixPanel_I2S_DMA *matrix, enum Mode mode);

29
nametag/src/constants.h Normal file
View File

@ -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

13
nametag/src/enums.h Normal file
View File

@ -0,0 +1,13 @@
#ifndef INCLUDED_ENUMS
#define INCLUDED_ENUMS
enum Mode {
Stealth,
LowVis,
HighVis
};
enum DisplayStyle {
Rain,
Congress
};
#endif

View File

@ -3,86 +3,23 @@
#include <ESP32-HUB75-MatrixPanel-I2S-DMA.h> #include <ESP32-HUB75-MatrixPanel-I2S-DMA.h>
#include "main.h" #include "main.h"
#include "constants.h"
#include "congress.h"
#include "rain.h"
#include "caveatbrush9pt7b.h"
#include "pillowlava8pt7b.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; 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; Mode mode = HighVis;
DisplayStyle style = Congress; DisplayStyle style = Congress;
void setup(){ void setup(){
Serial.begin(BAUD_RATE);
pinMode(ONBOARD_LED, OUTPUT); pinMode(ONBOARD_LED, OUTPUT);
pinMode(BACK_BUTTON, INPUT_PULLUP); pinMode(BACK_BUTTON, INPUT_PULLUP);
pinMode(NEXT_BUTTON, INPUT_PULLUP); pinMode(NEXT_BUTTON, INPUT_PULLUP);
for (int i = 0; i<PANEL_WIDTH; i++) { // redefine pins in constants.h if required
raindrops[i].y = 0 - random(24);
raindrops[i].length = random(20, 28);
raindrops[i].speed = random(25, 100);
raindrops[i].last_moved = millis();
//raindrops[i].reached_bottom = false;
}
// redefine pins if required
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);
@ -99,115 +36,9 @@ void setup(){
matrix->begin(); matrix->begin();
matrix->setBrightness8(64); matrix->setBrightness8(64);
matrix->fillScreenRGB888(0, 0, 0); matrix->fillScreenRGB888(0, 0, 0);
//matrix->setFont(&CaveatBrush_Regular9pt7b);
matrix->setFont(&Pilowlava_Regular8pt7b); 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() { void loop() {
matrix ->flipDMABuffer(); matrix ->flipDMABuffer();
matrix->clearScreen(); matrix->clearScreen();
@ -242,10 +73,10 @@ void loop() {
switch(style) { switch(style) {
case Rain: case Rain:
draw_rain(); draw_rain(matrix, mode);
break; break;
case Congress: case Congress:
draw_congress(); draw_congress(matrix, mode);
break; break;
} }
} }

87
nametag/src/rain.cpp Normal file
View File

@ -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; i<PANEL_WIDTH; i++) {
raindrops[i].y = 0 - random(24);
raindrops[i].length = random(20, 28);
raindrops[i].speed = random(25, 100);
raindrops[i].last_moved = millis();
}
}
void draw_rain(MatrixPanel_I2S_DMA *matrix, Mode mode) {
//matrix ->drawBitmap(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;
}
}
}
}
}
}

4
nametag/src/rain.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_rain(MatrixPanel_I2S_DMA *matrix, enum Mode mode);