1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-22 15:46:14 +01:00

looptimer test 1

This commit is contained in:
Harald Barth 2024-08-07 21:13:44 +02:00
parent 27dc8059d7
commit 7e29011d63

View File

@ -141,44 +141,73 @@ void setup()
CommandDistributor::broadcastPower();
}
void looptimer(unsigned long timeout, const FSH* message)
{
static unsigned long lasttimestamp = 0;
unsigned long now = micros();
if (timeout != 0) {
unsigned long diff = now - lasttimestamp;
if (diff > timeout) {
DIAG(message);
DIAG(F("DeltaT=%L"), diff);
lasttimestamp = micros();
return;
}
}
lasttimestamp = now;
}
void loop()
{
// The main sketch has responsibilities during loop()
// Responsibility 1: Handle DCC background processes
// (loco reminders and power checks)
looptimer(0, F(""));
DCC::loop();
looptimer(5000, F("DCC")); // got warnings up to 3884 during prog track read
// Responsibility 2: handle any incoming commands on USB connection
SerialManager::loop();
looptimer(2000, F("Serial")); // got warnings up to 1900 during start
// Responsibility 3: Optionally handle any incoming WiFi traffic
#ifndef ARDUINO_ARCH_ESP32
#if WIFI_ON
WifiInterface::loop();
looptimer(9000, F("Wifi")); // got warnings up to 8000
#endif //WIFI_ON
#else //ARDUINO_ARCH_ESP32
#ifndef WIFI_TASK_ON_CORE0
WifiESP::loop();
looptimer(1000, F("WifiESP"));
#endif
#endif //ARDUINO_ARCH_ESP32
#if ETHERNET_ON
EthernetInterface::loop();
looptimer(10000, F("Ethernet"));
#endif
RMFT::loop(); // ignored if no automation
looptimer(1000, F("RMFT"));
#if defined(LCN_SERIAL)
LCN::loop();
looptimer(1000, F("LCN"));
#endif
// Display refresh
DisplayInterface::loop();
looptimer(2000, F("Display")); // got warnings around 1150
// Handle/update IO devices.
IODevice::loop();
looptimer(1000, F("IODevice"));
Sensor::checkAll(); // Update and print changes
looptimer(1000, F("Sensor"));
// Report any decrease in memory (will automatically trigger on first call)
static int ramLowWatermark = __INT_MAX__; // replaced on first loop