From 68255dcadd4344d3c5ab5e503b78bdd729ce81ce Mon Sep 17 00:00:00 2001 From: mstevetodd Date: Thu, 13 Aug 2020 16:38:22 -0400 Subject: [PATCH] drop any acquired locos on Q(uit), reduce heartbeat to 2s also some indentation fixes note that 2s heartbeat works best with next version of ED. --- WiThrottle.cpp | 39 ++++++++++++++++++++++++--------------- WiThrottle.h | 2 +- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/WiThrottle.cpp b/WiThrottle.cpp index 6d26809..644b4a1 100644 --- a/WiThrottle.cpp +++ b/WiThrottle.cpp @@ -48,7 +48,7 @@ #include "DIAG.h" #define LOOPLOCOS(THROTTLECHAR, CAB) for (int loco=0;loco\n"), myLocos[loco].throttle, LorS(myLocos[loco].cab), myLocos[loco].cab); + myLocos[loco].throttle='\0'; + } + } + DIAG(F("WiThrottle(%d) Quit\n"), clientid); delete this; break; } @@ -228,10 +236,10 @@ void WiThrottle::multithrottle(Print & stream, byte * cmd){ } } break; - case '-': // remove loco + case '-': // stop and remove loco(s) LOOPLOCOS(throttleChar, locoid) { myLocos[loco].throttle='\0'; - DCC::setThrottle(myLocos[loco].cab,0,1); + DCC::setThrottle(myLocos[loco].cab,0, DCC::getThrottleDirection(myLocos[loco].cab)); DCC::forgetLoco(myLocos[loco].cab); //unregister this loco address StringFormatter::send(stream, F("M%c-%c%d<;>\n"), throttleChar, LorS(myLocos[loco].cab), myLocos[loco].cab); } @@ -293,14 +301,14 @@ void WiThrottle::locoAction(Print & stream, byte* aval, char throttleChar, int c //Emergency Stop (speed code 1) LOOPLOCOS(throttleChar, cab) { DCC::setThrottle(myLocos[loco].cab,1, DCC::getThrottleDirection(myLocos[loco].cab)); - } - break; + } + break; case 'I': // Idle, set speed to 0 case 'Q': // Quit, set speed to 0 LOOPLOCOS(throttleChar, cab) { DCC::setThrottle(myLocos[loco].cab,0, DCC::getThrottleDirection(myLocos[loco].cab)); - } - break; + } + break; } } @@ -313,12 +321,13 @@ void WiThrottle::loop() { void WiThrottle::checkHeartbeat() { // if 2 heartbeats missed... STOP and forget all locos for this client if(heartBeatEnable && (millis()-heartBeat > HEARTBEAT_TIMEOUT*2000)) { - DIAG(F("WiThrottle hearbeat missed client=%d"),clientid); - for (int loco=0;loco