diff --git a/CommandDistributor.cpp b/CommandDistributor.cpp index aeed9ca..730d2c7 100644 --- a/CommandDistributor.cpp +++ b/CommandDistributor.cpp @@ -24,6 +24,7 @@ #include "DIAG.h" #include "defines.h" #include "DCCWaveform.h" +#include "DCC.h" const byte NO_CLIENT=255; @@ -93,8 +94,10 @@ void CommandDistributor::broadcastTurnout(int16_t id, bool isClosed ) { broadcast(); } - void CommandDistributor::broadcastLoco(int16_t cab, int16_t slot, byte speed, uint32_t functions) { - StringFormatter::send(broadcastBufferWriter,F("\n"), cab,slot,speed,functions); + void CommandDistributor::broadcastLoco(byte slot) { + DCC::LOCO * sp=&DCC::speedTable[slot]; + StringFormatter::send(broadcastBufferWriter,F("\n"), + sp->loco,slot,sp->speedCode,sp->functions); broadcast(); } diff --git a/CommandDistributor.h b/CommandDistributor.h index b861856..e855e51 100644 --- a/CommandDistributor.h +++ b/CommandDistributor.h @@ -25,7 +25,7 @@ class CommandDistributor { public : static void parse(byte clientId,byte* buffer, RingStream * ring); - static void broadcastLoco(int16_t cab, int16_t slot, byte speed, uint32_t functions); + static void broadcastLoco(byte slot); static void broadcastSensor(int16_t id, bool value); static void broadcastTurnout(int16_t id, bool isClosed); static void broadcastPower(); diff --git a/DCC.cpp b/DCC.cpp index 70e09af..2ac863d 100644 --- a/DCC.cpp +++ b/DCC.cpp @@ -27,6 +27,7 @@ #include "version.h" #include "FSH.h" #include "IODevice.h" +#include "CommandDistributor.h" // This module is responsible for converting API calls into // messages to be sent to the waveform generator. @@ -185,6 +186,7 @@ void DCC::setFn( int cab, int16_t functionNumber, bool on) { speedTable[reg].functions &= ~funcmask; } updateGroupflags(speedTable[reg].groupFlags, functionNumber); + CommandDistributor::broadcastLoco(reg); return; } @@ -218,6 +220,7 @@ int DCC::changeFn( int cab, int16_t functionNumber, bool pressed) { funcstate = (speedTable[reg].functions & funcmask)? 1 : 0; } updateGroupflags(speedTable[reg].groupFlags, functionNumber); + CommandDistributor::broadcastLoco(reg); return funcstate; } @@ -667,6 +670,7 @@ int DCC::lookupSpeedTable(int locoId) { speedTable[reg].speedCode=128; // default direction forward speedTable[reg].groupFlags=0; speedTable[reg].functions=0; + CommandDistributor::broadcastLoco(reg); } return reg; } @@ -677,13 +681,17 @@ void DCC::updateLocoReminder(int loco, byte speedCode) { // broadcast stop/estop but dont change direction for (int reg = 0; reg < MAX_LOCOS; reg++) { speedTable[reg].speedCode = (speedTable[reg].speedCode & 0x80) | (speedCode & 0x7f); + CommandDistributor::broadcastLoco(reg); } return; } // determine speed reg for this loco int reg=lookupSpeedTable(loco); - if (reg>=0) speedTable[reg].speedCode = speedCode; + if (reg>=0) { + speedTable[reg].speedCode = speedCode; + CommandDistributor::broadcastLoco(reg); + } } DCC::LOCO DCC::speedTable[MAX_LOCOS]; diff --git a/DCC.h b/DCC.h index fea9a1a..1bf27ae 100644 --- a/DCC.h +++ b/DCC.h @@ -134,7 +134,6 @@ public: return ackRetryPSum; }; -private: struct LOCO { int loco; @@ -142,6 +141,9 @@ private: byte groupFlags; unsigned long functions; }; + static LOCO speedTable[MAX_LOCOS]; + +private: static byte joinRelay; static byte loopStatus; static void setThrottle2(uint16_t cab, uint8_t speedCode); @@ -152,7 +154,6 @@ private: static FSH *shieldName; static byte globalSpeedsteps; - static LOCO speedTable[MAX_LOCOS]; static byte cv1(byte opcode, int cv); static byte cv2(int cv); static int lookupSpeedTable(int locoId);