From 55d26d494944c854447fcaf504880ddcb611d760 Mon Sep 17 00:00:00 2001 From: Felix Pankratz Date: Sun, 7 Dec 2025 19:34:15 +0100 Subject: [PATCH] Fahrplan initial commit --- fahrplan/Makefile | 21 ++++++++ fahrplan/platformio.ini | 22 ++++++++ fahrplan/src/config.h | 4 ++ fahrplan/src/constants.h | 26 +++++++++ fahrplan/src/main.cpp | 110 +++++++++++++++++++++++++++++++++++++++ fahrplan/src/main.h | 10 ++++ fahrplan/src/util.cpp | 5 ++ fahrplan/src/util.h | 2 + 8 files changed, 200 insertions(+) create mode 100644 fahrplan/Makefile create mode 100644 fahrplan/platformio.ini create mode 100644 fahrplan/src/config.h create mode 100644 fahrplan/src/constants.h create mode 100644 fahrplan/src/main.cpp create mode 100644 fahrplan/src/main.h create mode 100644 fahrplan/src/util.cpp create mode 100644 fahrplan/src/util.h diff --git a/fahrplan/Makefile b/fahrplan/Makefile new file mode 100644 index 0000000..c5e3ab2 --- /dev/null +++ b/fahrplan/Makefile @@ -0,0 +1,21 @@ +# Uncomment lines below if you have problems with $PATH +#SHELL := /bin/bash +#PATH := /usr/local/bin:$(PATH) + +all: + pio.exe -f -c vim run + +upload: + pio.exe -f -c vim run --target upload + +clean: + pio.exe -f -c vim run --target clean + +program: + pio.exe -f -c vim run --target program + +uploadfs: + pio.exe -f -c vim run --target uploadfs + +update: + pio.exe -f -c vim update diff --git a/fahrplan/platformio.ini b/fahrplan/platformio.ini new file mode 100644 index 0000000..0e62411 --- /dev/null +++ b/fahrplan/platformio.ini @@ -0,0 +1,22 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[env:adafruit_matrixportal_esp32s3] +platform = espressif32 +board = adafruit_matrixportal_esp32s3 +framework = arduino +monitor_speed = 115200 + +lib_deps = + adafruit/Adafruit GFX Library + adafruit/Adafruit BusIO + Wire + fastled/FastLED + https://github.com/mrfaptastic/ESP32-HUB75-MatrixPanel-I2S-DMA.git diff --git a/fahrplan/src/config.h b/fahrplan/src/config.h new file mode 100644 index 0000000..3f3c6c0 --- /dev/null +++ b/fahrplan/src/config.h @@ -0,0 +1,4 @@ +// config.h + +#define WIFI_SSID PankiNet +#define WIFI_PSK foo diff --git a/fahrplan/src/constants.h b/fahrplan/src/constants.h new file mode 100644 index 0000000..0561782 --- /dev/null +++ b/fahrplan/src/constants.h @@ -0,0 +1,26 @@ +#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 diff --git a/fahrplan/src/main.cpp b/fahrplan/src/main.cpp new file mode 100644 index 0000000..1070219 --- /dev/null +++ b/fahrplan/src/main.cpp @@ -0,0 +1,110 @@ +#include +#include "xtensa/core-macros.h" +#include + +#include "main.h" +#include "constants.h" +#include "config.h" +#include "util.h" + +#include +#include + +MatrixPanel_I2S_DMA *matrix = nullptr; + +void setup(){ + Serial.begin(BAUD_RATE); + //while (!Serial) { + // ; // wait for serial port to connect. Needed for native USB + //} + pinMode(ONBOARD_LED, OUTPUT); + + // 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 mxconfig(PANEL_WIDTH, PANEL_HEIGHT, PANELS_NUMBER, _pins); + + mxconfig.gpio.e = PIN_E; + mxconfig.driver = HUB75_I2S_CFG::FM6126A; // for panels using FM6126A chips + + mxconfig.latch_blanking = 4; + mxconfig.i2sspeed = HUB75_I2S_CFG::HZ_10M; + mxconfig.clkphase = false; + + // mxconfig.double_buff = true; + + matrix = new MatrixPanel_I2S_DMA(mxconfig); + matrix->begin(); + matrix->setBrightness8(64); + matrix->fillScreenRGB888(0, 0, 0); +} + +void draw_title(const std::string& title, uint16_t color) { + int y_pos = 0; + int x_pos = 0; + //matrix->setCursor(x_pos, y_pos); + for (size_t idx = 0; idx < title.size(); idx++) { + char current = title[idx]; + if (current != ' ') { + if (current == 'I') { + x_pos -=1; + } + matrix->drawChar(x_pos, y_pos, current, color, matrix->color444(0,0,0), 1); + if (current == 'I') { + x_pos += 5; + } else { + x_pos += 6; // char width + 1px gap + } + } else { + x_pos += 2; // small space + } + + if (x_pos > (63 - 5)) { // new line + if (current != ' ') { + matrix->drawChar(x_pos, y_pos, '-', color, matrix->color444(0,0,0), 1); + } + x_pos = 0; + y_pos = y_pos + 8; //char height + 1px + } + } +} + +void draw_time(const std::string &time) { + int x_pos = 0; + int y_pos = 32 - 8; + + for (size_t idx = 0; idx < time.size(); idx++) { + char current = time[idx]; + int offset = 0; + switch (current) { + case '1': + offset = 1; + break; + } + if (current == ':') { + matrix->drawPixel(x_pos, y_pos + 2, matrix->color444(1,1,1)); + matrix->drawPixel(x_pos, y_pos + 4, matrix->color444(1,1,1)); + x_pos = x_pos + 2; + } else { + x_pos = x_pos - offset; + matrix->drawChar(x_pos, y_pos, current, matrix->color444(1,1,1), matrix->color444(0,0,0), 1); + x_pos = x_pos + (6 - offset); + } + } +} + +void draw_location(const std::string &location) { + int pixel_size = (location.size() * 6) - 1; + matrix->setCursor(63 - pixel_size, 32 - 8); + matrix->print(location.c_str()); +} + +void loop() { + std::string title = "THE ART OF TEXT RENDERING"; + std::string time = "11:00"; + std::string loc = "GRND"; + draw_title(title, matrix->color565(249, 176, 0)); + draw_time(time); + draw_location(loc); + + delay(100); +} diff --git a/fahrplan/src/main.h b/fahrplan/src/main.h new file mode 100644 index 0000000..e4e784a --- /dev/null +++ b/fahrplan/src/main.h @@ -0,0 +1,10 @@ +#include + +#define BAUD_RATE 115200 // serial debug port baud rate + +void buffclear(CRGB *buf); +uint16_t XY16( uint16_t x, uint16_t y); +void mxfill(CRGB *leds); +uint16_t colorWheel(uint8_t pos); +void drawText(int colorWheelOffset); + diff --git a/fahrplan/src/util.cpp b/fahrplan/src/util.cpp new file mode 100644 index 0000000..e445ef5 --- /dev/null +++ b/fahrplan/src/util.cpp @@ -0,0 +1,5 @@ +#include "constants.h" + +bool is_in_bounds(int x, int y) { + return (x < PANEL_WIDTH) and (y < PANEL_HEIGHT) and (x >= 0) and (y >= 0); +} diff --git a/fahrplan/src/util.h b/fahrplan/src/util.h new file mode 100644 index 0000000..3289174 --- /dev/null +++ b/fahrplan/src/util.h @@ -0,0 +1,2 @@ +bool is_in_bounds(int x, int y); +