prevent time variable overflow

This commit is contained in:
2020-12-09 19:53:59 +01:00
parent 1547854edf
commit ee91b36c66
5 changed files with 48 additions and 16 deletions

View File

@@ -5,6 +5,7 @@
#include "Pins.h"
#include "GeneralInfoService.h"
#include "SettingsService.h"
#include "Timer.h"
bool allow;
bool error = false;
@@ -18,7 +19,7 @@ Ticker pumpendauer;
//WifiManager mang;
Heating mHeat;
unsigned long turnontime = 0;
uint32_t turnontime = 0;
AsyncWebServer server(80);
ESP8266React esp8266React(&server);
@@ -31,7 +32,7 @@ void pumpeSchalten(bool on) {
if (on) {
Serial.println("versuche Pumpe EIN zuschalten");
// refresh last pump counter
generalinfo.setlastPumpTime(millis());
generalinfo.setlastPumpTime(Timer::getSystemSeconds());
} else {
Serial.println("versuche Pumpe AUS zuschalten");
}
@@ -40,7 +41,7 @@ void pumpeSchalten(bool on) {
if (on) {
pumpendauer.once((float)settingsservice.getSettings()->maxpumpduration + 1, []() {
//erlaube keine einschaltung von mehr als 60 sek
if (millis() - turnontime >= (unsigned)settingsservice.getSettings()->maxpumpduration * 1000 && turnontime != 0) {
if (Timer::getSystemSeconds() - turnontime >= (unsigned)settingsservice.getSettings()->maxpumpduration && turnontime != 0) {
//error zu lange
Serial.println("\n\npumpe lief mehr als 10 Minuten durchgaengig");
pumpeSchalten(false);
@@ -48,11 +49,11 @@ void pumpeSchalten(bool on) {
}
});
} else {
generalinfo.setPumpDuration(millis() - turnontime);
generalinfo.setPumpDuration(Timer::getSystemSeconds() - turnontime);
}
// save pump start time
turnontime = millis();
turnontime = Timer::getSystemSeconds();
digitalWrite(SchuetzPin, on);
Serial.println("[Erfolg] pumpe wird geschalten");
@@ -90,7 +91,7 @@ void WasserSensorCheck() {
//kein Wasser dh timer auf 10min stellen
// refresh wateroutage counter
generalinfo.setlastWaterOutage(millis());
generalinfo.setlastWaterOutage(Timer::getSystemSeconds());
allow = false;
Serial.println("Schalte pumpe aus");