58 lines
1.5 KiB
C++
58 lines
1.5 KiB
C++
#include <Arduino.h>
|
|
#include "config.h"
|
|
#include "settings.h"
|
|
#include "wifi_connector.h"
|
|
#include "display_manager.h"
|
|
#include "laser_tracker.h"
|
|
#include "mqtt_client.h"
|
|
|
|
void setup() {
|
|
Serial.begin(SERIAL_BAUD_RATE);
|
|
settings.begin();
|
|
LOG_I("MAIN", "LaserCutter Display gestartet");
|
|
LOG_I("MAIN", "Laser GPIO: %d, Display CS: %d", LASER_SIGNAL_PIN, DISPLAY_CS_PIN);
|
|
settings.printToSerial();
|
|
|
|
display.begin();
|
|
display.printToSerial();
|
|
display.showWifiError(false);
|
|
display.showMqttError(false);
|
|
display.showLaserTime(0.0f); // Session startet bei 0
|
|
display.showIdle();
|
|
|
|
laserTracker.begin();
|
|
laserTracker.printToSerial();
|
|
|
|
wifiConnector.begin();
|
|
wifiConnector.printToSerial();
|
|
|
|
mqttClient.begin();
|
|
mqttClient.printToSerial();
|
|
}
|
|
|
|
void loop() {
|
|
laserTracker.loop();
|
|
wifiConnector.loop();
|
|
mqttClient.loop();
|
|
|
|
// MQTT: Session-Publish nur wenn Netto-Zeit vorhanden (kein GRATIS-only)
|
|
if (laserTracker.consumeSessionEnd()) {
|
|
int lastSession = laserTracker.getLastSessionSeconds();
|
|
if (lastSession > 0) {
|
|
mqttClient.publishSession(lastSession, settings.get().gratisSeconds);
|
|
}
|
|
}
|
|
|
|
// Display mit aktuellen Werten aktualisieren
|
|
display.showLaserTime((float)laserTracker.getAllSessionsSumMinutes()); // Module 1-3
|
|
int countdown = laserTracker.getCountdownRemaining();
|
|
if (laserTracker.isActive() && countdown > 0) {
|
|
display.showCountdown(countdown); // Module 5-7: Gratiszeit
|
|
} else {
|
|
display.showIdle(); // Module 5-7: Idle / NET_COUNTING
|
|
}
|
|
|
|
display.update();
|
|
delay(50);
|
|
}
|