From ebe8f62cf05d560a33553086a26f20af923acce1 Mon Sep 17 00:00:00 2001 From: Asbelos Date: Sat, 13 Apr 2024 10:16:26 +0100 Subject: [PATCH] ONBUTTON/ONSENSOR use latch --- EXRAIL2.cpp | 9 ++++++--- EXRAIL2.h | 5 +++-- EXRAILMacros.h | 4 ++++ EXRAILSensor.cpp | 2 +- version.h | 3 ++- 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/EXRAIL2.cpp b/EXRAIL2.cpp index adea99e..6b1b05e 100644 --- a/EXRAIL2.cpp +++ b/EXRAIL2.cpp @@ -253,11 +253,13 @@ if (compileFeatures & FEATURE_SIGNAL) { } case OPCODE_ONSENSOR: + if (compileFeatures & FEATURE_SENSOR) new EXRAILSensor(operand,progCounter+3,true ); - break; + break; case OPCODE_ONBUTTON: + if (compileFeatures & FEATURE_SENSOR) new EXRAILSensor(operand,progCounter+3,false ); - break; + break; case OPCODE_TURNOUT: { VPIN id=operand; int addr=getOperand(progCounter,1); @@ -487,7 +489,8 @@ bool RMFT2::skipIfBlock() { } void RMFT2::loop() { - EXRAILSensor::checkAll(); + if (compileFeatures & FEATURE_SENSOR) + EXRAILSensor::checkAll(); // Round Robin call to a RMFT task each time if (loopTask==NULL) return; diff --git a/EXRAIL2.h b/EXRAIL2.h index 1042d53..794eb86 100644 --- a/EXRAIL2.h +++ b/EXRAIL2.h @@ -115,6 +115,7 @@ enum BlinkState: byte { static const byte FEATURE_ROUTESTATE= 0x10; static const byte FEATURE_STASH = 0x08; static const byte FEATURE_BLINK = 0x04; + static const byte FEATURE_SENSOR = 0x02; // Flag bits for status of hardware and TPL @@ -185,7 +186,8 @@ class LookList { 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); - + static bool readSensor(uint16_t sensorId); + private: static void ComandFilter(Print * stream, byte & opcode, byte & paramCount, int16_t p[]); static bool parseSlash(Print * stream, byte & paramCount, int16_t p[]) ; @@ -208,7 +210,6 @@ private: static RMFT2 * pausingTask; void delayMe(long millisecs); void driveLoco(byte speedo); - bool readSensor(uint16_t sensorId); bool skipIfBlock(); bool readLoco(); void loop2(); diff --git a/EXRAILMacros.h b/EXRAILMacros.h index 508540a..e9e2f77 100644 --- a/EXRAILMacros.h +++ b/EXRAILMacros.h @@ -210,6 +210,10 @@ bool exrailHalSetup() { #define STASH(id) | FEATURE_STASH #undef BLINK #define BLINK(vpin,onDuty,offDuty) | FEATURE_BLINK +#undef ONBUTTON +#define ONBUTTON(vpin) | FEATURE_SENSOR +#undef ONSENSOR +#define ONSENSOR(vpin) | FEATURE_SENSOR const byte RMFT2::compileFeatures = 0 #include "myAutomation.h" diff --git a/EXRAILSensor.cpp b/EXRAILSensor.cpp index b0a5fa0..218b970 100644 --- a/EXRAILSensor.cpp +++ b/EXRAILSensor.cpp @@ -59,7 +59,7 @@ void EXRAILSensor::checkAll() { bool EXRAILSensor::check() { // check for debounced change in this sensor - inputState = IODevice::read(pin); + inputState = RMFT2::readSensor(pin); // Check if changed since last time, and process changes. if (inputState == active) {// no change diff --git a/version.h b/version.h index 395630a..0b8c1a6 100644 --- a/version.h +++ b/version.h @@ -3,7 +3,8 @@ #include "StringFormatter.h" -#define VERSION "5.2.49" +#define VERSION "5.2.50" +// 5.2.50 - EXRAIL ONBUTTON/ONSENSOR observe LATCH // 5.2.49 - EXRAIL additions: // ONBUTTON, ONSENSOR // 5.2.48 - Bugfix: HALDisplay was generating I2C traffic prior to I2C being initialised