diff --git a/CommandDistributor.cpp b/CommandDistributor.cpp index efd4778..351a18d 100644 --- a/CommandDistributor.cpp +++ b/CommandDistributor.cpp @@ -273,7 +273,7 @@ void CommandDistributor::broadcastTrackState(const FSH* format,byte trackLetter, broadcastReply(COMMAND_TYPE, format,trackLetter, dcAddr); } -void CommandDistributor::broadcastRouteState(uint16_t routeId, RouteState state ) { +void CommandDistributor::broadcastRouteState(uint16_t routeId, byte state ) { broadcastReply(COMMAND_TYPE, F("\n"),routeId,state); } diff --git a/CommandDistributor.h b/CommandDistributor.h index 839bcbf..83bfbbd 100644 --- a/CommandDistributor.h +++ b/CommandDistributor.h @@ -37,7 +37,6 @@ class CommandDistributor { public: enum clientType: byte {NONE_TYPE,COMMAND_TYPE,WITHROTTLE_TYPE}; - enum RouteState: byte {STATE_ACTIVE,STATE_INACTIVE,STATE_HIDDEN}; private: static void broadcastToClients(clientType type); static StringBuffer * broadcastBufferWriter; @@ -59,7 +58,7 @@ public : static void broadcastTrackState(const FSH* format,byte trackLetter, int16_t dcAddr); template static void broadcastReply(clientType type, Targs... msg); static void forget(byte clientId); - static void broadcastRouteState(uint16_t routeId,RouteState state); + static void broadcastRouteState(uint16_t routeId,byte state); static void broadcastRouteCaption(uint16_t routeId,const FSH * caption); diff --git a/EXRAIL2.cpp b/EXRAIL2.cpp index 634df29..870ff6d 100644 --- a/EXRAIL2.cpp +++ b/EXRAIL2.cpp @@ -100,6 +100,7 @@ LookList * RMFT2::onClockLookup=NULL; LookList * RMFT2::onRotateLookup=NULL; #endif LookList * RMFT2::onOverloadLookup=NULL; +byte * RMFT2::routeStateArray=nullptr; #define GET_OPCODE GETHIGHFLASH(RMFT2::RouteCode,progCounter) #define SKIPOP progCounter+=3 @@ -139,6 +140,15 @@ int16_t LookList::find(int16_t value) { } return -1; } +int16_t LookList::findPosition(int16_t value) { + for (int16_t i=0;isize(),sizeof(byte)); onThrowLookup=LookListLoader(OPCODE_ONTHROW); onCloseLookup=LookListLoader(OPCODE_ONCLOSE); onActivateLookup=LookListLoader(OPCODE_ONACTIVATE); @@ -1131,13 +1142,13 @@ void RMFT2::loop2() { printMessage(operand); break; case OPCODE_ROUTE_HIDDEN: - CommandDistributor::broadcastRouteState(operand,CommandDistributor::RouteState::STATE_HIDDEN); + manageRoute(operand,2); break; case OPCODE_ROUTE_ACTIVE: - CommandDistributor::broadcastRouteState(operand,CommandDistributor::RouteState::STATE_ACTIVE); + manageRoute(operand,0); break; case OPCODE_ROUTE_INACTIVE: - CommandDistributor::broadcastRouteState(operand,CommandDistributor::RouteState::STATE_INACTIVE); + manageRoute(operand,1); break; case OPCODE_ROUTE: @@ -1462,3 +1473,14 @@ void RMFT2::thrungeString(uint32_t strfar, thrunger mode, byte id) { break; } } + +void RMFT2::manageRoute(uint16_t id, byte state) { + CommandDistributor::broadcastRouteState(id,state); + // Route state must be maintained for when new throttles connect. + // locate route id in the Routes lookup + int16_t position=sequenceLookup->findPosition(id); + if (position<0) return; + // set state beside it + routeStateArray[position]=state; +} + \ No newline at end of file diff --git a/EXRAIL2.h b/EXRAIL2.h index 1898b26..ed3e459 100644 --- a/EXRAIL2.h +++ b/EXRAIL2.h @@ -121,7 +121,9 @@ class LookList { public: LookList(int16_t size); void add(int16_t lookup, int16_t result); - int16_t find(int16_t value); + int16_t find(int16_t value); // finds result value + int16_t findPosition(int16_t value); // finds index + int16_t size(); private: int16_t m_size; int16_t m_loaded; @@ -217,6 +219,8 @@ private: static const int countLCCLookup; static int onLCCLookup[]; static const byte compileFeatures; + static void manageRoute(uint16_t id, byte state); + static byte * routeStateArray; // Local variables - exist for each instance/task RMFT2 *next; // loop chain diff --git a/EXRAIL2MacroReset.h b/EXRAIL2MacroReset.h index 9bfad1b..ff8dc8d 100644 --- a/EXRAIL2MacroReset.h +++ b/EXRAIL2MacroReset.h @@ -126,8 +126,8 @@ #undef ROTATE #undef ROTATE_DCC #undef ROUTE -#undef ROUTE_ACTVE -#undef ROUTE_INACTVE +#undef ROUTE_ACTIVE +#undef ROUTE_INACTIVE #undef ROUTE_HIDDEN #undef ROUTE_CAPTION #undef SENDLOCO