From 9ba13a62c9f53dfda3b99a4f614342e89022fa4e Mon Sep 17 00:00:00 2001 From: Asbelos Date: Sat, 4 Sep 2021 10:38:38 +0100 Subject: [PATCH] Negative sensor ids --- RMFT2.cpp | 13 +++++++++---- RMFT2.h | 6 +++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/RMFT2.cpp b/RMFT2.cpp index 2018532..bc9c01e 100644 --- a/RMFT2.cpp +++ b/RMFT2.cpp @@ -330,11 +330,16 @@ void RMFT2::driveLoco(byte speed) { speedo=speed; } -bool RMFT2::readSensor(int16_t sensorId) { - VPIN vpin=abs(sensorId); +bool RMFT2::readSensor(uint16_t sensorId) { + // Exrail operands are unsigned but we need the signed version as inserted by the macros. + int16_t sId=(int16_t) sensorId; + + VPIN vpin=abs(sId); if (getFlag(vpin,LATCH_FLAG)) return true; // latched on - bool s= IODevice::read(vpin) ^ (sensorId<0); - if (s && diag) DIAG(F("EXRAIL Sensor %d hit"),sensorId); + + // negative sensorIds invert the logic (e.g. for a break-beam sensor which goes OFF when detecting) + bool s= IODevice::read(vpin) ^ (sId<0); + if (s && diag) DIAG(F("EXRAIL Sensor %d hit"),sId); return s; } diff --git a/RMFT2.h b/RMFT2.h index bb205c3..26cdf1d 100644 --- a/RMFT2.h +++ b/RMFT2.h @@ -85,7 +85,7 @@ private: static RMFT2 * pausingTask; void delayMe(long millisecs); void driveLoco(byte speedo); - bool readSensor(int16_t sensorId); + bool readSensor(uint16_t sensorId); bool skipIfBlock(); bool readLoco(); void loop2(); @@ -106,10 +106,10 @@ private: unsigned long delayTime; byte taskId; - int16_t loco; + uint16_t loco; bool forward; bool invert; - int speedo; + byte speedo; int16_t onTurnoutId; byte stackDepth; int callStack[MAX_STACK_DEPTH];