split config now

This commit is contained in:
Priec
2025-11-14 10:13:59 +01:00
parent 1f5bc11ddd
commit 3e0018d1cb
9 changed files with 155 additions and 119 deletions

View File

@@ -0,0 +1,35 @@
// src/render/background.cpp
#include "../background_dark_inverted.h"
#include <cstdio>
#include <cstring>
void draw_mask(const char *unused_filename, int shift, const char *text) {
const int view_width = 50;
const int view_height = 19;
// Terminal clear + home
printf("\033[2J\033[H");
for (int i = 0; i < view_height && i < BACKGROUND_DARK_INVERTED_LINES; i++) {
const char *row = BACKGROUND_DARK_INVERTED[i];
int width = strlen(row);
if (width == 0) {
printf("\r\n");
continue;
}
int start = shift % width;
for (int j = 0; j < view_width; j++) {
printf("%c", row[(start + j) % width]);
}
printf("\r\n");
}
if (text && text[0] != '\0') {
printf("\r\n[RX] %s\r\n", text);
}
fflush(stdout);
}

View File

@@ -0,0 +1,6 @@
// src/render/background.h
#pragma once
// Draws the ASCII art background with optional message
void draw_mask(const char *unused_filename, int shift, const char *text = nullptr);

View File

@@ -0,0 +1,67 @@
// src/render/loop.c
#include "loop.h"
#include "mbed.h"
#include "../background_dark_inverted.h"
extern BufferedSerial serial_port;
extern DigitalOut led;
#define BUFFER_SIZE 64
static char rx_buffer[BUFFER_SIZE];
static char message[BUFFER_SIZE];
static bool message_active = false;
void draw_mask(const char *unused_filename, int shift, const char *text = nullptr);
void render_loop() {
Timer msg_timer;
Timer anim_timer;
msg_timer.start();
anim_timer.start();
int shift = 0;
const char *bg_file = "background_dark_inverted.txt";
bool need_redraw = false;
while (true) {
// Read from UART if available
if (serial_port.readable()) {
memset(rx_buffer, 0, sizeof(rx_buffer));
ssize_t num = serial_port.read(rx_buffer, sizeof(rx_buffer) - 1);
if (num > 0) {
led = !led;
strncpy(message, rx_buffer, sizeof(message) - 1);
message_active = true;
msg_timer.reset();
need_redraw = true;
}
}
// Message lifetime
if (message_active && msg_timer.elapsed_time() > 1s) {
message_active = false;
memset(message, 0, sizeof(message));
need_redraw = true;
}
// Animation tick
if (anim_timer.elapsed_time() >= 80ms) {
shift++;
anim_timer.reset();
need_redraw = true;
}
// Draw
if (need_redraw) {
draw_mask(bg_file, shift, message_active ? message : nullptr);
need_redraw = false;
ThisThread::sleep_for(60ms);
}
ThisThread::sleep_for(20ms);
}
}

View File

@@ -0,0 +1,6 @@
// src/render/loop.h
#pragma once
// Runs the render loop: reads UART, animates, and draws output
void render_loop();