From 1b802cc6005ef72e757fef1298a82beb4ec6262c Mon Sep 17 00:00:00 2001 From: mstevetodd Date: Tue, 29 Sep 2020 11:51:01 -0400 Subject: [PATCH 1/2] add support for FireBox_Mk1, reduce heartbeat, separate eStop time (#43) --- 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 From 6feda4e217b81784e76f09bd756cf6358ca42a8d Mon Sep 17 00:00:00 2001 From: Asbelos Date: Fri, 2 Oct 2020 17:12:48 +0100 Subject: [PATCH 2/2] startup Info on USB (#44) Add status info to CS startup and ash Git SHA for version tracking --- DCC.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/DCC.cpp b/DCC.cpp index 29fa9d7..0c8c322 100644 --- a/DCC.cpp +++ b/DCC.cpp @@ -20,6 +20,8 @@ #include "DCC.h" #include "DCCWaveform.h" #include "DIAG.h" +#include "GITHUB_SHA.h" +#include "version.h" // This module is responsible for converting API calls into @@ -45,6 +47,7 @@ __FlashStringHelper* DCC::shieldName=NULL; void DCC::begin(const __FlashStringHelper* motorShieldName, MotorDriver * mainDriver, MotorDriver* progDriver, byte timerNumber) { shieldName=(__FlashStringHelper*)motorShieldName; + DIAG(F("\n"), F(VERSION), F(ARDUINO_TYPE), shieldName, F(GITHUB_SHA)); DCCWaveform::begin(mainDriver,progDriver, timerNumber); }