From 4e08177b7bc3417475fb90e8ec28f63f9f553115 Mon Sep 17 00:00:00 2001 From: Asbelos Date: Tue, 7 Nov 2023 16:27:26 +0000 Subject: [PATCH] Route state management (part 1) --- CommandDistributor.cpp | 8 ++++++++ CommandDistributor.h | 4 ++++ EXRAIL2.cpp | 11 ++++++++++- EXRAIL2.h | 1 + EXRAIL2MacroReset.h | 8 ++++++++ EXRAILMacros.h | 10 ++++++++++ 6 files changed, 41 insertions(+), 1 deletion(-) diff --git a/CommandDistributor.cpp b/CommandDistributor.cpp index 1651771..efd4778 100644 --- a/CommandDistributor.cpp +++ b/CommandDistributor.cpp @@ -272,3 +272,11 @@ void CommandDistributor::broadcastRaw(clientType type, char * msg) { void CommandDistributor::broadcastTrackState(const FSH* format,byte trackLetter, int16_t dcAddr) { broadcastReply(COMMAND_TYPE, format,trackLetter, dcAddr); } + +void CommandDistributor::broadcastRouteState(uint16_t routeId, RouteState state ) { + broadcastReply(COMMAND_TYPE, F("\n"),routeId,state); +} + +void CommandDistributor::broadcastRouteCaption(uint16_t routeId, const FSH* caption ) { + broadcastReply(COMMAND_TYPE, F("\n"),routeId,caption); +} diff --git a/CommandDistributor.h b/CommandDistributor.h index d54ef31..839bcbf 100644 --- a/CommandDistributor.h +++ b/CommandDistributor.h @@ -37,6 +37,7 @@ 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; @@ -58,6 +59,9 @@ 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 broadcastRouteCaption(uint16_t routeId,const FSH * caption); + }; diff --git a/EXRAIL2.cpp b/EXRAIL2.cpp index c902708..634df29 100644 --- a/EXRAIL2.cpp +++ b/EXRAIL2.cpp @@ -1130,7 +1130,16 @@ void RMFT2::loop2() { case OPCODE_PRINT: printMessage(operand); break; - + case OPCODE_ROUTE_HIDDEN: + CommandDistributor::broadcastRouteState(operand,CommandDistributor::RouteState::STATE_HIDDEN); + break; + case OPCODE_ROUTE_ACTIVE: + CommandDistributor::broadcastRouteState(operand,CommandDistributor::RouteState::STATE_ACTIVE); + break; + case OPCODE_ROUTE_INACTIVE: + CommandDistributor::broadcastRouteState(operand,CommandDistributor::RouteState::STATE_INACTIVE); + break; + case OPCODE_ROUTE: case OPCODE_AUTOMATION: case OPCODE_SEQUENCE: diff --git a/EXRAIL2.h b/EXRAIL2.h index de14f11..1898b26 100644 --- a/EXRAIL2.h +++ b/EXRAIL2.h @@ -68,6 +68,7 @@ enum OPCODE : byte {OPCODE_THROW,OPCODE_CLOSE, OPCODE_ONROTATE,OPCODE_ROTATE,OPCODE_WAITFORTT, OPCODE_LCC,OPCODE_LCCX,OPCODE_ONLCC, OPCODE_ONOVERLOAD, + OPCODE_ROUTE_ACTIVE,OPCODE_ROUTE_INACTIVE,OPCODE_ROUTE_HIDDEN, // OPcodes below this point are skip-nesting IF operations // placed here so that they may be skipped as a group diff --git a/EXRAIL2MacroReset.h b/EXRAIL2MacroReset.h index d44b244..9bfad1b 100644 --- a/EXRAIL2MacroReset.h +++ b/EXRAIL2MacroReset.h @@ -126,6 +126,10 @@ #undef ROTATE #undef ROTATE_DCC #undef ROUTE +#undef ROUTE_ACTVE +#undef ROUTE_INACTVE +#undef ROUTE_HIDDEN +#undef ROUTE_CAPTION #undef SENDLOCO #undef SEQUENCE #undef SERIAL @@ -267,6 +271,10 @@ #define ROTATE_DCC(turntable_id,position) #define ROSTER(cab,name,funcmap...) #define ROUTE(id,description) +#define ROUTE_ACTIVE(id) +#define ROUTE_INACTIVE(id) +#define ROUTE_HIDDEN(id) +#define ROUTE_CAPTION(id,caption) #define SENDLOCO(cab,route) #define SEQUENCE(id) #define SERIAL(msg) diff --git a/EXRAILMacros.h b/EXRAILMacros.h index 8954f6d..e11b5db 100644 --- a/EXRAILMacros.h +++ b/EXRAILMacros.h @@ -153,6 +153,12 @@ const int StringMacroTracker1=__COUNTER__; #define PRINT(msg) THRUNGE(msg,thrunge_print) #undef LCN #define LCN(msg) THRUNGE(msg,thrunge_lcn) +#undef ROUTE_CAPTION +#define ROUTE_CAPTION(id,caption) \ +case (__COUNTER__ - StringMacroTracker1) : {\ + CommandDistributor::broadcastRouteCaption(id,F(caption));\ + return;\ + } #undef SERIAL #define SERIAL(msg) THRUNGE(msg,thrunge_serial) #undef SERIAL1 @@ -440,6 +446,10 @@ int RMFT2::onLCCLookup[RMFT2::countLCCLookup]; #define ROTATE_DCC(id,position) OPCODE_ROTATE,V(id),OPCODE_PAD,V(position),OPCODE_PAD,V(0), #endif #define ROUTE(id, description) OPCODE_ROUTE, V(id), +#define ROUTE_ACTIVE(id) OPCODE_ROUTE_ACTIVE,V(id), +#define ROUTE_INACTIVE(id) OPCODE_ROUTE_INACTIVE,V(id), +#define ROUTE_HIDDEN(id) OPCODE_ROUTE_HIDDEN,V(id), +#define ROUTE_CAPTION(id,caption) PRINT(caption) #define SENDLOCO(cab,route) OPCODE_SENDLOCO,V(cab),OPCODE_PAD,V(route), #define SEQUENCE(id) OPCODE_SEQUENCE, V(id), #define SERIAL(msg) PRINT(msg)