From d24a40702145e5877eafe29ca43f4b3b585aa76b Mon Sep 17 00:00:00 2001 From: Asbelos Date: Tue, 8 Aug 2023 17:17:34 +0100 Subject: [PATCH] ONLCC poc --- EXRAIL2.cpp | 35 +++++++++++++++++++++++++++++++++++ EXRAIL2.h | 4 +++- EXRAIL2MacroReset.h | 2 ++ EXRAILMacros.h | 14 ++++++++++++++ version.h | 2 +- 5 files changed, 55 insertions(+), 2 deletions(-) diff --git a/EXRAIL2.cpp b/EXRAIL2.cpp index a134068..95ba6a2 100644 --- a/EXRAIL2.cpp +++ b/EXRAIL2.cpp @@ -70,6 +70,8 @@ const int16_t HASH_KEYWORD_RED=26099; const int16_t HASH_KEYWORD_AMBER=18713; const int16_t HASH_KEYWORD_GREEN=-31493; const int16_t HASH_KEYWORD_S='S'; +const int16_t HASH_KEYWORD_L='L'; +const int16_t HASH_KEYWORD_E='E'; // One instance of RMFT clas is used for each "thread" in the automation. // Each thread manages a loco on a journey through the layout, and/or may manage a scenery automation. @@ -310,7 +312,39 @@ void RMFT2::ComandFilter(Print * stream, byte & opcode, byte & paramCount, int16 } StringFormatter::send(stream,F(">\n")); opcode=0; + return; } + if (paramCount==1 && p[0]==HASH_KEYWORD_L) { // + // we stream the hex events we wish to listen to + // and at the same time build the event index lookup + + LCCSerial=stream; + StringFormatter::send(stream,F("\n")); + opcode=0; + return; + } + if (paramCount==2 && p[0]==HASH_KEYWORD_E) { // + reject=p[1]<0 || p[1]>=countLCCLookup; + if (reject) break; + new RMFT2(onLCCLookup[p[1]]); + opcode=0; + return; + } break; default: // other commands pass through @@ -997,6 +1031,7 @@ void RMFT2::loop2() { case OPCODE_SERVOTURNOUT: // Turnout definition ignored at runtime case OPCODE_PINTURNOUT: // Turnout definition ignored at runtime case OPCODE_ONCLOSE: // Turnout event catchers ignored here + case OPCODE_ONLCC: // LCC event catchers ignored here case OPCODE_ONTHROW: case OPCODE_ONACTIVATE: // Activate event catchers ignored here case OPCODE_ONDEACTIVATE: diff --git a/EXRAIL2.h b/EXRAIL2.h index c99d5dc..0cc995d 100644 --- a/EXRAIL2.h +++ b/EXRAIL2.h @@ -62,7 +62,7 @@ enum OPCODE : byte {OPCODE_THROW,OPCODE_CLOSE, OPCODE_ONCHANGE, OPCODE_ONCLOCKTIME, OPCODE_ONTIME, - OPCODE_LCC, + OPCODE_LCC,OPCODE_ONLCC, // OPcodes below this point are skip-nesting IF operations // placed here so that they may be skipped as a group @@ -190,6 +190,8 @@ private: static LookList * onGreenLookup; static LookList * onChangeLookup; static LookList * onClockLookup; + static const int countLCCLookup; + static int onLCCLookup[]; // Local variables - exist for each instance/task RMFT2 *next; // loop chain diff --git a/EXRAIL2MacroReset.h b/EXRAIL2MacroReset.h index 07ac364..9ea1a36 100644 --- a/EXRAIL2MacroReset.h +++ b/EXRAIL2MacroReset.h @@ -91,6 +91,7 @@ #undef ONDEACTIVATE #undef ONDEACTIVATEL #undef ONCLOSE +#undef ONLCC #undef ONTIME #undef ONCLOCKTIME #undef ONCLOCKMINS @@ -220,6 +221,7 @@ #define ONDEACTIVATE(addr,subaddr) #define ONDEACTIVATEL(linear) #define ONCLOSE(turnout_id) +#define ONLCC(sender,event) #define ONGREEN(signal_id) #define ONRED(signal_id) #define ONTHROW(turnout_id) diff --git a/EXRAILMacros.h b/EXRAILMacros.h index 56ed2f7..18abf7a 100644 --- a/EXRAILMacros.h +++ b/EXRAILMacros.h @@ -243,6 +243,16 @@ const HIGHFLASH int16_t RMFT2::SignalDefinitions[] = { #include "myAutomation.h" 0,0,0,0 }; +// Pass 9 ONLCC counter and lookup array +#include "EXRAIL2MacroReset.h" +#undef ONLCC +#define ONLCC(sender,event) +1 + +const int RMFT2::countLCCLookup=0 +#include "myAutomation.h" +; +int RMFT2::onLCCLookup[RMFT2::countLCCLookup]; + // Last Pass : create main routes table // Only undef the macros, not dummy them. #define RMFT2_UNDEF_ONLY @@ -318,6 +328,10 @@ const HIGHFLASH int16_t RMFT2::SignalDefinitions[] = { #define ONACTIVATEL(linear) OPCODE_ONACTIVATE,V(linear+3), #define ONAMBER(signal_id) OPCODE_ONAMBER,V(signal_id), #define ONCLOSE(turnout_id) OPCODE_ONCLOSE,V(turnout_id), +#define ONLCC(sender,event) OPCODE_ONLCC,V(event),\ + OPCODE_PAD,V((((uint64_t)sender)>>32)&0xFFFF),\ + OPCODE_PAD,V((((uint64_t)sender)>>16)&0xFFFF),\ + OPCODE_PAD,V((((uint64_t)sender)>>0)&0xFFFF), #define ONTIME(value) OPCODE_ONTIME,V(value), #define ONCLOCKTIME(hours,mins) OPCODE_ONTIME,V((STRIP_ZERO(hours)*60)+STRIP_ZERO(mins)), #define ONCLOCKMINS(mins) ONCLOCKTIME(25,mins) diff --git a/version.h b/version.h index bfb3a0b..e6cb735 100644 --- a/version.h +++ b/version.h @@ -3,7 +3,7 @@ #include "StringFormatter.h" -#define VERSION "4.2.66" +#define VERSION "5.0.1LCC" // 4.2.66 - Throttle inrush current by applying PWM to brake pin when // fault pin goes active // 4.2.65 - new config WIFI_FORCE_AP option