diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index b8c3100..4282b83 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -1135,12 +1135,7 @@ bool DCCEXParser::parseS(Print *stream, int16_t params, int16_t p[]) return true; case 0: // list sensor definitions - if (Sensor::firstSensor == NULL) - return false; - for (Sensor *tt = Sensor::firstSensor; tt != NULL; tt = tt->nextSensor) - { - StringFormatter::send(stream, F("\n"), tt->data.snum, tt->data.pin, tt->data.pullUp); - } + Sensor::dumpAll(stream); return true; default: // invalid number of arguments diff --git a/EXRAIL2MacroReset.h b/EXRAIL2MacroReset.h index 60cdd07..092791e 100644 --- a/EXRAIL2MacroReset.h +++ b/EXRAIL2MacroReset.h @@ -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 type sensor feedback definitions each with id matching vpin + * @brief Defines multiple JMRI 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 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) diff --git a/EXRAILMacros.h b/EXRAILMacros.h index e2eb3f0..9366658 100644 --- a/EXRAILMacros.h +++ b/EXRAILMacros.h @@ -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), diff --git a/SensorGroup.cpp b/SensorGroup.cpp index e11224b..78fa813 100644 --- a/SensorGroup.cpp +++ b/SensorGroup.cpp @@ -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\n"), - (statebits[stateByte]&stateMask)?'Q':'q', firstVpin+i); + (statebits[stateByte]&stateMask)?'Q':'q', vpin); + break; + + case GroupProcess::dump: + StringFormatter::send(serial, F("\n"), + vpin, vpin, pullup?'1':'0'); break; } } diff --git a/SensorGroup.h b/SensorGroup.h index bb65aed..6f8c9c0 100644 --- a/SensorGroup.h +++ b/SensorGroup.h @@ -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); }; diff --git a/Sensors.cpp b/Sensors.cpp index 760e138..2e42f4d 100644 --- a/Sensors.cpp +++ b/Sensors.cpp @@ -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("\n"), + tt->data.snum, tt->data.pin,tt->data.pullUp); + } +} // Sensor::dumpAll /////////////////////////////////////////////////////////////////////////////// // Static Function to create/find Sensor object. diff --git a/Sensors.h b/Sensors.h index c1550e0..f69db09 100644 --- a/Sensors.h +++ b/Sensors.h @@ -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.