1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-23 08:06:13 +01:00

ELSE in EXRAIL

This commit is contained in:
Asbelos 2022-01-02 19:41:57 +00:00
parent a806af6f2f
commit 1ad4e57332
4 changed files with 14 additions and 2 deletions

View File

@ -489,6 +489,7 @@ bool RMFT2::readSensor(uint16_t sensorId) {
return s; return s;
} }
// This skips to the end of an if block, or to the ELSE within it.
bool RMFT2::skipIfBlock() { bool RMFT2::skipIfBlock() {
// returns false if killed // returns false if killed
short nest = 1; short nest = 1;
@ -512,6 +513,10 @@ bool RMFT2::skipIfBlock() {
case OPCODE_ENDIF: case OPCODE_ENDIF:
nest--; nest--;
break; 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: default:
break; break;
} }
@ -642,6 +647,10 @@ void RMFT2::loop2() {
if (!readSensor(operand)) if (!skipIfBlock()) return; if (!readSensor(operand)) if (!skipIfBlock()) return;
break; break;
case OPCODE_ELSE: // skip to matching ENDIF
if (!skipIfBlock()) return;
break;
case OPCODE_IFGTE: // do next operand if sensor>= value case OPCODE_IFGTE: // do next operand if sensor>= value
if (IODevice::readAnalogue(operand)<(int)(GET_OPERAND(1))) if (!skipIfBlock()) return; if (IODevice::readAnalogue(operand)<(int)(GET_OPERAND(1))) if (!skipIfBlock()) return;
break; break;

View File

@ -33,7 +33,7 @@ enum OPCODE : byte {OPCODE_THROW,OPCODE_CLOSE,
OPCODE_AT,OPCODE_AFTER,OPCODE_AUTOSTART, OPCODE_AT,OPCODE_AFTER,OPCODE_AUTOSTART,
OPCODE_LATCH,OPCODE_UNLATCH,OPCODE_SET,OPCODE_RESET, OPCODE_LATCH,OPCODE_UNLATCH,OPCODE_SET,OPCODE_RESET,
OPCODE_IF,OPCODE_IFNOT,OPCODE_ENDIF,OPCODE_IFRANDOM,OPCODE_IFRESERVE, 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_DELAY,OPCODE_DELAYMINS,OPCODE_RANDWAIT,
OPCODE_FON,OPCODE_FOFF,OPCODE_XFON,OPCODE_XFOFF, OPCODE_FON,OPCODE_FOFF,OPCODE_XFON,OPCODE_XFOFF,
OPCODE_RED,OPCODE_GREEN,OPCODE_AMBER,OPCODE_DRIVE, OPCODE_RED,OPCODE_GREEN,OPCODE_AMBER,OPCODE_DRIVE,

View File

@ -39,6 +39,7 @@
#undef DELAYRANDOM #undef DELAYRANDOM
#undef DONE #undef DONE
#undef DRIVE #undef DRIVE
#undef ELSE
#undef ENDEXRAIL #undef ENDEXRAIL
#undef ENDIF #undef ENDIF
#undef ENDTASK #undef ENDTASK
@ -125,6 +126,7 @@
#define DELAYRANDOM(mindelay,maxdelay) #define DELAYRANDOM(mindelay,maxdelay)
#define DONE #define DONE
#define DRIVE(analogpin) #define DRIVE(analogpin)
#define ELSE
#define ENDEXRAIL #define ENDEXRAIL
#define ENDIF #define ENDIF
#define ENDTASK #define ENDTASK

View File

@ -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 DELAYRANDOM(mindelay,maxdelay) OPCODE_DELAY,V(mindelay/100L),OPCODE_RANDWAIT,V((maxdelay-mindelay)/100L),
#define DONE OPCODE_ENDTASK,0,0, #define DONE OPCODE_ENDTASK,0,0,
#define DRIVE(analogpin) OPCODE_DRIVE,V(analogpin), #define DRIVE(analogpin) OPCODE_DRIVE,V(analogpin),
#define ELSE OPCODE_ELSE,0,0,
#define ENDEXRAIL #define ENDEXRAIL
#define ENDIF OPCODE_ENDIF,0,0, #define ENDIF OPCODE_ENDIF,0,0,
#define ENDTASK OPCODE_ENDTASK,0,0, #define ENDTASK OPCODE_ENDTASK,0,0,