From 7e29011d638ed4ed91ad10a5d59c916d57f1b9fe Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Wed, 7 Aug 2024 21:13:44 +0200 Subject: [PATCH] looptimer test 1 --- CommandStation-EX.ino | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/CommandStation-EX.ino b/CommandStation-EX.ino index 3a0e5ca..31b3b21 100644 --- a/CommandStation-EX.ino +++ b/CommandStation-EX.ino @@ -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