1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2025-07-28 09:53:45 +02:00

JMRI_SENSOR_NOPULLUP

and associated dump for <S>
This commit is contained in:
Asbelos
2025-07-25 09:29:57 +01:00
parent d84e354142
commit c699eb3492
7 changed files with 68 additions and 28 deletions

View File

@@ -1135,12 +1135,7 @@ bool DCCEXParser::parseS(Print *stream, int16_t params, int16_t p[])
return true;
case 0: // <S> list sensor definitions
if (Sensor::firstSensor == NULL)
return false;
for (Sensor *tt = Sensor::firstSensor; tt != NULL; tt = tt->nextSensor)
{
StringFormatter::send(stream, F("<Q %d %d %d>\n"), tt->data.snum, tt->data.pin, tt->data.pullUp);
}
Sensor::dumpAll(stream);
return true;
default: // invalid number of arguments

View File

@@ -98,6 +98,7 @@
#undef IFBITMAP_ANY
#undef INVERT_DIRECTION
#undef JMRI_SENSOR
#undef JMRI_SENSOR_NOPULLUP
#undef JOIN
#undef KILLALL
#undef LATCH
@@ -684,11 +685,18 @@
#define INVERT_DIRECTION
/**
* @def JMRI_SENSOR(vpin,count...)
* @brief Defines multiple JMRI <s> type sensor feedback definitions each with id matching vpin
* @brief Defines multiple JMRI <s> type sensor feedback definitions each with id matching vpin and INPUT_PULLUP
* @param vpin first vpin number
* @param count... Number of consecutine VPINS for which to create JMRI sensor feedbacks. Default 1.
*/
#define JMRI_SENSOR(vpin,count...)
/**
* @def JMRI_SENSOR_NOPULLUP(vpin,count...)
* @brief Defines multiple JMRI <s> type sensor feedback definitions each with id matching vpin
* @param vpin first vpin number
* @param count... Number of consecutine VPINS for which to create JMRI sensor feedbacks. Default 1.
*/
#define JMRI_SENSOR_NOPULLUP(vpin,count...)
/**
* @def JOIN
* @brief Switches PROG track to receive MAIN track DCC packets. (Drive on PROG track)

View File

@@ -117,12 +117,19 @@ bool exrailHalSetup1() {
{ \
const int npins=#count[0]? count+0:1; \
static byte state_map[(npins+7)/8]; \
SensorGroup::doSensorGroup(vpin,npins,state_map,action,&USB_SERIAL); \
SensorGroup::doSensorGroup(vpin,npins,state_map,action,&USB_SERIAL,true); \
}
#undef JMRI_SENSOR_NOPULLUP
#define JMRI_SENSOR_NOPULLUP(vpin,count...) \
{ \
const int npins=#count[0]? count+0:1; \
static byte state_map[(npins+7)/8]; \
SensorGroup::doSensorGroup(vpin,npins,state_map,action,&USB_SERIAL,false); \
}
void SensorGroup::doExrailSensorGroup(GroupProcess action, Print * stream) {
(void) action; // suppress unused warning
(void) stream; // suppress unused warning
(void) action; // suppress unused warnings if no groups
(void) stream;
#include "myAutomation.h"
}
@@ -135,7 +142,7 @@ void SensorGroup::doExrailSensorGroup(GroupProcess action, Print * stream) {
void exrailHalSetup2() {
#include "myAutomation.h"
// pullup any group sensors
SensorGroup::pullupAll();
SensorGroup::prepareAll();
}
// Pass 1c detect compile time featurtes
@@ -513,6 +520,7 @@ int RMFT2::onLCCLookup[RMFT2::countLCCLookup];
#define IFBITMAP_ANY(vpin,mask) OPCODE_IFBITMAP_ANY,V(vpin),OPCODE_PAD,V(mask),
#define INVERT_DIRECTION OPCODE_INVERT_DIRECTION,0,0,
#define JMRI_SENSOR(vpin,count...)
#define JMRI_SENSOR_NOPULLUP(vpin,count...)
#define JOIN OPCODE_JOIN,0,0,
#define KILLALL OPCODE_KILLALL,0,0,
#define LATCH(sensor_id) OPCODE_LATCH,V(sensor_id),

View File

@@ -1,29 +1,36 @@
#include "SensorGroup.h"
#ifdef EXRAIL_ACTIVE
// called in loop to check sensors
void SensorGroup::checkAll() {
#ifdef EXRAIL_ACTIVE
doExrailSensorGroup(GroupProcess::check, & USB_SERIAL);
#endif
}
// called by command to get sensor list
void SensorGroup::printAll(Print * serial) {
(void)serial; // suppress unused warning
#ifdef EXRAIL_ACTIVE
doExrailSensorGroup(GroupProcess::print,serial);
#endif
}
void SensorGroup::pullupAll() {
#ifdef EXRAIL_ACTIVE
doExrailSensorGroup(GroupProcess::pullup, & USB_SERIAL);
#endif
void SensorGroup::prepareAll() {
doExrailSensorGroup(GroupProcess::prepare, & USB_SERIAL);
}
void SensorGroup::dumpAll(Print * stream) {
doExrailSensorGroup(GroupProcess::dump, stream);
}
#else
// if EXRAIL is not active, these functions are empty
void SensorGroup::checkAll() {}
void SensorGroup::printAll(Print * serial) {(void)serial;}
void SensorGroup::prepareAll() {}
#endif
// called by EXRAIL constructed doExrailSensorGroup for each group
void SensorGroup::doSensorGroup(VPIN firstVpin, int nPins, byte* statebits,
GroupProcess action, Print * serial) {
GroupProcess action, Print * serial, bool pullup) {
// Loop through the pins in the group
for (auto i=0;i<nPins;i++) {
@@ -32,8 +39,8 @@ void SensorGroup::doSensorGroup(VPIN firstVpin, int nPins, byte* statebits,
byte stateMask=1<<(i%8);
VPIN vpin= firstVpin+i;
switch(action) {
case GroupProcess::pullup:
IODevice::configureInput(vpin, true);
case GroupProcess::prepare:
IODevice::configureInput(vpin, pullup);
__attribute__ ((fallthrough)); // to check the current state
case GroupProcess::check:
@@ -41,13 +48,18 @@ void SensorGroup::doSensorGroup(VPIN firstVpin, int nPins, byte* statebits,
if ((bool)(statebits[stateByte]&stateMask) ==IODevice::read(vpin)) break; // no change
// flip state bit
statebits[stateByte]^=stateMask;
if (action==GroupProcess::pullup) break;
if (action==GroupProcess::prepare) break;
// fall through to print the changed value
__attribute__ ((fallthrough));
case GroupProcess::print:
StringFormatter::send(serial, F("<%c %d>\n"),
(statebits[stateByte]&stateMask)?'Q':'q', firstVpin+i);
(statebits[stateByte]&stateMask)?'Q':'q', vpin);
break;
case GroupProcess::dump:
StringFormatter::send(serial, F("<Q %d %d %c>\n"),
vpin, vpin, pullup?'1':'0');
break;
}
}

View File

@@ -9,15 +9,19 @@
// reference to the optional exrail built function which contains the
// calls to SensorGroup::doSensorGroup
enum GroupProcess:byte {pullup,print,check};
enum GroupProcess:byte {prepare,print,check,dump};
class SensorGroup {
public:
static void checkAll();
static void printAll(Print * serial);
static void pullupAll();
static void prepareAll();
static void dumpAll(Print* serial);
// doSensorGroup is called from the automatically
// built doExrailSensorGroup, once for each user defined group.
static void doSensorGroup(VPIN vpin, int nPins, byte* statebits,
GroupProcess action, Print * serial);
GroupProcess action, Print * serial, bool pullup=false);
private:
static void doExrailSensorGroup(GroupProcess action, Print * stream);
};

View File

@@ -191,7 +191,18 @@ void Sensor::printAll(Print *stream){
for(Sensor * tt=firstSensor;tt!=NULL;tt=tt->nextSensor){
StringFormatter::send(stream, F("<%c %d>\n"), tt->active ? 'Q' : 'q', tt->data.snum);
}
} // Sensor::printAll
}
void Sensor::dumpAll(Print *stream){
if (stream == NULL) return; // Nothing to do
SensorGroup::dumpAll(stream);
for(Sensor * tt=firstSensor;tt!=NULL;tt=tt->nextSensor){
StringFormatter::send(stream, F("<Q %d %d %d>\n"),
tt->data.snum, tt->data.pin,tt->data.pullUp);
}
} // Sensor::dumpAll
///////////////////////////////////////////////////////////////////////////////
// Static Function to create/find Sensor object.

View File

@@ -82,6 +82,8 @@ public:
static bool remove(int id);
static void checkAll();
static void printAll(Print *stream);
static void dumpAll(Print* stream);
static unsigned long lastReadCycle; // value of micros at start of last read cycle
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.