diff --git a/DCC.h b/DCC.h index fadce8d..bbc93ef 100644 --- a/DCC.h +++ b/DCC.h @@ -122,7 +122,7 @@ public: private: static byte loopStatus; static byte defaultMomentumA; // Accelerating - static byte defaultMomentumD; // Accelerating + static byte defaultMomentumD; // Decelerating static void setThrottle2(uint16_t cab, uint8_t speedCode); static void setFunctionInternal(int cab, byte fByte, byte eByte, byte count); static bool issueReminder(LOCO * slot); diff --git a/EXRAIL2.cpp b/EXRAIL2.cpp index 85cbbec..5395286 100644 --- a/EXRAIL2.cpp +++ b/EXRAIL2.cpp @@ -86,6 +86,8 @@ LookList * RMFT2::onClockLookup=NULL; LookList * RMFT2::onRotateLookup=NULL; #endif LookList * RMFT2::onOverloadLookup=NULL; +LookList * RMFT2::onBlockEnterLookup=NULL; +LookList * RMFT2::onBlockExitLookup=NULL; byte * RMFT2::routeStateArray=nullptr; const FSH * * RMFT2::routeCaptionArray=nullptr; int16_t * RMFT2::stashArray=nullptr; @@ -130,11 +132,11 @@ int16_t LookList::find(int16_t value) { void LookList::chain(LookList * chain) { m_chain=chain; } -void LookList::handleEvent(const FSH* reason,int16_t id) { +void LookList::handleEvent(const FSH* reason,int16_t id, int16_t loco) { // New feature... create multiple ONhandlers for (int i=0;ihandleEvent(F("DEACTIVATE"),addr); } +void RMFT2::blockEvent(int16_t block, int16_t loco, bool entering) { + // Hunt for an ONBLOCKENTER/ONBLOCKEXIT for this accessory + if (entering) onBlockEnterLookup->handleEvent(F("BLOCKENTER"),block,loco); + else onBlockExitLookup->handleEvent(F("BLOCKEXIT"),block,loco); +} + void RMFT2::changeEvent(int16_t vpin, bool change) { // Hunt for an ONCHANGE for this sensor if (change) onChangeLookup->handleEvent(F("CHANGE"),vpin); @@ -1331,7 +1341,7 @@ void RMFT2::killBlinkOnVpin(VPIN pin) { } } -void RMFT2::startNonRecursiveTask(const FSH* reason, int16_t id,int pc) { +void RMFT2::startNonRecursiveTask(const FSH* reason, int16_t id,int pc, int16_t loco) { // Check we dont already have a task running this handler RMFT2 * task=loopTask; while(task) { @@ -1343,7 +1353,7 @@ void RMFT2::startNonRecursiveTask(const FSH* reason, int16_t id,int pc) { if (task==loopTask) break; } - task=new RMFT2(pc); // new task starts at this instruction + task=new RMFT2(pc,loco); // new task starts at this instruction task->onEventStartPosition=pc; // flag for recursion detector } diff --git a/EXRAIL2.h b/EXRAIL2.h index b0ed324..02458f7 100644 --- a/EXRAIL2.h +++ b/EXRAIL2.h @@ -77,6 +77,7 @@ enum OPCODE : byte {OPCODE_THROW,OPCODE_CLOSE,OPCODE_TOGGLE_TURNOUT, OPCODE_ROUTE_DISABLED, OPCODE_STASH,OPCODE_CLEAR_STASH,OPCODE_CLEAR_ALL_STASH,OPCODE_PICKUP_STASH, OPCODE_ONBUTTON,OPCODE_ONSENSOR, + OPCODE_ONBLOCKENTER,OPCODE_ONBLOCKEXIT, // OPcodes below this point are skip-nesting IF operations // placed here so that they may be skipped as a group // see skipIfBlock() @@ -119,6 +120,7 @@ enum BlinkState: byte { static const byte FEATURE_STASH = 0x08; static const byte FEATURE_BLINK = 0x04; static const byte FEATURE_SENSOR = 0x02; + static const byte FEATURE_BLOCK = 0x01; // Flag bits for status of hardware and TPL @@ -145,7 +147,7 @@ class LookList { int16_t findPosition(int16_t value); // finds index int16_t size(); void stream(Print * _stream); - void handleEvent(const FSH* reason,int16_t id); + void handleEvent(const FSH* reason,int16_t id, int16_t loco=0); private: int16_t m_size; @@ -170,6 +172,7 @@ class LookList { static void clockEvent(int16_t clocktime, bool change); static void rotateEvent(int16_t id, bool change); static void powerEvent(int16_t track, bool overload); + static void blockEvent(int16_t block, int16_t loco, bool entering); static bool signalAspectEvent(int16_t address, byte aspect ); static const int16_t SERVO_SIGNAL_FLAG=0x4000; static const int16_t ACTIVE_HIGH_SIGNAL_FLAG=0x2000; @@ -188,7 +191,7 @@ class LookList { static const FSH * getRosterFunctions(int16_t id); static const FSH * getTurntableDescription(int16_t id); static const FSH * getTurntablePositionDescription(int16_t turntableId, uint8_t positionId); - static void startNonRecursiveTask(const FSH* reason, int16_t id,int pc); + static void startNonRecursiveTask(const FSH* reason, int16_t id,int pc, int16_t loco=0); static bool readSensor(uint16_t sensorId); static bool isSignal(int16_t id,char rag); @@ -241,6 +244,9 @@ private: static LookList * onRotateLookup; #endif static LookList * onOverloadLookup; + static LookList * onBlockEnterLookup; + static LookList * onBlockExitLookup; + static const int countLCCLookup; static int onLCCLookup[];