Skip to content

Commit

Permalink
add isFunctionMomentary(int function);
Browse files Browse the repository at this point in the history
  • Loading branch information
flash62au committed Jan 29, 2024
1 parent 2c2f961 commit 56868d8
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
11 changes: 11 additions & 0 deletions examples/DCCEXProtocol_Roster_etc/DCCEXProtocol_Roster_etc.ino
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ void printRoster() {
Serial.print(" ~");
Serial.print(name);
Serial.println("~");
for (int i=0; i<32; i++) {
char* fName = loco->getFunctionName(i);
if (fName != nullptr) {
Serial.print("loadFunctionLabels() ");
Serial.print(fName);
if (loco->isFunctionMomentary(i)) {
Serial.print(" - Momentary");
}
Serial.println();
}
}
}
Serial.println("\n");
}
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=DCCEXProtocol
version=0.0.6
version=0.0.7
author=Peter Cole, Peter Akers <[email protected]>
maintainer=Peter Cole, Peter Akers <[email protected]>
sentence=DCC-EX Native Protocol implementation
Expand Down
6 changes: 5 additions & 1 deletion src/DCCEXLoco.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void Loco::setupFunctions(char *functionNames) {
if (momentary) {
_momentaryFlags |= 1<<fkey;
} else {
_momentaryFlags &= ~1<<fkey;
_momentaryFlags &= ~(1<<fkey);
}
}
// Serial.print("Function ");
Expand Down Expand Up @@ -153,6 +153,10 @@ char* Loco::getFunctionName(int function) {
return _functionNames[function];
}

bool Loco::isFunctionMomentary(int function) {
return _momentaryFlags & 1<<function;
}

Loco* Loco::getFirst() {
return _first;
}
Expand Down
5 changes: 5 additions & 0 deletions src/DCCEXLoco.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ class Loco {
/// @return char* representing the function name/label
char* getFunctionName(int function);

/// @brief Get the name/label for a function
/// @param function Number of the function to return the name/label of
/// @return char* representing the function name/label
bool isFunctionMomentary(int function);

/// @brief Get first Loco object
/// @return Pointer to the first Loco object
static Loco* getFirst();
Expand Down
1 change: 1 addition & 0 deletions src/DCCEXProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
/*
Version information:
0.0.6 - add isFunctionMomentary(int function);
0.0.6 - add getFunctionName(int function);
0.0.5 - Increase MAX_FUNCTIONS to 32.
- Also add check to make sure the incoming does not exceed MAX_FUNCTIONS
Expand Down

0 comments on commit 56868d8

Please sign in to comment.