From cf0807d3c742dd2c2f16589ab437779a2a8aa6bd Mon Sep 17 00:00:00 2001 From: 84julian <99591778+84julian@users.noreply.github.com> Date: Sun, 13 Feb 2022 12:18:16 +0100 Subject: [PATCH] Sensor Broadcast Exrail Nonreal (eg id 200) Sensor broadcasting to wifi via Exrail Latch/Unlatch --- EXRAIL2.cpp | 3 +++ Sensors.cpp | 20 ++++++++++++++++++++ Sensors.h | 1 + 3 files changed, 24 insertions(+) diff --git a/EXRAIL2.cpp b/EXRAIL2.cpp index af6f0a1..3576041 100644 --- a/EXRAIL2.cpp +++ b/EXRAIL2.cpp @@ -49,6 +49,7 @@ #include "WiThrottle.h" #include "DCCEXParser.h" #include "Turnouts.h" +#include "Sensors.h" // Sensor feedback an rocrail senden #include "CommandDistributor.h" @@ -624,10 +625,12 @@ void RMFT2::loop2() { case OPCODE_LATCH: setFlag(operand,LATCH_FLAG); + Sensor::call(operand, 1); // sesor aktiv senden break; case OPCODE_UNLATCH: setFlag(operand,0,LATCH_FLAG); + Sensor::call(operand, 0); // sensor inaktiv senden break; case OPCODE_SET: diff --git a/Sensors.cpp b/Sensors.cpp index d1c0fe5..4db302e 100644 --- a/Sensors.cpp +++ b/Sensors.cpp @@ -189,6 +189,26 @@ void Sensor::printAll(Print *stream){ } // loop over all sensors } // Sensor::printAll +/////////////////////////////////////////////////////////////////////////////// +// +// Static Function to call Sensor object. +// +/////////////////////////////////////////////////////////////////////////////// + +Sensor *Sensor::call(int snum, int pullUp){ + Sensor *tt; + if (pullUp == 0) + CommandDistributor::broadcastSensor(readingSensor->data.snum=snum,readingSensor->active); + else + CommandDistributor::broadcastSensor(readingSensor->data.snum=snum,readingSensor->latchDelay = minReadCount ); + // minReadCount could be better defind to always inactive?? + + return tt ; + + + +} + /////////////////////////////////////////////////////////////////////////////// // Static Function to create/find Sensor object. diff --git a/Sensors.h b/Sensors.h index 4b12a03..caa104e 100644 --- a/Sensors.h +++ b/Sensors.h @@ -76,6 +76,7 @@ public: static void store(); #endif static Sensor *create(int id, VPIN vpin, int pullUp); + static Sensor *call(int id, int pullUp); // broadcast sensor to rocrail static Sensor* get(int id); static bool remove(int id); static void checkAll();