1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-12-25 13:41:23 +01:00

EXRAIL multiple ON events

This commit is contained in:
Asbelos 2023-11-10 20:13:33 +00:00
parent 670645db4b
commit d2d7a5cd16
3 changed files with 25 additions and 22 deletions

View File

@ -126,6 +126,13 @@ int16_t LookList::find(int16_t value) {
void LookList::chain(LookList * chain) { void LookList::chain(LookList * chain) {
m_chain=chain; m_chain=chain;
} }
void LookList::handleEvent(const FSH* reason,int16_t id) {
// New feature... create multiple ONhandlers
for (int i=0;i<m_size;i++)
if (m_lookupArray[i]==id)
RMFT2::startNonRecursiveTask(reason,id,m_resultArray[i]);
}
void LookList::stream(Print * _stream) { void LookList::stream(Print * _stream) {
for (int16_t i=0;i<m_size;i++) { for (int16_t i=0;i<m_size;i++) {
@ -1013,9 +1020,9 @@ int16_t RMFT2::getSignalSlot(int16_t id) {
// Schedule any event handler for this signal change. // Schedule any event handler for this signal change.
// Thjis will work even without a signal definition. // Thjis will work even without a signal definition.
if (rag==SIGNAL_RED) handleEvent(F("RED"),onRedLookup,id); if (rag==SIGNAL_RED) onRedLookup->handleEvent(F("RED"),id);
else if (rag==SIGNAL_GREEN) handleEvent(F("GREEN"), onGreenLookup,id); else if (rag==SIGNAL_GREEN) onGreenLookup->handleEvent(F("GREEN"),id);
else handleEvent(F("AMBER"), onAmberLookup,id); else onAmberLookup->handleEvent(F("AMBER"),id);
int16_t sigslot=getSignalSlot(id); int16_t sigslot=getSignalSlot(id);
if (sigslot<0) return; if (sigslot<0) return;
@ -1084,26 +1091,26 @@ int16_t RMFT2::getSignalSlot(int16_t id) {
void RMFT2::turnoutEvent(int16_t turnoutId, bool closed) { void RMFT2::turnoutEvent(int16_t turnoutId, bool closed) {
// Hunt for an ONTHROW/ONCLOSE for this turnout // Hunt for an ONTHROW/ONCLOSE for this turnout
if (closed) handleEvent(F("CLOSE"),onCloseLookup,turnoutId); if (closed) onCloseLookup->handleEvent(F("CLOSE"),turnoutId);
else handleEvent(F("THROW"),onThrowLookup,turnoutId); else onThrowLookup->handleEvent(F("THROW"),turnoutId);
} }
void RMFT2::activateEvent(int16_t addr, bool activate) { void RMFT2::activateEvent(int16_t addr, bool activate) {
// Hunt for an ONACTIVATE/ONDEACTIVATE for this accessory // Hunt for an ONACTIVATE/ONDEACTIVATE for this accessory
if (activate) handleEvent(F("ACTIVATE"),onActivateLookup,addr); if (activate) onActivateLookup->handleEvent(F("ACTIVATE"),addr);
else handleEvent(F("DEACTIVATE"),onDeactivateLookup,addr); else onDeactivateLookup->handleEvent(F("DEACTIVATE"),addr);
} }
void RMFT2::changeEvent(int16_t vpin, bool change) { void RMFT2::changeEvent(int16_t vpin, bool change) {
// Hunt for an ONCHANGE for this sensor // Hunt for an ONCHANGE for this sensor
if (change) handleEvent(F("CHANGE"),onChangeLookup,vpin); if (change) onChangeLookup->handleEvent(F("CHANGE"),vpin);
} }
#ifndef IO_NO_HAL #ifndef IO_NO_HAL
void RMFT2::rotateEvent(int16_t turntableId, bool change) { void RMFT2::rotateEvent(int16_t turntableId, bool change) {
// Hunt or an ONROTATE for this turntable // Hunt or an ONROTATE for this turntable
if (change) handleEvent(F("ROTATE"),onRotateLookup,turntableId); if (change) onRotateLookup->handleEvent(F("ROTATE"),turntableId);
} }
#endif #endif
@ -1112,8 +1119,8 @@ void RMFT2::clockEvent(int16_t clocktime, bool change) {
if (Diag::CMD) if (Diag::CMD)
DIAG(F("Looking for clock event at : %d"), clocktime); DIAG(F("Looking for clock event at : %d"), clocktime);
if (change) { if (change) {
handleEvent(F("CLOCK"),onClockLookup,clocktime); onClockLookup->handleEvent(F("CLOCK"),clocktime);
handleEvent(F("CLOCK"),onClockLookup,25*60+clocktime%60); onClockLookup->handleEvent(F("CLOCK"),25*60+clocktime%60);
} }
} }
@ -1122,16 +1129,10 @@ void RMFT2::powerEvent(int16_t track, bool overload) {
if (Diag::CMD) if (Diag::CMD)
DIAG(F("Looking for Power event on track : %c"), track); DIAG(F("Looking for Power event on track : %c"), track);
if (overload) { if (overload) {
handleEvent(F("POWER"),onOverloadLookup,track); onOverloadLookup->handleEvent(F("POWER"),track);
} }
} }
void RMFT2::handleEvent(const FSH* reason,LookList* handlers, int16_t id) {
int pc= handlers->find(id);
if (pc>=0) startNonRecursiveTask(reason,id,pc);
}
void RMFT2::startNonRecursiveTask(const FSH* reason, int16_t id,int pc) { void RMFT2::startNonRecursiveTask(const FSH* reason, int16_t id,int pc) {
// Check we dont already have a task running this handler // Check we dont already have a task running this handler
RMFT2 * task=loopTask; RMFT2 * task=loopTask;

View File

@ -127,6 +127,8 @@ class LookList {
int16_t findPosition(int16_t value); // finds index int16_t findPosition(int16_t value); // finds index
int16_t size(); int16_t size();
void stream(Print * _stream); void stream(Print * _stream);
void handleEvent(const FSH* reason,int16_t id);
private: private:
int16_t m_size; int16_t m_size;
int16_t m_loaded; int16_t m_loaded;
@ -166,6 +168,7 @@ class LookList {
static const FSH * getRosterFunctions(int16_t id); static const FSH * getRosterFunctions(int16_t id);
static const FSH * getTurntableDescription(int16_t id); static const FSH * getTurntableDescription(int16_t id);
static const FSH * getTurntablePositionDescription(int16_t turntableId, uint8_t positionId); static const FSH * getTurntablePositionDescription(int16_t turntableId, uint8_t positionId);
static void startNonRecursiveTask(const FSH* reason, int16_t id,int pc);
private: private:
static void ComandFilter(Print * stream, byte & opcode, byte & paramCount, int16_t p[]); static void ComandFilter(Print * stream, byte & opcode, byte & paramCount, int16_t p[]);
@ -183,9 +186,7 @@ private:
#endif #endif
static LookList* LookListLoader(OPCODE op1, static LookList* LookListLoader(OPCODE op1,
OPCODE op2=OPCODE_ENDEXRAIL,OPCODE op3=OPCODE_ENDEXRAIL); OPCODE op2=OPCODE_ENDEXRAIL,OPCODE op3=OPCODE_ENDEXRAIL);
static void handleEvent(const FSH* reason,LookList* handlers, int16_t id);
static uint16_t getOperand(int progCounter,byte n); static uint16_t getOperand(int progCounter,byte n);
static void startNonRecursiveTask(const FSH* reason, int16_t id,int pc);
static RMFT2 * loopTask; static RMFT2 * loopTask;
static RMFT2 * pausingTask; static RMFT2 * pausingTask;
void delayMe(long millisecs); void delayMe(long millisecs);

View File

@ -3,7 +3,8 @@
#include "StringFormatter.h" #include "StringFormatter.h"
#define VERSION "5.1.20" #define VERSION "5.1.21"
// 5.1.21 - EXRAIL invoke multiple ON handlers for same event
// 5.1.20 - EXRAIL Tidy and ROUTE_STATE, ROUTE_CAPTION // 5.1.20 - EXRAIL Tidy and ROUTE_STATE, ROUTE_CAPTION
// 5.1.19 - Only flag 2.2.0.0-dev as broken, not 2.2.0.0 // 5.1.19 - Only flag 2.2.0.0-dev as broken, not 2.2.0.0
// 5.1.18 - TURNOUTL bugfix // 5.1.18 - TURNOUTL bugfix