1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-12-23 12:51:24 +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;
}
// 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;

View File

@ -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,

View File

@ -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

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 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,