Skip to content

Commit

Permalink
support for 32 functions
Browse files Browse the repository at this point in the history
  • Loading branch information
flash62au committed Dec 27, 2023
1 parent 90ea08d commit 3964b93
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void setFunction(char multiThrottle, String address, int num, bool pressed)
void setFunction(char multiThrottle, int num, bool pressed)
void setFunction(int num, bool pressed)
```
Update the state for the specified function (0-28 is the acceptable range). If the function button has been pressed down (or otherwise activated), set ```pressed``` to ```true```. When the button is released, set ```pressed``` to ```false```.
Update the state for the specified function (0-31 is the acceptable range). If the function button has been pressed down (or otherwise activated), set ```pressed``` to ```true```. When the button is released, set ```pressed``` to ```false```.

multiThrottle defaults to 'T' if not specified. Otherwise use '0', '1', '2', '3', '4', '5' only.
If the Address is blank ("") on not provided, the lead loco only ill be sent the function. "*" will send to all locos in the consist.
Expand Down Expand Up @@ -260,7 +260,7 @@ void receivedRosterEntry(int index, String name, int address, char length)
Indicates that the WiThrottle Server has sent the details of an individual roster entry.

```
virtual void receivedRosterFunctionList(String functions[28]) { }
virtual void receivedRosterFunctionList(String functions[31]) { }
```

Indicates the labels of the functions for the roster entry.
Expand Down
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.5
version=1.1.6
author=David Zuhn <zoo@statebeltrailway.org>, Luca Dentella <luca@dentella.it>, Peter Akers <akersp62@gmail.com>
maintainer=Peter Akers <akersp62@gmail.com>
sentence=JMRI WiThrottle Protocol implementation
Expand Down
10 changes: 5 additions & 5 deletions src/WiThrottleProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ void
WiThrottleProtocol::processFunctionState(char multiThrottle, const String& functionData) {
console->print("processFunctionState(): "); console->println(multiThrottle);

// F[0|1]nn - where nn is 0-28
// F[0|1]nn - where nn is 0-31
if (delegate && functionData.length() >= 3) {
bool state = functionData[1]=='1' ? true : false;

Expand All @@ -737,15 +737,15 @@ void
WiThrottleProtocol::processRosterFunctionListEntries(char multiThrottle, const String& s) {
console->print("processRosterFunctionListEntries(): "); console->println(multiThrottle);

String functions[28];
String functions[MAX_FUNCTIONS];

// loop
int entries = -1;
boolean entryFound = true;
int entryStartPosition = 3; //ignore the first entry separator
if (s.length() <= 3) entryFound =false;

while ((entryFound) && (entries < 28)) {
while ((entryFound) && (entries < MAX_FUNCTIONS)) {
entries++;

// get element
Expand All @@ -760,7 +760,7 @@ WiThrottleProtocol::processRosterFunctionListEntries(char multiThrottle, const S

console->print("Functions for roster entry: "); console->println(entries);

for(int i = entries+1; i < 28; i++) {
for(int i = entries+1; i < MAX_FUNCTIONS; i++) {
functions[i] = "";
}

Expand Down Expand Up @@ -1369,7 +1369,7 @@ WiThrottleProtocol::setFunction(char multiThrottle, String address, int funcNum,
return;
}

if (funcNum < 0 || funcNum > 28) {
if (funcNum < 0 || funcNum > MAX_FUNCTIONS) {
return;
}

Expand Down
6 changes: 4 additions & 2 deletions src/WiThrottleProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
#define DEFAULT_MULTITHROTTLE 'T'
#define ALL_LOCOS_ON_THROTTLE "*"

#define MAX_FUNCTIONS 32

typedef enum Direction {
Reverse = 0,
Forward = 1
Expand Down Expand Up @@ -106,10 +108,10 @@ class WiThrottleProtocolDelegate
virtual void heartbeatConfig(int seconds) { }

virtual void receivedFunctionState(uint8_t func, bool state) { }
virtual void receivedRosterFunctionList(String functions[28]) { }
virtual void receivedRosterFunctionList(String functions[MAX_FUNCTIONS]) { }

virtual void receivedFunctionStateMultiThrottle(char multiThrottle, uint8_t func, bool state) { }
virtual void receivedRosterFunctionListMultiThrottle(char multiThrottle, String functions[28]) { }
virtual void receivedRosterFunctionListMultiThrottle(char multiThrottle, String functions[MAX_FUNCTIONS]) { }

virtual void receivedSpeed(int speed) { } // Vnnn
virtual void receivedDirection(Direction dir) { } // R{0,1}
Expand Down

0 comments on commit 3964b93

Please sign in to comment.