From f6b5a47975941002659bc808946f806bdcad125d Mon Sep 17 00:00:00 2001 From: SteveT Date: Mon, 28 Sep 2020 19:07:27 -0400 Subject: [PATCH] add support for FireBox_Mk1, reduce heartbeat, separate eStop time --- DCC.h | 2 ++ WiThrottle.cpp | 27 ++++++++++++++------------- WiThrottle.h | 5 +++-- defines.h | 2 +- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/DCC.h b/DCC.h index 0e8fcc6..580d8b7 100644 --- a/DCC.h +++ b/DCC.h @@ -156,6 +156,8 @@ private: #define ARDUINO_TYPE "MEGA" #elif defined(ARDUINO_ARCH_MEGAAVR) #define ARDUINO_TYPE "UNOWIFIR2" +#elif defined(ARDUINO_SAMD_ZERO) + #define ARDUINO_TYPE "FireBoxMK1" #else #error CANNOT COMPILE - DCC++ EX ONLY WORKS WITH AN ARDUINO UNO, NANO 328, OR ARDUINO MEGA 1280/2560 #endif diff --git a/WiThrottle.cpp b/WiThrottle.cpp index f9c5a41..044b00b 100644 --- a/WiThrottle.cpp +++ b/WiThrottle.cpp @@ -46,6 +46,8 @@ #include "StringFormatter.h" #include "Turnouts.h" #include "DIAG.h" +#include "GITHUB_SHA.h" +#include "version.h" #define LOOPLOCOS(THROTTLECHAR, CAB) for (int loco=0;loco\n"), myLocos[loco].throttle, LorS(myLocos[loco].cab), myLocos[loco].cab); } } - if (Diag::WITHROTTLE) DIAG(F("WiThrottle(%d) Quit\n"), clientid); + if (Diag::WITHROTTLE) DIAG(F("%l WiThrottle(%d) Quit\n"),millis(),clientid); delete this; break; } @@ -343,19 +346,17 @@ void WiThrottle::loop() { } void WiThrottle::checkHeartbeat() { - // if 2 heartbeats missed... drop connection and eStop any locos still assigned to this client - if(heartBeatEnable && (millis()-heartBeat > HEARTBEAT_TIMEOUT*2000)) { - if (Diag::WITHROTTLE) DIAG(F("\n\nWiThrottle(%d) hearbeat missed, dropping connection\n\n"),clientid); + // if eStop time passed... eStop any locos still assigned to this client and then drop the connection + if(heartBeatEnable && (millis()-heartBeat > ESTOP_SECONDS*1000)) { + if (Diag::WITHROTTLE) DIAG(F("\n\n%l WiThrottle(%d) eStop(%ds) timeout, drop connection\n"), millis(), clientid, ESTOP_SECONDS); LOOPLOCOS('*', -1) { if (myLocos[loco].throttle!='\0') { - if (Diag::WITHROTTLE) DIAG(F(" eStopping cab %d\n"), myLocos[loco].cab); + if (Diag::WITHROTTLE) DIAG(F("%l eStopping cab %d\n"),millis(),myLocos[loco].cab); DCC::setThrottle(myLocos[loco].cab, 1, DCC::getThrottleDirection(myLocos[loco].cab)); // speed 1 is eStop } } delete this; - } else { - // TODO Check if anything has changed on my locos since last notified! - } + } } char WiThrottle::LorS(int cab) { diff --git a/WiThrottle.h b/WiThrottle.h index ad29ee5..c1b5bba 100644 --- a/WiThrottle.h +++ b/WiThrottle.h @@ -35,8 +35,9 @@ class WiThrottle { WiThrottle( int wifiClientId); ~WiThrottle(); - static const int MAX_MY_LOCO=10; //maximum number of locos assigned to a single client - static const int HEARTBEAT_TIMEOUT=2;// heartbeat at 2secs to provide messaging transport + static const int MAX_MY_LOCO=10; // maximum number of locos assigned to a single client + static const int HEARTBEAT_SECONDS=4; // heartbeat at 4secs to provide messaging transport + static const int ESTOP_SECONDS=8; // eStop if no incoming messages for more than 8secs static WiThrottle* firstThrottle; static int getInt(byte * cmd); static int getLocoId(byte * cmd); diff --git a/defines.h b/defines.h index 700687b..99b49bd 100644 --- a/defines.h +++ b/defines.h @@ -22,7 +22,7 @@ // // WIFI_ON: All prereqs for running with WIFI are met // -#if ENABLE_WIFI && (defined(ARDUINO_AVR_MEGA) || defined(ARDUINO_AVR_MEGA2560)) +#if ENABLE_WIFI && (defined(ARDUINO_AVR_MEGA) || defined(ARDUINO_AVR_MEGA2560) || defined(ARDUINO_SAMD_ZERO)) #define WIFI_ON #endif