Skip to content

Commit

Permalink
EXRAIL multiple ON events
Browse files Browse the repository at this point in the history
  • Loading branch information
Asbelos committed Nov 10, 2023
1 parent 670645d commit d2d7a5c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
37 changes: 19 additions & 18 deletions EXRAIL2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ int16_t LookList::find(int16_t value) {
void LookList::chain(LookList * 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) {
for (int16_t i=0;i<m_size;i++) {
Expand Down Expand Up @@ -1013,9 +1020,9 @@ int16_t RMFT2::getSignalSlot(int16_t id) {

// Schedule any event handler for this signal change.
// Thjis will work even without a signal definition.
if (rag==SIGNAL_RED) handleEvent(F("RED"),onRedLookup,id);
else if (rag==SIGNAL_GREEN) handleEvent(F("GREEN"), onGreenLookup,id);
else handleEvent(F("AMBER"), onAmberLookup,id);
if (rag==SIGNAL_RED) onRedLookup->handleEvent(F("RED"),id);
else if (rag==SIGNAL_GREEN) onGreenLookup->handleEvent(F("GREEN"),id);
else onAmberLookup->handleEvent(F("AMBER"),id);

int16_t sigslot=getSignalSlot(id);
if (sigslot<0) return;
Expand Down Expand Up @@ -1084,26 +1091,26 @@ int16_t RMFT2::getSignalSlot(int16_t id) {

void RMFT2::turnoutEvent(int16_t turnoutId, bool closed) {
// Hunt for an ONTHROW/ONCLOSE for this turnout
if (closed) handleEvent(F("CLOSE"),onCloseLookup,turnoutId);
else handleEvent(F("THROW"),onThrowLookup,turnoutId);
if (closed) onCloseLookup->handleEvent(F("CLOSE"),turnoutId);
else onThrowLookup->handleEvent(F("THROW"),turnoutId);
}


void RMFT2::activateEvent(int16_t addr, bool activate) {
// Hunt for an ONACTIVATE/ONDEACTIVATE for this accessory
if (activate) handleEvent(F("ACTIVATE"),onActivateLookup,addr);
else handleEvent(F("DEACTIVATE"),onDeactivateLookup,addr);
if (activate) onActivateLookup->handleEvent(F("ACTIVATE"),addr);
else onDeactivateLookup->handleEvent(F("DEACTIVATE"),addr);
}

void RMFT2::changeEvent(int16_t vpin, bool change) {
// 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
void RMFT2::rotateEvent(int16_t turntableId, bool change) {
// Hunt or an ONROTATE for this turntable
if (change) handleEvent(F("ROTATE"),onRotateLookup,turntableId);
if (change) onRotateLookup->handleEvent(F("ROTATE"),turntableId);
}
#endif

Expand All @@ -1112,8 +1119,8 @@ void RMFT2::clockEvent(int16_t clocktime, bool change) {
if (Diag::CMD)
DIAG(F("Looking for clock event at : %d"), clocktime);
if (change) {
handleEvent(F("CLOCK"),onClockLookup,clocktime);
handleEvent(F("CLOCK"),onClockLookup,25*60+clocktime%60);
onClockLookup->handleEvent(F("CLOCK"),clocktime);
onClockLookup->handleEvent(F("CLOCK"),25*60+clocktime%60);
}
}

Expand All @@ -1122,16 +1129,10 @@ void RMFT2::powerEvent(int16_t track, bool overload) {
if (Diag::CMD)
DIAG(F("Looking for Power event on track : %c"), track);
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) {
// Check we dont already have a task running this handler
RMFT2 * task=loopTask;
Expand Down
7 changes: 4 additions & 3 deletions EXRAIL2.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ 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);

private:
int16_t m_size;
int16_t m_loaded;
Expand Down Expand Up @@ -166,7 +168,8 @@ 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);

private:
static void ComandFilter(Print * stream, byte & opcode, byte & paramCount, int16_t p[]);
static bool parseSlash(Print * stream, byte & paramCount, int16_t p[]) ;
Expand All @@ -183,9 +186,7 @@ class LookList {
#endif
static LookList* LookListLoader(OPCODE op1,
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 void startNonRecursiveTask(const FSH* reason, int16_t id,int pc);
static RMFT2 * loopTask;
static RMFT2 * pausingTask;
void delayMe(long millisecs);
Expand Down
3 changes: 2 additions & 1 deletion version.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

#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.19 - Only flag 2.2.0.0-dev as broken, not 2.2.0.0
// 5.1.18 - TURNOUTL bugfix
Expand Down

0 comments on commit d2d7a5c

Please sign in to comment.