diff --git a/RMFT2.cpp b/RMFT2.cpp index 13b2f13..ea7b7c1 100644 --- a/RMFT2.cpp +++ b/RMFT2.cpp @@ -35,6 +35,7 @@ const int16_t HASH_KEYWORD_LATCH=1618; const int16_t HASH_KEYWORD_UNLATCH=1353; const int16_t HASH_KEYWORD_PAUSE=-4142; const int16_t HASH_KEYWORD_RESUME=27609; +const int16_t HASH_KEYWORD_KILL=5218; // One instance of RMFT clas is used for each "thread" in the automation. // Each thread manages a loco on a journey through the layout, and/or may manage a scenery automation. @@ -44,7 +45,7 @@ const int16_t HASH_KEYWORD_RESUME=27609; int16_t RMFT2::progtrackLocoId; // used for callback when detecting a loco on prograck bool RMFT2::diag=false; // RMFT2 * RMFT2::loopTask=NULL; // loopTask contains the address of ONE of the tasks in a ring. -RMFT2 * RMFT2::pausingTask=NULL; // Task causing a PAUSE. +RMFT2 * RMFT2::pausingTask=NULL; // Task causing a PAUSE. // when pausingTask is set, that is the ONLY task that gets any service, // and all others will have their locos stopped, then resumed after the pausing task resumes. byte RMFT2::flags[MAX_FLAGS]; @@ -138,8 +139,8 @@ bool RMFT2::parseSlash(Print * stream, byte & paramCount, int16_t p[]) { StringFormatter::send(stream, F("<* EXRAIL STATUS")); RMFT2 * task=loopTask; while(task) { - StringFormatter::send(stream,F("\nPC=%d,DT=%l,LOCO=%d%c,SPEED=%d%c"), - task->progCounter,task->delayTime,task->loco, + StringFormatter::send(stream,F("\nID=%d,PC=%d,LOCO=%d%c,SPEED=%d%c"), + (int)(task->taskId),task->progCounter,task->loco, task->invert?'I':' ', task->speedo, task->forward?'F':'R' @@ -150,7 +151,7 @@ bool RMFT2::parseSlash(Print * stream, byte & paramCount, int16_t p[]) { // Now stream the flags for (int id=0;id=MAX_FLAGS) return false; - switch (p[0]) { + switch (p[0]) { + case HASH_KEYWORD_KILL: // Kill taskid + { + RMFT2 * task=loopTask; + while(task) { + if (task->taskId==p[1]) { + delete task; + return true; + } + task=task->next; + if (task==loopTask) break; + } + } + return false; + case HASH_KEYWORD_RESERVE: // force reserve a section setFlag(p[1],SECTION_FLAG); return true; @@ -234,6 +249,16 @@ void RMFT2::emitWithrottleRouteList(Print* stream) { RMFT2::RMFT2(int progCtr) { progCounter=progCtr; + + // get an unused task id from the flags table + taskId=255; // in case of overflow + for (int f=0;fnext) if (ring->next == this) { ring->next=next; @@ -609,9 +635,10 @@ void RMFT2::setFlag(VPIN id,byte onMask, byte offMask) { byte f=flags[id]; f &= ~offMask; f |= onMask; + flags[id]=f; } -byte RMFT2::getFlag(VPIN id,byte mask) { +bool RMFT2::getFlag(VPIN id,byte mask) { if (FLAGOVERFLOW(id)) return 0; // Outside range limit return flags[id]&mask; } diff --git a/RMFT2.h b/RMFT2.h index 90253f3..8ab26c3 100644 --- a/RMFT2.h +++ b/RMFT2.h @@ -51,6 +51,7 @@ enum OPCODE : byte {OPCODE_THROW,OPCODE_CLOSE, // Flag bits for status of hardware and TPL static const byte SECTION_FLAG = 0x01; static const byte LATCH_FLAG = 0x02; + static const byte TASK_FLAG = 0x04; static const byte MAX_STACK_DEPTH=4; @@ -73,7 +74,7 @@ private: static bool parseSlash(Print * stream, byte & paramCount, int p[]) ; static void streamFlags(Print* stream); static void setFlag(VPIN id,byte onMask, byte OffMask=0); - static byte getFlag(VPIN id,byte mask); + static bool getFlag(VPIN id,byte mask); static int locateRouteStart(int16_t _route); static int progtrackLocoId; static void doSignal(VPIN id,bool red, bool amber, bool green); @@ -85,9 +86,6 @@ private: bool readSensor(int16_t sensorId); bool skipIfBlock(); bool readLoco(); - void showManual(); - void showProg(bool progOn); - bool doManual(); void loop2(); void kill(const FSH * reason=NULL,int operand=0); void printMessage(uint16_t id); // Built by RMFTMacros.h @@ -98,12 +96,14 @@ private: static const FLASH char RouteDescription[]; static byte flags[MAX_FLAGS]; - // Local variables - exist for each instance/task + // Local variables - exist for each instance/task RMFT2 *next; // loop chain int progCounter; // Byte offset of next route opcode in ROUTES table unsigned long delayStart; // Used by opcodes that must be recalled before completing unsigned long waitAfter; // Used by OPCODE_AFTER unsigned long delayTime; + byte taskId; + int loco; bool forward; bool invert;