MQTT-Display-LaserCutter/test_sketches/test_display_manager.cpp
MaPaLo76 4349b37f05 feat(display): implement DisplayManager with raw MD_MAX72XX
- Add include/display_manager.h: DisplayManager class declaration
  - Two-zone layout: Zone 0 (top, laser time), Zone 1 (bottom, countdown/status)
  - showLaserTime(), showCountdown(), showIdle(), showStatus(), setBrightness()
  - rotateCCW() bitmap transformation for 90 deg physical module rotation
  - charBitmap() for 17-character set (0-9, space, dash, dot, special chars)

- Add src/display_manager.cpp: full implementation
  - Double-init pattern for SPI power stability
  - showLaserTime() format: <10 -> ' x.x', <100 -> 'xx.x', <1000 -> ' xxx', else 'xxxx'
  - showCountdown() right-aligned 4-char format
  - All methods use writeZone() -> writeChar() -> rotateCCW() -> MD_MAX72XX

- Add test_sketches/test_display_manager.cpp: 6-step verification test
  - allLedsOn/Off, showLaserTime (12 boundary values), showCountdown 5->0
  - showIdle, showStatus (Err/AP/WiFi/oF), live simulation loop

- Update platformio.ini: add test-display-mgr environment
- Update src/main.cpp: integrate display.begin/showIdle/update
- Update Implementation-Plan.md: mark Phase 4 tasks 4.1-4.3 complete

Tested on hardware: all 6 test steps passed
2026-02-22 14:00:54 +01:00

132 lines
4.5 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* TEST SKETCH 4.3 DisplayManager Verifikation
*
* Testet alle Methoden des DisplayManagers:
* 1. Alle LEDs EIN/AUS (Modul-Check)
* 2. showLaserTime() mit verschiedenen Werten (Grenzwerttest)
* 3. showCountdown() hochzählend
* 4. showIdle()
* 5. showStatus() mit "Err", "AP", "WiFi"
* 6. Realistischer Loop: laufende Laserzeit + Countdown simuliert
*
* Flash: pio run -e test-display-mgr --target upload
* Monitor: pio device monitor -e test-display-mgr
*/
#include <Arduino.h>
#include "display_manager.h"
// Pause zwischen Testschritten
#define STEP_MS 2000
static void step(const char* desc) {
Serial.printf("[STEP] %s\n", desc);
delay(STEP_MS);
}
// ---------------------------------------------------------------------------
void setup() {
Serial.begin(115200);
delay(500);
Serial.println("\n========================================");
Serial.println(" TEST 4.3 DisplayManager");
Serial.println("========================================");
display.begin();
display.printToSerial();
// ------------------------------------------------------------------
// 1. Alle LEDs EIN → alle 8 Module müssen leuchten
// ------------------------------------------------------------------
Serial.println("\n[1] Alle LEDs EIN (2s) alle 8 Module pruefen");
display.allLedsOn();
delay(2000);
display.allLedsOff();
delay(500);
// ------------------------------------------------------------------
// 2. showLaserTime() Grenzwerttests
// ------------------------------------------------------------------
Serial.println("\n[2] showLaserTime() Grenzwerte:");
float testTimes[] = { 0.0f, 0.5f, 1.0f, 9.9f, 10.0f, 42.5f, 99.9f,
100.0f, 123.0f, 999.0f, 1000.0f, 9999.0f };
for (float t : testTimes) {
Serial.printf(" %.1f min → oben\n", t);
display.showLaserTime(t);
delay(1500);
}
display.clear();
delay(500);
// ------------------------------------------------------------------
// 3. showCountdown() von 120 → 0 (jede Sekunde)
// ------------------------------------------------------------------
Serial.println("\n[3] showCountdown() 5..0:");
for (int s = 5; s >= 0; s--) {
Serial.printf(" %d s\n", s);
display.showCountdown(s);
delay(1000);
}
delay(500);
// ------------------------------------------------------------------
// 4. showIdle()
// ------------------------------------------------------------------
Serial.println("\n[4] showIdle() (2s)");
display.showIdle();
step("Erwarte ' --' auf unterer Reihe");
// ------------------------------------------------------------------
// 5. showStatus() mit verschiedenen Strings
// ------------------------------------------------------------------
Serial.println("\n[5] showStatus() Tests:");
const char* statMsgs[] = { "Err ", "AP ", "WiFi", " oF" };
for (const char* m : statMsgs) {
Serial.printf(" '%s'\n", m);
display.showStatus(m);
delay(STEP_MS);
}
display.clear();
delay(500);
// ------------------------------------------------------------------
// 6. Realistischer Betrieb: Laserzeit wächst, Countdown läuft
// ------------------------------------------------------------------
Serial.println("\n[6] Realistischer Betrieb (30s): Laserzeit + Countdown");
Serial.println(" Erwarte: oben steigt, unten zaehlt runter, dann '--'");
}
// ---------------------------------------------------------------------------
void loop() {
static float totalMin = 42.3f;
static int countdown = 20;
static bool counting = true;
static uint32_t lastSec = 0;
static uint32_t lastTenth = 0;
uint32_t now = millis();
// Jede 100ms: Laserzeit um ~0.001 min erhöhen (0.06 min/min = 1x Normal)
if (now - lastTenth >= 100) {
lastTenth = now;
totalMin += 0.001f;
display.showLaserTime(totalMin);
}
// Jede Sekunde: Countdown herunterzählen
if (now - lastSec >= 1000) {
lastSec = now;
if (counting && countdown > 0) {
display.showCountdown(countdown);
countdown--;
} else if (counting && countdown == 0) {
counting = false;
display.showIdle();
Serial.println("[LIVE] Countdown abgelaufen → Idle");
}
Serial.printf("[LIVE] %.2f min, countdown=%d\n", totalMin, countdown);
}
}