Skip to content

Commit

Permalink
Corrected the EStop for 'all' throttles
Browse files Browse the repository at this point in the history
  • Loading branch information
flash62au committed Jul 30, 2024
1 parent bb1dafe commit 675c708
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=WiThrottleProtocol
version=1.1.19
version=1.1.20
author=Peter Akers <[email protected]>, David Zuhn <[email protected]>, Luca Dentella <[email protected]>
maintainer=Peter Akers <[email protected]>
sentence=JMRI WiThrottle Protocol implementation for ESP32
Expand Down
23 changes: 16 additions & 7 deletions src/WiThrottleProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ bool WiThrottleProtocol::checkHeartbeat() {

// if there are any locos under control, resend all their speeds
if ( (timeLastLocoAcquired!=0) && ((millis() - timeLastLocoAcquired) > 5000) ) { // wait at least 5 seconds from the last time that a loco was aqcuired, to give the server time to send any existing speeds
for (int i=0; i<6; i++) {
for (int i=0; i<MAX_WIT_THROTTLES; i++) {
char multiThrottleChar = '0' + i;
if (getNumberOfLocomotives(multiThrottleChar)>0) {
setSpeed(multiThrottleChar, getSpeed(multiThrottleChar), true);
Expand Down Expand Up @@ -1393,20 +1393,29 @@ Direction WiThrottleProtocol::getDirection(char multiThrottle, String address) {
// ******************************************************************************************************

void WiThrottleProtocol::emergencyStop() {
emergencyStop(DEFAULT_MULTITHROTTLE, ALL_LOCOS_ON_THROTTLE);
emergencyStop('*', ALL_LOCOS_ON_THROTTLE);
}
void WiThrottleProtocol::emergencyStop(char multiThrottle) {
emergencyStop(multiThrottle, ALL_LOCOS_ON_THROTTLE);
}

void WiThrottleProtocol::emergencyStop(char multiThrottle, String address) {
if (logLevel>0) { console->print("WiT:: emergencyStop(): "); console->print(multiThrottle);console->print(" address: "); console->print(address); }
setSpeed(multiThrottle,0);
String cmd = "M" + String(multiThrottle) + "A" + address;
cmd.concat(PROPERTY_SEPARATOR);
cmd.concat("X");

sendDelayedCommand(cmd);
String cmd; cmd.reserve(10);
char multiThrottleChar = multiThrottle;

if (multiThrottleChar!='*') { // single throttle
setSpeed(multiThrottle,0);
cmd = "M" + String(multiThrottle) + "A" + address + PROPERTY_SEPARATOR + "X";
sendDelayedCommand(cmd);
} else { // all throttles
for (int i=0; i<MAX_WIT_THROTTLES; i++) {
multiThrottleChar = '0' + i;
cmd = "M" + String(multiThrottleChar) + "A" + address + PROPERTY_SEPARATOR + "X";
sendDelayedCommand(cmd);
}
}
}

// ******************************************************************************************************
Expand Down
12 changes: 7 additions & 5 deletions src/WiThrottleProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
/*
Version information:
1.1.20 - Corrected the EStop for 'all' throttles
1.1.18/19- Added support for logLevel. Assigned levels to every log message
- changed all the log messages so that it is clearer which came from this library
1.1.17 - fix version numbers. no code change
Expand Down Expand Up @@ -68,6 +69,7 @@ Version information:
#define DEFAULT_MULTITHROTTLE 'T'
#define ALL_LOCOS_ON_THROTTLE "*"

#define MAX_WIT_THROTTLES 6
#define MAX_FUNCTIONS 32

/// @brief Loco/Throttle Direction options
Expand Down Expand Up @@ -760,13 +762,13 @@ class WiThrottleProtocol

void init();

bool locomotiveSelected[6] = {false, false, false, false, false, false};
bool locomotiveSelected[MAX_WIT_THROTTLES] = {false, false, false, false, false, false};

String currentAddress[6];
String currentAddress[MAX_WIT_THROTTLES];

int currentSpeed[6];
int speedSteps[6]; // 1=128, 2=28, 4=27, 8=14, 16=28Mot
Direction currentDirection[6];
int currentSpeed[MAX_WIT_THROTTLES];
int speedSteps[MAX_WIT_THROTTLES]; // 1=128, 2=28, 4=27, 8=14, 16=28Mot
Direction currentDirection[MAX_WIT_THROTTLES];

String mostRecentTurnout;
TurnoutState mostRecentTurnoutState;
Expand Down

0 comments on commit 675c708

Please sign in to comment.