mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-27 01:56:14 +01:00
Compare commits
6 Commits
4036bd79f1
...
73b434b9a6
Author | SHA1 | Date | |
---|---|---|---|
|
73b434b9a6 | ||
|
3af2f67792 | ||
|
c382bd33bc | ||
|
ebe8f62cf0 | ||
|
7dafe0383d | ||
|
4aa97e1731 |
51
EXRAIL2.cpp
51
EXRAIL2.cpp
|
@ -54,6 +54,7 @@
|
||||||
#include "TrackManager.h"
|
#include "TrackManager.h"
|
||||||
#include "Turntables.h"
|
#include "Turntables.h"
|
||||||
#include "IODevice.h"
|
#include "IODevice.h"
|
||||||
|
#include "EXRAILSensor.h"
|
||||||
|
|
||||||
|
|
||||||
// One instance of RMFT clas is used for each "thread" in the automation.
|
// One instance of RMFT clas is used for each "thread" in the automation.
|
||||||
|
@ -204,15 +205,16 @@ LookList* RMFT2::LookListLoader(OPCODE op1, OPCODE op2, OPCODE op3) {
|
||||||
|
|
||||||
// Second pass startup, define any turnouts or servos, set signals red
|
// Second pass startup, define any turnouts or servos, set signals red
|
||||||
// add sequences onRoutines to the lookups
|
// add sequences onRoutines to the lookups
|
||||||
if (compileFeatures & FEATURE_SIGNAL) {
|
if (compileFeatures & FEATURE_SIGNAL) {
|
||||||
onRedLookup=LookListLoader(OPCODE_ONRED);
|
onRedLookup=LookListLoader(OPCODE_ONRED);
|
||||||
onAmberLookup=LookListLoader(OPCODE_ONAMBER);
|
onAmberLookup=LookListLoader(OPCODE_ONAMBER);
|
||||||
onGreenLookup=LookListLoader(OPCODE_ONGREEN);
|
onGreenLookup=LookListLoader(OPCODE_ONGREEN);
|
||||||
for (int sigslot=0;;sigslot++) {
|
for (int sigslot=0;;sigslot++) {
|
||||||
VPIN sigid=GETHIGHFLASHW(RMFT2::SignalDefinitions,sigslot*8);
|
int16_t sighandle=GETHIGHFLASHW(RMFT2::SignalDefinitions,sigslot*8);
|
||||||
if (sigid==0) break; // end of signal list
|
if (sighandle==0) break; // end of signal list
|
||||||
doSignal(sigid & SIGNAL_ID_MASK, SIGNAL_RED);
|
VPIN sigid = sighandle & SIGNAL_ID_MASK;
|
||||||
}
|
doSignal(sigid, SIGNAL_RED);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int progCounter;
|
int progCounter;
|
||||||
|
@ -251,6 +253,14 @@ if (compileFeatures & FEATURE_SIGNAL) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case OPCODE_ONSENSOR:
|
||||||
|
if (compileFeatures & FEATURE_SENSOR)
|
||||||
|
new EXRAILSensor(operand,progCounter+3,true );
|
||||||
|
break;
|
||||||
|
case OPCODE_ONBUTTON:
|
||||||
|
if (compileFeatures & FEATURE_SENSOR)
|
||||||
|
new EXRAILSensor(operand,progCounter+3,false );
|
||||||
|
break;
|
||||||
case OPCODE_TURNOUT: {
|
case OPCODE_TURNOUT: {
|
||||||
VPIN id=operand;
|
VPIN id=operand;
|
||||||
int addr=getOperand(progCounter,1);
|
int addr=getOperand(progCounter,1);
|
||||||
|
@ -480,6 +490,8 @@ bool RMFT2::skipIfBlock() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void RMFT2::loop() {
|
void RMFT2::loop() {
|
||||||
|
if (compileFeatures & FEATURE_SENSOR)
|
||||||
|
EXRAILSensor::checkAll();
|
||||||
|
|
||||||
// Round Robin call to a RMFT task each time
|
// Round Robin call to a RMFT task each time
|
||||||
if (loopTask==NULL) return;
|
if (loopTask==NULL) return;
|
||||||
|
@ -1084,6 +1096,8 @@ void RMFT2::loop2() {
|
||||||
case OPCODE_ONGREEN:
|
case OPCODE_ONGREEN:
|
||||||
case OPCODE_ONCHANGE:
|
case OPCODE_ONCHANGE:
|
||||||
case OPCODE_ONTIME:
|
case OPCODE_ONTIME:
|
||||||
|
case OPCODE_ONBUTTON:
|
||||||
|
case OPCODE_ONSENSOR:
|
||||||
#ifndef IO_NO_HAL
|
#ifndef IO_NO_HAL
|
||||||
case OPCODE_DCCTURNTABLE: // Turntable definition ignored at runtime
|
case OPCODE_DCCTURNTABLE: // Turntable definition ignored at runtime
|
||||||
case OPCODE_EXTTTURNTABLE: // Turntable definition ignored at runtime
|
case OPCODE_EXTTTURNTABLE: // Turntable definition ignored at runtime
|
||||||
|
@ -1130,16 +1144,17 @@ void RMFT2::kill(const FSH * reason, int operand) {
|
||||||
|
|
||||||
int16_t RMFT2::getSignalSlot(int16_t id) {
|
int16_t RMFT2::getSignalSlot(int16_t id) {
|
||||||
for (int sigslot=0;;sigslot++) {
|
for (int sigslot=0;;sigslot++) {
|
||||||
int16_t sigid=GETHIGHFLASHW(RMFT2::SignalDefinitions,sigslot*8);
|
int16_t sighandle=GETHIGHFLASHW(RMFT2::SignalDefinitions,sigslot*8);
|
||||||
if (sigid==0) { // end of signal list
|
if (sighandle==0) { // end of signal list
|
||||||
DIAG(F("EXRAIL Signal %d not defined"), id);
|
DIAG(F("EXRAIL Signal %d not defined"), id);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
VPIN sigid = sighandle & SIGNAL_ID_MASK;
|
||||||
// sigid is the signal id used in RED/AMBER/GREEN macro
|
// sigid is the signal id used in RED/AMBER/GREEN macro
|
||||||
// for a LED signal it will be same as redpin
|
// for a LED signal it will be same as redpin
|
||||||
// but for a servo signal it will also have SERVO_SIGNAL_FLAG set.
|
// but for a servo signal it will also have SERVO_SIGNAL_FLAG set.
|
||||||
|
|
||||||
if ((sigid & SIGNAL_ID_MASK)!= id) continue; // keep looking
|
if (sigid != id) continue; // keep looking
|
||||||
return sigslot; // relative slot in signals table
|
return sigslot; // relative slot in signals table
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1162,13 +1177,14 @@ int16_t RMFT2::getSignalSlot(int16_t id) {
|
||||||
|
|
||||||
// Correct signal definition found, get the rag values
|
// Correct signal definition found, get the rag values
|
||||||
int16_t sigpos=sigslot*8;
|
int16_t sigpos=sigslot*8;
|
||||||
VPIN sigid=GETHIGHFLASHW(RMFT2::SignalDefinitions,sigpos);
|
int16_t sighandle=GETHIGHFLASHW(RMFT2::SignalDefinitions,sigpos);
|
||||||
VPIN redpin=GETHIGHFLASHW(RMFT2::SignalDefinitions,sigpos+2);
|
VPIN redpin=GETHIGHFLASHW(RMFT2::SignalDefinitions,sigpos+2);
|
||||||
VPIN amberpin=GETHIGHFLASHW(RMFT2::SignalDefinitions,sigpos+4);
|
VPIN amberpin=GETHIGHFLASHW(RMFT2::SignalDefinitions,sigpos+4);
|
||||||
VPIN greenpin=GETHIGHFLASHW(RMFT2::SignalDefinitions,sigpos+6);
|
VPIN greenpin=GETHIGHFLASHW(RMFT2::SignalDefinitions,sigpos+6);
|
||||||
//if (diag) DIAG(F("signal %d %d %d %d %d"),sigid,id,redpin,amberpin,greenpin);
|
//if (diag) DIAG(F("signal %d %d %d %d %d"),sigid,id,redpin,amberpin,greenpin);
|
||||||
|
|
||||||
VPIN sigtype=sigid & ~SIGNAL_ID_MASK;
|
VPIN sigtype=sighandle & ~SIGNAL_ID_MASK;
|
||||||
|
VPIN sigid = sighandle & SIGNAL_ID_MASK;
|
||||||
|
|
||||||
if (sigtype == SERVO_SIGNAL_FLAG) {
|
if (sigtype == SERVO_SIGNAL_FLAG) {
|
||||||
// A servo signal, the pin numbers are actually servo positions
|
// A servo signal, the pin numbers are actually servo positions
|
||||||
|
@ -1191,7 +1207,7 @@ int16_t RMFT2::getSignalSlot(int16_t id) {
|
||||||
byte value=redpin;
|
byte value=redpin;
|
||||||
if (rag==SIGNAL_AMBER) value=amberpin;
|
if (rag==SIGNAL_AMBER) value=amberpin;
|
||||||
if (rag==SIGNAL_GREEN) value=greenpin;
|
if (rag==SIGNAL_GREEN) value=greenpin;
|
||||||
DCC::setExtendedAccessory(sigid & SIGNAL_ID_MASK,value);
|
DCC::setExtendedAccessory(sigid, value);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1242,8 +1258,9 @@ bool RMFT2::signalAspectEvent(int16_t address, byte aspect ) {
|
||||||
int16_t sigslot=getSignalSlot(address);
|
int16_t sigslot=getSignalSlot(address);
|
||||||
if (sigslot<0) return false; // this is not a defined signal
|
if (sigslot<0) return false; // this is not a defined signal
|
||||||
int16_t sigpos=sigslot*8;
|
int16_t sigpos=sigslot*8;
|
||||||
VPIN sigid=GETHIGHFLASHW(RMFT2::SignalDefinitions,sigpos);
|
int16_t sighandle=GETHIGHFLASHW(RMFT2::SignalDefinitions,sigpos);
|
||||||
VPIN sigtype=sigid & ~SIGNAL_ID_MASK;
|
VPIN sigtype=sighandle & ~SIGNAL_ID_MASK;
|
||||||
|
VPIN sigid = sighandle & SIGNAL_ID_MASK;
|
||||||
if (sigtype!=DCCX_SIGNAL_FLAG) return false; // not a DCCX signal
|
if (sigtype!=DCCX_SIGNAL_FLAG) return false; // not a DCCX signal
|
||||||
// Turn an aspect change into a RED/AMBER/GREEN setting
|
// Turn an aspect change into a RED/AMBER/GREEN setting
|
||||||
if (aspect==GETHIGHFLASHW(RMFT2::SignalDefinitions,sigpos+2)) {
|
if (aspect==GETHIGHFLASHW(RMFT2::SignalDefinitions,sigpos+2)) {
|
||||||
|
|
|
@ -73,7 +73,7 @@ enum OPCODE : byte {OPCODE_THROW,OPCODE_CLOSE,OPCODE_TOGGLE_TURNOUT,
|
||||||
OPCODE_ROUTE_ACTIVE,OPCODE_ROUTE_INACTIVE,OPCODE_ROUTE_HIDDEN,
|
OPCODE_ROUTE_ACTIVE,OPCODE_ROUTE_INACTIVE,OPCODE_ROUTE_HIDDEN,
|
||||||
OPCODE_ROUTE_DISABLED,
|
OPCODE_ROUTE_DISABLED,
|
||||||
OPCODE_STASH,OPCODE_CLEAR_STASH,OPCODE_CLEAR_ALL_STASH,OPCODE_PICKUP_STASH,
|
OPCODE_STASH,OPCODE_CLEAR_STASH,OPCODE_CLEAR_ALL_STASH,OPCODE_PICKUP_STASH,
|
||||||
|
OPCODE_ONBUTTON,OPCODE_ONSENSOR,
|
||||||
// OPcodes below this point are skip-nesting IF operations
|
// OPcodes below this point are skip-nesting IF operations
|
||||||
// placed here so that they may be skipped as a group
|
// placed here so that they may be skipped as a group
|
||||||
// see skipIfBlock()
|
// see skipIfBlock()
|
||||||
|
@ -115,6 +115,7 @@ enum BlinkState: byte {
|
||||||
static const byte FEATURE_ROUTESTATE= 0x10;
|
static const byte FEATURE_ROUTESTATE= 0x10;
|
||||||
static const byte FEATURE_STASH = 0x08;
|
static const byte FEATURE_STASH = 0x08;
|
||||||
static const byte FEATURE_BLINK = 0x04;
|
static const byte FEATURE_BLINK = 0x04;
|
||||||
|
static const byte FEATURE_SENSOR = 0x02;
|
||||||
|
|
||||||
|
|
||||||
// Flag bits for status of hardware and TPL
|
// Flag bits for status of hardware and TPL
|
||||||
|
@ -185,7 +186,8 @@ class LookList {
|
||||||
static const FSH * getTurntableDescription(int16_t id);
|
static const FSH * getTurntableDescription(int16_t id);
|
||||||
static const FSH * getTurntablePositionDescription(int16_t turntableId, uint8_t positionId);
|
static const FSH * getTurntablePositionDescription(int16_t turntableId, uint8_t positionId);
|
||||||
static void startNonRecursiveTask(const FSH* reason, int16_t id,int pc);
|
static void startNonRecursiveTask(const FSH* reason, int16_t id,int pc);
|
||||||
|
static bool readSensor(uint16_t sensorId);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void ComandFilter(Print * stream, byte & opcode, byte & paramCount, int16_t p[]);
|
static void ComandFilter(Print * stream, byte & opcode, byte & paramCount, int16_t p[]);
|
||||||
static bool parseSlash(Print * stream, byte & paramCount, int16_t p[]) ;
|
static bool parseSlash(Print * stream, byte & paramCount, int16_t p[]) ;
|
||||||
|
@ -208,7 +210,6 @@ private:
|
||||||
static RMFT2 * pausingTask;
|
static RMFT2 * pausingTask;
|
||||||
void delayMe(long millisecs);
|
void delayMe(long millisecs);
|
||||||
void driveLoco(byte speedo);
|
void driveLoco(byte speedo);
|
||||||
bool readSensor(uint16_t sensorId);
|
|
||||||
bool skipIfBlock();
|
bool skipIfBlock();
|
||||||
bool readLoco();
|
bool readLoco();
|
||||||
void loop2();
|
void loop2();
|
||||||
|
|
|
@ -114,6 +114,8 @@
|
||||||
#undef ONGREEN
|
#undef ONGREEN
|
||||||
#undef ONRED
|
#undef ONRED
|
||||||
#undef ONROTATE
|
#undef ONROTATE
|
||||||
|
#undef ONBUTTON
|
||||||
|
#undef ONSENSOR
|
||||||
#undef ONTHROW
|
#undef ONTHROW
|
||||||
#undef ONCHANGE
|
#undef ONCHANGE
|
||||||
#undef PARSE
|
#undef PARSE
|
||||||
|
@ -279,6 +281,8 @@
|
||||||
#define ONROTATE(turntable_id)
|
#define ONROTATE(turntable_id)
|
||||||
#define ONTHROW(turnout_id)
|
#define ONTHROW(turnout_id)
|
||||||
#define ONCHANGE(sensor_id)
|
#define ONCHANGE(sensor_id)
|
||||||
|
#define ONSENSOR(sensor_id)
|
||||||
|
#define ONBUTTON(sensor_id)
|
||||||
#define PAUSE
|
#define PAUSE
|
||||||
#define PIN_TURNOUT(id,pin,description...)
|
#define PIN_TURNOUT(id,pin,description...)
|
||||||
#define PRINT(msg)
|
#define PRINT(msg)
|
||||||
|
|
|
@ -214,12 +214,13 @@ bool RMFT2::parseSlash(Print * stream, byte & paramCount, int16_t p[]) {
|
||||||
// do the signals
|
// do the signals
|
||||||
// flags[n] represents the state of the nth signal in the table
|
// flags[n] represents the state of the nth signal in the table
|
||||||
for (int sigslot=0;;sigslot++) {
|
for (int sigslot=0;;sigslot++) {
|
||||||
VPIN sigid=GETHIGHFLASHW(RMFT2::SignalDefinitions,sigslot*8);
|
int16_t sighandle=GETHIGHFLASHW(RMFT2::SignalDefinitions,sigslot*8);
|
||||||
if (sigid==0) break; // end of signal list
|
if (sighandle==0) break; // end of signal list
|
||||||
byte flag=flags[sigslot] & SIGNAL_MASK; // obtain signal flags for this id
|
VPIN sigid = sighandle & SIGNAL_ID_MASK;
|
||||||
|
byte flag=flags[sigslot] & SIGNAL_MASK; // obtain signal flags for this id
|
||||||
StringFormatter::send(stream,F("\n%S[%d]"),
|
StringFormatter::send(stream,F("\n%S[%d]"),
|
||||||
(flag == SIGNAL_RED)? F("RED") : (flag==SIGNAL_GREEN) ? F("GREEN") : F("AMBER"),
|
(flag == SIGNAL_RED)? F("RED") : (flag==SIGNAL_GREEN) ? F("GREEN") : F("AMBER"),
|
||||||
sigid & SIGNAL_ID_MASK);
|
sigid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -210,6 +210,10 @@ bool exrailHalSetup() {
|
||||||
#define STASH(id) | FEATURE_STASH
|
#define STASH(id) | FEATURE_STASH
|
||||||
#undef BLINK
|
#undef BLINK
|
||||||
#define BLINK(vpin,onDuty,offDuty) | FEATURE_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
|
const byte RMFT2::compileFeatures = 0
|
||||||
#include "myAutomation.h"
|
#include "myAutomation.h"
|
||||||
|
@ -553,6 +557,8 @@ int RMFT2::onLCCLookup[RMFT2::countLCCLookup];
|
||||||
#endif
|
#endif
|
||||||
#define ONTHROW(turnout_id) OPCODE_ONTHROW,V(turnout_id),
|
#define ONTHROW(turnout_id) OPCODE_ONTHROW,V(turnout_id),
|
||||||
#define ONCHANGE(sensor_id) OPCODE_ONCHANGE,V(sensor_id),
|
#define ONCHANGE(sensor_id) OPCODE_ONCHANGE,V(sensor_id),
|
||||||
|
#define ONSENSOR(sensor_id) OPCODE_ONSENSOR,V(sensor_id),
|
||||||
|
#define ONBUTTON(sensor_id) OPCODE_ONBUTTON,V(sensor_id),
|
||||||
#define PAUSE OPCODE_PAUSE,0,0,
|
#define PAUSE OPCODE_PAUSE,0,0,
|
||||||
#define PICKUP_STASH(id) OPCODE_PICKUP_STASH,V(id),
|
#define PICKUP_STASH(id) OPCODE_PICKUP_STASH,V(id),
|
||||||
#define PIN_TURNOUT(id,pin,description...) OPCODE_PINTURNOUT,V(id),OPCODE_PAD,V(pin),
|
#define PIN_TURNOUT(id,pin,description...) OPCODE_PINTURNOUT,V(id),OPCODE_PAD,V(pin),
|
||||||
|
|
104
EXRAILSensor.cpp
Normal file
104
EXRAILSensor.cpp
Normal file
|
@ -0,0 +1,104 @@
|
||||||
|
/*
|
||||||
|
* © 2024 Chris Harlow
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This file is part of CommandStation-EX
|
||||||
|
*
|
||||||
|
* This is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* It is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with CommandStation. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**********************************************************************
|
||||||
|
EXRAILSensor represents a sensor that should be monitored in order
|
||||||
|
to call an exrail ONBUTTON or ONCHANGE handler.
|
||||||
|
These are created at EXRAIL startup and thus need no delete or listing
|
||||||
|
capability.
|
||||||
|
The basic logic is similar to that found in the Sensor class
|
||||||
|
except that on the relevant change an EXRAIL thread is started.
|
||||||
|
**********************************************************************/
|
||||||
|
|
||||||
|
#include "EXRAILSensor.h"
|
||||||
|
#include "EXRAIL2.h"
|
||||||
|
|
||||||
|
void EXRAILSensor::checkAll() {
|
||||||
|
if (firstSensor == NULL) return; // No sensors to be scanned
|
||||||
|
if (readingSensor == NULL) {
|
||||||
|
// Not currently scanning sensor list
|
||||||
|
unsigned long thisTime = micros();
|
||||||
|
if (thisTime - lastReadCycle < cycleInterval) return;
|
||||||
|
// Required time has elapsed since last read cycle started,
|
||||||
|
// so initiate new scan through the sensor list
|
||||||
|
readingSensor = firstSensor;
|
||||||
|
lastReadCycle = thisTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loop until either end of list is encountered or we pause for some reason
|
||||||
|
byte sensorCount = 0;
|
||||||
|
|
||||||
|
while (readingSensor != NULL) {
|
||||||
|
bool pause=readingSensor->check();
|
||||||
|
// Move to next sensor in list.
|
||||||
|
readingSensor = readingSensor->nextSensor;
|
||||||
|
// Currently process max of 16 sensors per entry.
|
||||||
|
// Performance measurements taken during development indicate that, with 128 sensors configured
|
||||||
|
// on 8x 16-pin MCP23017 GPIO expanders with polling (no change notification), all inputs can be read from the devices
|
||||||
|
// within 1.4ms (400Mhz I2C bus speed), and a full cycle of checking 128 sensors for changes takes under a millisecond.
|
||||||
|
if (pause || (++sensorCount)>=16) return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool EXRAILSensor::check() {
|
||||||
|
// check for debounced change in this sensor
|
||||||
|
inputState = RMFT2::readSensor(pin);
|
||||||
|
|
||||||
|
// Check if changed since last time, and process changes.
|
||||||
|
if (inputState == active) {// no change
|
||||||
|
latchDelay = minReadCount; // Reset counter
|
||||||
|
return false; // no change
|
||||||
|
}
|
||||||
|
|
||||||
|
// Change detected ... has it stayed changed for long enough
|
||||||
|
if (latchDelay > 0) {
|
||||||
|
latchDelay--;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// change validated, act on it.
|
||||||
|
active = inputState;
|
||||||
|
latchDelay = minReadCount; // Reset debounce counter
|
||||||
|
if (onChange || active) {
|
||||||
|
new RMFT2(progCounter);
|
||||||
|
return true; // Don't check any more sensors on this entry
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
EXRAILSensor::EXRAILSensor(VPIN _pin, int _progCounter, bool _onChange) {
|
||||||
|
// Add to the start of the list
|
||||||
|
//DIAG(F("ONthing vpin=%d at %d"), _pin, _progCounter);
|
||||||
|
nextSensor = firstSensor;
|
||||||
|
firstSensor = this;
|
||||||
|
|
||||||
|
pin=_pin;
|
||||||
|
progCounter=_progCounter;
|
||||||
|
onChange=_onChange;
|
||||||
|
|
||||||
|
IODevice::configureInput(pin, true);
|
||||||
|
active = IODevice::read(pin);
|
||||||
|
inputState = active;
|
||||||
|
latchDelay = minReadCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
EXRAILSensor *EXRAILSensor::firstSensor=NULL;
|
||||||
|
EXRAILSensor *EXRAILSensor::readingSensor=NULL;
|
||||||
|
unsigned long EXRAILSensor::lastReadCycle=0;
|
50
EXRAILSensor.h
Normal file
50
EXRAILSensor.h
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
/*
|
||||||
|
* © 2024 Chris Harlow
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This file is part of CommandStation-EX
|
||||||
|
*
|
||||||
|
* This is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* It is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with CommandStation. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef EXRAILSensor_h
|
||||||
|
#define EXRAILSensor_h
|
||||||
|
#include "IODevice.h"
|
||||||
|
class EXRAILSensor {
|
||||||
|
static EXRAILSensor * firstSensor;
|
||||||
|
static EXRAILSensor * readingSensor;
|
||||||
|
static unsigned long lastReadCycle;
|
||||||
|
|
||||||
|
public:
|
||||||
|
static void checkAll();
|
||||||
|
|
||||||
|
EXRAILSensor(VPIN _pin, int _progCounter, bool _onChange);
|
||||||
|
bool check();
|
||||||
|
|
||||||
|
private:
|
||||||
|
static const unsigned int cycleInterval = 10000; // min time between consecutive reads of each sensor in microsecs.
|
||||||
|
// should not be less than device scan cycle time.
|
||||||
|
static const byte minReadCount = 4; // number of additional scans before acting on change
|
||||||
|
// E.g. 1 means that a change is ignored for one scan and actioned on the next.
|
||||||
|
// Max value is 63
|
||||||
|
|
||||||
|
EXRAILSensor* nextSensor;
|
||||||
|
VPIN pin;
|
||||||
|
int progCounter;
|
||||||
|
bool active;
|
||||||
|
bool inputState;
|
||||||
|
bool onChange;
|
||||||
|
byte latchDelay;
|
||||||
|
};
|
||||||
|
#endif
|
|
@ -1 +1 @@
|
||||||
#define GITHUB_SHA "devel-202404061747Z"
|
#define GITHUB_SHA "devel-202404211704Z"
|
||||||
|
|
|
@ -1,3 +1,24 @@
|
||||||
|
// 5.2.49
|
||||||
|
|
||||||
|
Which is a more efficient than the AT/AFTER/IF methods
|
||||||
|
of handling buttons and switches, especially on MIMIC panels.
|
||||||
|
|
||||||
|
ONBUTTON(vpin)
|
||||||
|
handles debounce and starts a task if a button is used to
|
||||||
|
short a pin to ground.
|
||||||
|
|
||||||
|
for example:
|
||||||
|
ONBUTTON(30) TOGGLE_TURNOUT(30) DONE
|
||||||
|
|
||||||
|
ONSENSOR(vpin)
|
||||||
|
handles debounce and starts a task if the pin changes.
|
||||||
|
You may want to check the pin state with an IF ...
|
||||||
|
|
||||||
|
Note the ONBUTTON and ONSENSOR are not generally useful
|
||||||
|
for track sensors and running trains, because you dont know which
|
||||||
|
train triggered the sensor.
|
||||||
|
|
||||||
|
// 5.2.47
|
||||||
|
|
||||||
BLINK(vpin, onMs,offMs)
|
BLINK(vpin, onMs,offMs)
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,11 @@
|
||||||
|
|
||||||
#include "StringFormatter.h"
|
#include "StringFormatter.h"
|
||||||
|
|
||||||
#define VERSION "5.2.48"
|
#define VERSION "5.2.51"
|
||||||
|
// 5.2.51 - Bugfix for SIGNAL: Distinguish between sighandle and sigid
|
||||||
|
// 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
|
// 5.2.48 - Bugfix: HALDisplay was generating I2C traffic prior to I2C being initialised
|
||||||
// 5.2.47 - EXRAIL additions:
|
// 5.2.47 - EXRAIL additions:
|
||||||
// STEALTH_GLOBAL
|
// STEALTH_GLOBAL
|
||||||
|
|
Loading…
Reference in New Issue
Block a user