1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2025-01-11 13:21:01 +01:00

Negative sensor ids

This commit is contained in:
Asbelos 2021-09-04 10:38:38 +01:00
parent 99222bd37f
commit 9ba13a62c9
2 changed files with 12 additions and 7 deletions

View File

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

View File

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