116 lines
3.9 KiB
C++
116 lines
3.9 KiB
C++
/**
|
|
* TEST SKETCH 5.6 - LaserTracker Verifikation
|
|
*
|
|
* Simuliert das Laser-Signal durch Druecken des Push-Buttons (GPIO 4, LOW_ACTIVE).
|
|
* Button gedrueckt gehalten = Laser aktiv.
|
|
*
|
|
* Testet:
|
|
* 1. Gratiszeit: Countdown laeuft, Netto-Zeit = 0 waehrend Gratiszeit
|
|
* 2. Netto-Zeit: steigt an sobald Gratiszeit abgelaufen
|
|
* 3. Session-Ende: NVS-Speicherung (Gesamtzeit += Netto)
|
|
* 4. Naechste Session startet mit neuem Basis-Wert
|
|
* 5. BOOT-Taste (GPIO 0, 3s): Gesamtzeit zuruecksetzen
|
|
*
|
|
* Display-Ausgabe:
|
|
* Modul 0 : leer (kein WiFi-Fehler)
|
|
* Module 1-3 : Session-Minuten (ganzzahlig, reset bei Neustart)
|
|
* Modul 4 : leer (kein MQTT-Fehler)
|
|
* Module 5-7 : Countdown (Gratiszeit) oder ' --' (Idle / NET_COUNTING)
|
|
*
|
|
* Flash: pio run -e test-laser-tracker --target upload
|
|
* Monitor: pio device monitor -e test-laser-tracker
|
|
*/
|
|
|
|
#include <Arduino.h>
|
|
#include "settings.h"
|
|
#include "display_manager.h"
|
|
#include "laser_tracker.h"
|
|
|
|
// BOOT-Taste fuer Reset-Test
|
|
#define BOOT_PIN 0
|
|
#define RESET_HOLD_MS 3000
|
|
|
|
static uint32_t bootPressedAt = 0;
|
|
static bool bootWasLow = false;
|
|
|
|
// ---------------------------------------------------------------------------
|
|
void setup() {
|
|
Serial.begin(115200);
|
|
delay(500);
|
|
|
|
Serial.println("\n========================================");
|
|
Serial.println(" TEST 5.6 - LaserTracker");
|
|
Serial.println("========================================");
|
|
|
|
settings.begin();
|
|
settings.saveGratisSeconds(DEFAULT_GRATIS_SECONDS); // NVS-Korrektur: setzt 20s
|
|
settings.printToSerial();
|
|
|
|
display.begin();
|
|
display.showWifiError(false);
|
|
display.showMqttError(false);
|
|
display.showLaserTime(0.0f); // Session startet bei 0
|
|
display.showIdle();
|
|
|
|
laserTracker.begin();
|
|
laserTracker.printToSerial();
|
|
|
|
// BOOT-Taste
|
|
pinMode(BOOT_PIN, INPUT_PULLUP);
|
|
|
|
Serial.println("\n[BEREIT] Button (GPIO 4) druecken = Laser aktiv");
|
|
Serial.println("[RESET] BOOT-Taste (GPIO 0) 3s halten = Gesamtzeit loeschen");
|
|
Serial.println("----------------------------------------------------");
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
void loop() {
|
|
laserTracker.loop();
|
|
|
|
// ---- Display aktualisieren --------------------------------------------
|
|
int sessionMin = laserTracker.getSessionMinutes();
|
|
int countdown = laserTracker.getCountdownRemaining();
|
|
bool active = laserTracker.isActive();
|
|
|
|
// Module 1-3: Session-Minuten (ganzzahlig)
|
|
display.showLaserTime((float)sessionMin);
|
|
|
|
// Module 5-7: Countdown waehrend Gratiszeit, sonst Idle
|
|
if (active && countdown > 0) {
|
|
display.showCountdown(countdown);
|
|
} else {
|
|
display.showIdle();
|
|
}
|
|
|
|
// ---- Serielle Status-Ausgabe alle 500 ms ------------------------------
|
|
static uint32_t lastPrint = 0;
|
|
if (millis() - lastPrint >= 500) {
|
|
lastPrint = millis();
|
|
if (active) {
|
|
Serial.printf("[LIVE] aktiv | sessionMin=%d | countdown=%ds\n",
|
|
sessionMin, countdown);
|
|
}
|
|
}
|
|
|
|
// ---- BOOT-Taste: Gesamtzeit zuruecksetzen (3s halten) -----------------
|
|
if (digitalRead(BOOT_PIN) == LOW) {
|
|
if (!bootWasLow) {
|
|
bootWasLow = true;
|
|
bootPressedAt = millis();
|
|
Serial.println("[BTN] BOOT gedrueckt - 3s halten fuer Reset...");
|
|
} else if ((millis() - bootPressedAt) >= RESET_HOLD_MS) {
|
|
Serial.println("[RESET] Alle Einstellungen + Gesamtzeit werden zurueckgesetzt!");
|
|
settings.reset(); // NVS komplett auf Defaults (inkl. gratisSeconds=20)
|
|
laserTracker.resetTotal();
|
|
display.showLaserTime(0.0f);
|
|
display.showIdle();
|
|
bootWasLow = false;
|
|
delay(500); // Entprellen nach Reset
|
|
}
|
|
} else {
|
|
if (bootWasLow) {
|
|
Serial.println("[BTN] BOOT losgelassen (kein Reset).");
|
|
}
|
|
bootWasLow = false;
|
|
}
|
|
} |