mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2025-01-22 18:48:52 +01:00
Sensors show their status at change (as in classic)
This commit is contained in:
parent
c882c2edfc
commit
9099af3188
@ -96,6 +96,7 @@ void DCCEXParser::loop(Stream &stream)
|
|||||||
buffer[bufferLength++] = ch;
|
buffer[bufferLength++] = ch;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Sensor::checkAll(&stream); // Update and print changes
|
||||||
}
|
}
|
||||||
|
|
||||||
int DCCEXParser::splitValues(int result[MAX_PARAMS], const byte *cmd)
|
int DCCEXParser::splitValues(int result[MAX_PARAMS], const byte *cmd)
|
||||||
@ -359,11 +360,8 @@ void DCCEXParser::parse(Print *stream, byte *com, bool blocking)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
case 'Q': // SENSORS <Q>
|
case 'Q': // SENSORS <Q>
|
||||||
Sensor::checkAll();
|
Sensor::checkAll(NULL); // Update, don't print changes
|
||||||
for (Sensor *tt = Sensor::firstSensor; tt != NULL; tt = tt->nextSensor)
|
Sensor::printAll(stream); // Print all
|
||||||
{
|
|
||||||
StringFormatter::send(stream, F("<%c %d>"), tt->active ? 'Q' : 'q', tt->data.snum);
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case 's': // <s>
|
case 's': // <s>
|
||||||
|
26
Sensors.cpp
26
Sensors.cpp
@ -65,27 +65,49 @@ decide to ignore the <q ID> return and only react to <Q ID> triggers.
|
|||||||
|
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
|
|
||||||
|
#include "StringFormatter.h"
|
||||||
#include "Sensors.h"
|
#include "Sensors.h"
|
||||||
#include "EEStore.h"
|
#include "EEStore.h"
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// checks all defined sensors and prints _changed_ sensor states
|
||||||
|
// to stream unless stream is NULL in which case only internal
|
||||||
|
// state is updated
|
||||||
|
//
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void Sensor::checkAll(){
|
void Sensor::checkAll(Print *stream){
|
||||||
|
|
||||||
for(Sensor * tt=firstSensor;tt!=NULL;tt=tt->nextSensor){
|
for(Sensor * tt=firstSensor;tt!=NULL;tt=tt->nextSensor){
|
||||||
tt->signal=tt->signal*(1.0-SENSOR_DECAY)+digitalRead(tt->data.pin)*SENSOR_DECAY;
|
tt->signal=tt->signal*(1.0-SENSOR_DECAY)+digitalRead(tt->data.pin)*SENSOR_DECAY;
|
||||||
|
|
||||||
if(!tt->active && tt->signal<0.5){
|
if(!tt->active && tt->signal<0.5){
|
||||||
tt->active=true;
|
tt->active=true;
|
||||||
|
if (stream != NULL) StringFormatter::send(stream, F("<Q %d>"), tt->data.snum);
|
||||||
} else if(tt->active && tt->signal>0.9){
|
} else if(tt->active && tt->signal>0.9){
|
||||||
tt->active=false;
|
tt->active=false;
|
||||||
|
if (stream != NULL) StringFormatter::send(stream, F("<q %d>"), tt->data.snum);
|
||||||
}
|
}
|
||||||
} // loop over all sensors
|
} // loop over all sensors
|
||||||
|
|
||||||
} // Sensor::checkAll
|
} // Sensor::checkAll
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// prints all sensor states to stream
|
||||||
|
//
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void Sensor::printAll(Print *stream){
|
||||||
|
|
||||||
|
for(Sensor * tt=firstSensor;tt!=NULL;tt=tt->nextSensor){
|
||||||
|
if (stream != NULL)
|
||||||
|
StringFormatter::send(stream, F("<%c %d>"), tt->active ? 'Q' : 'q', tt->data.snum);
|
||||||
|
} // loop over all sensors
|
||||||
|
} // Sensor::printAll
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
Sensor *Sensor::create(int snum, int pin, int pullUp){
|
Sensor *Sensor::create(int snum, int pin, int pullUp){
|
||||||
|
@ -40,7 +40,8 @@ struct Sensor{
|
|||||||
static Sensor *create(int, int, int);
|
static Sensor *create(int, int, int);
|
||||||
static Sensor* get(int);
|
static Sensor* get(int);
|
||||||
static bool remove(int);
|
static bool remove(int);
|
||||||
static void checkAll();
|
static void checkAll(Print *);
|
||||||
|
static void printAll(Print *);
|
||||||
}; // Sensor
|
}; // Sensor
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user