Formatting all c files
This commit is contained in:
129
src/master.cpp
129
src/master.cpp
@@ -1,28 +1,30 @@
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "master.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
// Aquacross Timer - ESP32 Master (Webserver + ESP-NOW + Anlernmodus)
|
||||
#include <ESPAsyncWebServer.h>
|
||||
#include <SPIFFS.h>
|
||||
#include <esp_now.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include <AsyncTCP.h>
|
||||
#include <ESPAsyncWebServer.h>
|
||||
#include <Preferences.h>
|
||||
#include <PrettyOTA.h>
|
||||
#include <SPIFFS.h>
|
||||
#include <esp_now.h>
|
||||
#include <esp_wifi.h>
|
||||
#include <AsyncTCP.h>
|
||||
|
||||
#include <timesync.h>
|
||||
#include <licenceing.h>
|
||||
#include <debug.h>
|
||||
#include <wificlass.h>
|
||||
#include <webserverrouter.h>
|
||||
|
||||
#include <communication.h>
|
||||
#include <databasebackend.h>
|
||||
#include <debug.h>
|
||||
#include <licenceing.h>
|
||||
#include <rfid.h>
|
||||
#include <timesync.h>
|
||||
#include <webserverrouter.h>
|
||||
#include <wificlass.h>
|
||||
|
||||
const char* firmwareversion = "1.0.0"; // Version der Firmware
|
||||
|
||||
const char *firmwareversion = "1.0.0"; // Version der Firmware
|
||||
|
||||
void handleStart1(uint64_t timestamp = 0) {
|
||||
if (!timerData.isRunning1 && timerData.isReady1) {
|
||||
@@ -46,7 +48,8 @@ void handleStop1(uint64_t timestamp = 0) {
|
||||
timerData.bestTime1 = currentTime;
|
||||
saveBestTimes();
|
||||
}
|
||||
Serial.println("Bahn 1 gestoppt - Zeit: " + String(currentTime/1000.0) + "s");
|
||||
Serial.println("Bahn 1 gestoppt - Zeit: " + String(currentTime / 1000.0) +
|
||||
"s");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,66 +75,70 @@ void handleStop2(uint64_t timestamp = 0) {
|
||||
timerData.bestTime2 = currentTime;
|
||||
saveBestTimes();
|
||||
}
|
||||
Serial.println("Bahn 2 gestoppt - Zeit: " + String(currentTime/1000.0) + "s");
|
||||
Serial.println("Bahn 2 gestoppt - Zeit: " + String(currentTime / 1000.0) +
|
||||
"s");
|
||||
}
|
||||
}
|
||||
|
||||
void checkAutoReset() {
|
||||
unsigned long currentTime = millis();
|
||||
|
||||
if (timerData.isRunning1 && (currentTime - timerData.localStartTime1 > maxTimeBeforeReset)) {
|
||||
|
||||
if (timerData.isRunning1 &&
|
||||
(currentTime - timerData.localStartTime1 > maxTimeBeforeReset)) {
|
||||
timerData.isRunning1 = false;
|
||||
timerData.startTime1 = 0;
|
||||
Serial.println("Bahn 1 automatisch zurückgesetzt");
|
||||
}
|
||||
|
||||
if (timerData.isRunning2 && (currentTime - timerData.localStartTime2 > maxTimeBeforeReset)) {
|
||||
|
||||
if (timerData.isRunning2 &&
|
||||
(currentTime - timerData.localStartTime2 > maxTimeBeforeReset)) {
|
||||
timerData.isRunning2 = false;
|
||||
timerData.startTime2 = 0;
|
||||
Serial.println("Bahn 2 automatisch zurückgesetzt");
|
||||
}
|
||||
|
||||
// Automatischer Reset nach 10 Sekunden "Beendet"
|
||||
if (!timerData.isRunning1 && timerData.endTime1 > 0 && timerData.finishedSince1 > 0) {
|
||||
if (!timerData.isRunning1 && timerData.endTime1 > 0 &&
|
||||
timerData.finishedSince1 > 0) {
|
||||
if (millis() - timerData.finishedSince1 > maxTimeDisplay) {
|
||||
timerData.startTime1 = 0;
|
||||
timerData.endTime1 = 0;
|
||||
timerData.finishedSince1 = 0;
|
||||
timerData.isReady1 = true; // Zurücksetzen auf "Bereit"
|
||||
|
||||
JsonDocument messageDoc;
|
||||
messageDoc["firstname"] ="";
|
||||
messageDoc["lastname"] = "";
|
||||
messageDoc["lane"] = "start1"; // Add lane information
|
||||
|
||||
String message;
|
||||
serializeJson(messageDoc, message);
|
||||
JsonDocument messageDoc;
|
||||
messageDoc["firstname"] = "";
|
||||
messageDoc["lastname"] = "";
|
||||
messageDoc["lane"] = "start1"; // Add lane information
|
||||
|
||||
// Push the message to the frontend
|
||||
pushUpdateToFrontend(message);
|
||||
String message;
|
||||
serializeJson(messageDoc, message);
|
||||
|
||||
// Push the message to the frontend
|
||||
pushUpdateToFrontend(message);
|
||||
|
||||
Serial.println("Bahn 1 automatisch auf 'Bereit' zurückgesetzt");
|
||||
}
|
||||
}
|
||||
|
||||
if (!timerData.isRunning2 && timerData.endTime2 > 0 && timerData.finishedSince2 > 0) {
|
||||
if (!timerData.isRunning2 && timerData.endTime2 > 0 &&
|
||||
timerData.finishedSince2 > 0) {
|
||||
if (currentTime - timerData.finishedSince2 > maxTimeDisplay) {
|
||||
timerData.startTime2 = 0;
|
||||
timerData.endTime2 = 0;
|
||||
timerData.finishedSince2 = 0;
|
||||
timerData.isReady2 = true; // Zurücksetzen auf "Bereit"
|
||||
|
||||
JsonDocument messageDoc;
|
||||
messageDoc["firstname"] = "";
|
||||
messageDoc["lastname"] = "";
|
||||
messageDoc["lane"] = "start2"; // Add lane information
|
||||
|
||||
String message;
|
||||
serializeJson(messageDoc, message);
|
||||
JsonDocument messageDoc;
|
||||
messageDoc["firstname"] = "";
|
||||
messageDoc["lastname"] = "";
|
||||
messageDoc["lane"] = "start2"; // Add lane information
|
||||
|
||||
// Push the message to the frontend
|
||||
pushUpdateToFrontend(message);
|
||||
String message;
|
||||
serializeJson(messageDoc, message);
|
||||
|
||||
// Push the message to the frontend
|
||||
pushUpdateToFrontend(message);
|
||||
|
||||
Serial.println("Bahn 2 automatisch auf 'Bereit' zurückgesetzt");
|
||||
}
|
||||
@@ -186,14 +193,14 @@ void saveWifiSettings() {
|
||||
preferences.putString("ssid", ssidSTA);
|
||||
preferences.putString("password", passwordSTA);
|
||||
preferences.end();
|
||||
delay(500); // Warte 2 Sekunden, bevor der Neustart erfolgt
|
||||
delay(500); // Warte 2 Sekunden, bevor der Neustart erfolgt
|
||||
ESP.restart(); // Neustart des ESP32
|
||||
}
|
||||
|
||||
void loadLocationSettings() {
|
||||
preferences.begin("location", true);
|
||||
masterlocation = preferences.getString("location", "");
|
||||
preferences.end();
|
||||
preferences.begin("location", true);
|
||||
masterlocation = preferences.getString("location", "");
|
||||
preferences.end();
|
||||
}
|
||||
|
||||
void saveLocationSettings() {
|
||||
@@ -203,18 +210,14 @@ void saveLocationSettings() {
|
||||
}
|
||||
|
||||
void loadWifiSettings() {
|
||||
preferences.begin("wifi", true);
|
||||
String ssid = preferences.getString("ssid", "");
|
||||
String password = preferences.getString("password", "");
|
||||
ssidSTA = strdup(ssid.c_str());
|
||||
passwordSTA = strdup(password.c_str());
|
||||
preferences.end();
|
||||
preferences.begin("wifi", true);
|
||||
String ssid = preferences.getString("ssid", "");
|
||||
String password = preferences.getString("password", "");
|
||||
ssidSTA = strdup(ssid.c_str());
|
||||
passwordSTA = strdup(password.c_str());
|
||||
preferences.end();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int checkLicence() {
|
||||
loadLicenceFromPrefs();
|
||||
String id = getUniqueDeviceID();
|
||||
@@ -224,7 +227,7 @@ int checkLicence() {
|
||||
|
||||
String getTimerDataJSON() {
|
||||
DynamicJsonDocument doc(1024);
|
||||
|
||||
|
||||
unsigned long currentTime = millis();
|
||||
// Bahn 1
|
||||
if (timerData.isRunning1) {
|
||||
@@ -237,7 +240,7 @@ String getTimerDataJSON() {
|
||||
doc["time1"] = 0;
|
||||
doc["status1"] = "ready";
|
||||
}
|
||||
|
||||
|
||||
// Bahn 2
|
||||
if (timerData.isRunning2) {
|
||||
doc["time2"] = (currentTime - timerData.localStartTime2) / 1000.0;
|
||||
@@ -249,40 +252,38 @@ String getTimerDataJSON() {
|
||||
doc["time2"] = 0;
|
||||
doc["status2"] = "ready";
|
||||
}
|
||||
|
||||
|
||||
// Beste Zeiten
|
||||
doc["best1"] = timerData.bestTime1 / 1000.0;
|
||||
doc["best2"] = timerData.bestTime2 / 1000.0;
|
||||
|
||||
|
||||
// Lernmodus
|
||||
doc["learningMode"] = learningMode;
|
||||
if (learningMode) {
|
||||
String buttons[] = {"Start Bahn 1", "Stop Bahn 1", "Start Bahn 2", "Stop Bahn 2"};
|
||||
String buttons[] = {"Start Bahn 1", "Stop Bahn 1", "Start Bahn 2",
|
||||
"Stop Bahn 2"};
|
||||
doc["learningButton"] = buttons[learningStep];
|
||||
}
|
||||
|
||||
|
||||
String result;
|
||||
serializeJson(doc, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
|
||||
if (!SPIFFS.begin(true)) {
|
||||
Serial.println("SPIFFS Mount Failed");
|
||||
return;
|
||||
}
|
||||
|
||||
//setup API libararies
|
||||
|
||||
// setup API libararies
|
||||
setupTimeAPI(server);
|
||||
setupLicenceAPI(server);
|
||||
setupDebugAPI(server);
|
||||
setupBackendRoutes(server);
|
||||
setupRFIDRoute(server);
|
||||
|
||||
|
||||
// Gespeicherte Daten laden
|
||||
loadButtonConfig();
|
||||
@@ -293,14 +294,12 @@ void setup() {
|
||||
|
||||
setupWifi(); // WiFi initialisieren
|
||||
setupOTA(&server);
|
||||
|
||||
|
||||
setupRoutes();
|
||||
setupWebSocket();
|
||||
setupLED();
|
||||
setupMqttServer(); // MQTT Server initialisieren
|
||||
setupRFID();
|
||||
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
Reference in New Issue
Block a user