From 1ad4e5733240262a80e47828d51254a0b261fb71 Mon Sep 17 00:00:00 2001 From: Asbelos Date: Sun, 2 Jan 2022 19:41:57 +0000 Subject: [PATCH] ELSE in EXRAIL --- RMFT2.cpp | 11 ++++++++++- RMFT2.h | 2 +- RMFT2MacroReset.h | 2 ++ RMFTMacros.h | 1 + 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/RMFT2.cpp b/RMFT2.cpp index 08a5697..8ca2e2f 100644 --- a/RMFT2.cpp +++ b/RMFT2.cpp @@ -489,6 +489,7 @@ bool RMFT2::readSensor(uint16_t sensorId) { return s; } +// This skips to the end of an if block, or to the ELSE within it. bool RMFT2::skipIfBlock() { // returns false if killed short nest = 1; @@ -512,10 +513,14 @@ bool RMFT2::skipIfBlock() { case OPCODE_ENDIF: nest--; break; + case OPCODE_ELSE: + // if nest==1 then this is the ELSE for the IF we are skipping + if (nest==1) nest=0; // cause loop exit and return after ELSE + break; default: break; } - } + } return true; } @@ -641,6 +646,10 @@ void RMFT2::loop2() { case OPCODE_IF: // do next operand if sensor set if (!readSensor(operand)) if (!skipIfBlock()) return; break; + + case OPCODE_ELSE: // skip to matching ENDIF + if (!skipIfBlock()) return; + break; case OPCODE_IFGTE: // do next operand if sensor>= value if (IODevice::readAnalogue(operand)<(int)(GET_OPERAND(1))) if (!skipIfBlock()) return; diff --git a/RMFT2.h b/RMFT2.h index d961054..0ebbc02 100644 --- a/RMFT2.h +++ b/RMFT2.h @@ -33,7 +33,7 @@ enum OPCODE : byte {OPCODE_THROW,OPCODE_CLOSE, OPCODE_AT,OPCODE_AFTER,OPCODE_AUTOSTART, OPCODE_LATCH,OPCODE_UNLATCH,OPCODE_SET,OPCODE_RESET, OPCODE_IF,OPCODE_IFNOT,OPCODE_ENDIF,OPCODE_IFRANDOM,OPCODE_IFRESERVE, - OPCODE_IFCLOSED, OPCODE_IFTHROWN, + OPCODE_IFCLOSED, OPCODE_IFTHROWN,OPCODE_ELSE, OPCODE_DELAY,OPCODE_DELAYMINS,OPCODE_RANDWAIT, OPCODE_FON,OPCODE_FOFF,OPCODE_XFON,OPCODE_XFOFF, OPCODE_RED,OPCODE_GREEN,OPCODE_AMBER,OPCODE_DRIVE, diff --git a/RMFT2MacroReset.h b/RMFT2MacroReset.h index c95fc43..cf31dcf 100644 --- a/RMFT2MacroReset.h +++ b/RMFT2MacroReset.h @@ -39,6 +39,7 @@ #undef DELAYRANDOM #undef DONE #undef DRIVE +#undef ELSE #undef ENDEXRAIL #undef ENDIF #undef ENDTASK @@ -125,6 +126,7 @@ #define DELAYRANDOM(mindelay,maxdelay) #define DONE #define DRIVE(analogpin) +#define ELSE #define ENDEXRAIL #define ENDIF #define ENDTASK diff --git a/RMFTMacros.h b/RMFTMacros.h index e0151aa..cd0e4cf 100644 --- a/RMFTMacros.h +++ b/RMFTMacros.h @@ -168,6 +168,7 @@ const FSH * RMFT2::getRosterFunctions(int16_t cabid) { #define DELAYRANDOM(mindelay,maxdelay) OPCODE_DELAY,V(mindelay/100L),OPCODE_RANDWAIT,V((maxdelay-mindelay)/100L), #define DONE OPCODE_ENDTASK,0,0, #define DRIVE(analogpin) OPCODE_DRIVE,V(analogpin), +#define ELSE OPCODE_ELSE,0,0, #define ENDEXRAIL #define ENDIF OPCODE_ENDIF,0,0, #define ENDTASK OPCODE_ENDTASK,0,0,