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

esp32 sensorgroup

This commit is contained in:
Asbelos
2025-07-24 20:41:31 +01:00
parent 823ceef338
commit d84e354142
2 changed files with 8 additions and 8 deletions

View File

@@ -3,7 +3,7 @@
// called in loop to check sensors // called in loop to check sensors
void SensorGroup::checkAll() { void SensorGroup::checkAll() {
#ifdef EXRAIL_ACTIVE #ifdef EXRAIL_ACTIVE
doExrailSensorGroup(GroupProcess::CHECK, & USB_SERIAL); doExrailSensorGroup(GroupProcess::check, & USB_SERIAL);
#endif #endif
} }
@@ -11,13 +11,13 @@ void SensorGroup::checkAll() {
void SensorGroup::printAll(Print * serial) { void SensorGroup::printAll(Print * serial) {
(void)serial; // suppress unused warning (void)serial; // suppress unused warning
#ifdef EXRAIL_ACTIVE #ifdef EXRAIL_ACTIVE
doExrailSensorGroup(GroupProcess::PRINT,serial); doExrailSensorGroup(GroupProcess::print,serial);
#endif #endif
} }
void SensorGroup::pullupAll() { void SensorGroup::pullupAll() {
#ifdef EXRAIL_ACTIVE #ifdef EXRAIL_ACTIVE
doExrailSensorGroup(GroupProcess::PULLUP, & USB_SERIAL); doExrailSensorGroup(GroupProcess::pullup, & USB_SERIAL);
#endif #endif
} }
@@ -32,20 +32,20 @@ void SensorGroup::doSensorGroup(VPIN firstVpin, int nPins, byte* statebits,
byte stateMask=1<<(i%8); byte stateMask=1<<(i%8);
VPIN vpin= firstVpin+i; VPIN vpin= firstVpin+i;
switch(action) { switch(action) {
case GroupProcess::PULLUP: case GroupProcess::pullup:
IODevice::configureInput(vpin, true); IODevice::configureInput(vpin, true);
__attribute__ ((fallthrough)); // to check the current state __attribute__ ((fallthrough)); // to check the current state
case GroupProcess::CHECK: case GroupProcess::check:
// check for state change // check for state change
if ((bool)(statebits[stateByte]&stateMask) ==IODevice::read(vpin)) break; // no change if ((bool)(statebits[stateByte]&stateMask) ==IODevice::read(vpin)) break; // no change
// flip state bit // flip state bit
statebits[stateByte]^=stateMask; statebits[stateByte]^=stateMask;
if (action==GroupProcess::PULLUP) break; if (action==GroupProcess::pullup) break;
// fall through to print the changed value // fall through to print the changed value
__attribute__ ((fallthrough)); __attribute__ ((fallthrough));
case GroupProcess::PRINT: case GroupProcess::print:
StringFormatter::send(serial, F("<%c %d>\n"), StringFormatter::send(serial, F("<%c %d>\n"),
(statebits[stateByte]&stateMask)?'Q':'q', firstVpin+i); (statebits[stateByte]&stateMask)?'Q':'q', firstVpin+i);
break; break;

View File

@@ -9,7 +9,7 @@
// reference to the optional exrail built function which contains the // reference to the optional exrail built function which contains the
// calls to SensorGroup::doSensorGroup // calls to SensorGroup::doSensorGroup
enum GroupProcess:byte {PULLUP,PRINT,CHECK}; enum GroupProcess:byte {pullup,print,check};
class SensorGroup { class SensorGroup {
public: public: