Skip to content

Commit

Permalink
support for individual track power
Browse files Browse the repository at this point in the history
receivedIndividualTrackPower(TrackPower state, int track)
  • Loading branch information
flash62au committed Mar 11, 2024
1 parent 7043555 commit 83d5273
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
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.10
version=0.0.11
author=Peter Cole, Peter Akers <akersp62@gmail.com>
maintainer=Peter Cole, Peter Akers <akersp62@gmail.com>
sentence=DCC-EX Native Protocol implementation
Expand Down
19 changes: 16 additions & 3 deletions src/DCCEXProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ void DCCEXProtocol::check() {
if (r=='>') {
if (DCCEXInbound::parse(_cmdBuffer)) {
// Process stuff here
_console->print("<== ");
_console->println(_cmdBuffer);
_processCommand();
}
// Clear buffer after use
Expand Down Expand Up @@ -560,7 +562,7 @@ void DCCEXProtocol::_processCommand() {
break;

case 'p': // Power broadcast
if (DCCEXInbound::isTextParameter(0) || DCCEXInbound::getParameterCount()!=1) break;
if (DCCEXInbound::isTextParameter(0) || DCCEXInbound::getParameterCount()>2) break;
_processTrackPower();
break;

Expand Down Expand Up @@ -1111,17 +1113,28 @@ void DCCEXProtocol::_processTurntableBroadcast() { // <I id position moving>
// Track management methods

void DCCEXProtocol::_processTrackPower() {
// console->println(F("processTrackPower()"));
// _console->println(F("processTrackPower()"));
if (_delegate) {
TrackPower state = PowerUnknown;
if (DCCEXInbound::getNumber(0)==PowerOff) {
state = PowerOff;
} else if (DCCEXInbound::getNumber(0)==PowerOn) {
state = PowerOn;
}
// _console->print(F("processTrackPower(): state: "));
// _console->println(state);

if (DCCEXInbound::getParameterCount()==2) {
int _track = DCCEXInbound::getNumber(1);
// _console->print("processTrackPower(): 2nd : ");
// _console->println(_track);
_delegate->receivedIndividualTrackPower(state,_track);

if (DCCEXInbound::getNumber(1) != 2698315) { return;} // not equal "MAIN"
}
_delegate->receivedTrackPower(state);
}
// console->println(F("processTrackPower(): end"));
// _console->print(F("processTrackPower(): end"));
}

void DCCEXProtocol::_processTrackType() {
Expand Down
9 changes: 8 additions & 1 deletion src/DCCEXProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
/*
Version information:
0.0.11 - support for individual track power receivedIndividualTrackPower(TrackPower state, int track)
- imporved logic for overall track power
0.0.10 - Add support for broadcast messages
0.0.9 - if loco is selected by address and that loco is in the roster (with the same DCC Address), updated and send speed commands for both
0.0.8 - No functional changes, add cross-platform and unit testing capabilities (credit to higaski)
Expand Down Expand Up @@ -140,10 +142,15 @@ class DCCEXProtocolDelegate {
/// @param loco Pointer to the loco object
virtual void receivedLocoUpdate(Loco* loco) {}

/// @brief Notify when a track power state change is received
/// @brief Notify when the global track power state change is received
/// @param state Power state received (PowerOff|PowerOn|PowerUnknown)
virtual void receivedTrackPower(TrackPower state) {}

/// @brief Notify when an individual track power state change is received
/// @param state Power state received (PowerOff|PowerOn|PowerUnknown)
/// @param track which track changed 65=A..72=H | 2698315=MAIN | 2788330=PROG | 2183=DC | 71999=DCX
virtual void receivedIndividualTrackPower(TrackPower state, int track) {}

/// @brief Notify when a track type change is received
/// @param track track that changed
/// @param type type received (MAIN|PROG|DC|DCX|NONE)
Expand Down

0 comments on commit 83d5273

Please sign in to comment.