mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-23 08:06:13 +01:00
checkAll() only checks one now (and should be renamed)
This commit is contained in:
parent
9099af3188
commit
ecd176042e
|
@ -360,8 +360,7 @@ void DCCEXParser::parse(Print *stream, byte *com, bool blocking)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case 'Q': // SENSORS <Q>
|
case 'Q': // SENSORS <Q>
|
||||||
Sensor::checkAll(NULL); // Update, don't print changes
|
Sensor::printAll(stream);
|
||||||
Sensor::printAll(stream); // Print all
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case 's': // <s>
|
case 's': // <s>
|
||||||
|
|
27
Sensors.cpp
27
Sensors.cpp
|
@ -72,26 +72,27 @@ decide to ignore the <q ID> return and only react to <Q ID> triggers.
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// checks all defined sensors and prints _changed_ sensor states
|
// checks one defined sensors and prints _changed_ sensor state
|
||||||
// to stream unless stream is NULL in which case only internal
|
// to stream unless stream is NULL in which case only internal
|
||||||
// state is updated
|
// state is updated. Then advances to next sensor which will
|
||||||
|
// be checked att next invocation.
|
||||||
//
|
//
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void Sensor::checkAll(Print *stream){
|
void Sensor::checkAll(Print *stream){
|
||||||
|
|
||||||
for(Sensor * tt=firstSensor;tt!=NULL;tt=tt->nextSensor){
|
if (firstSensor == NULL) return;
|
||||||
tt->signal=tt->signal*(1.0-SENSOR_DECAY)+digitalRead(tt->data.pin)*SENSOR_DECAY;
|
if (readingSensor == NULL) readingSensor=firstSensor;
|
||||||
|
readingSensor->signal=readingSensor->signal*(1.0-SENSOR_DECAY)+digitalRead(readingSensor->data.pin)*SENSOR_DECAY;
|
||||||
|
|
||||||
if(!tt->active && tt->signal<0.5){
|
if(!readingSensor->active && readingSensor->signal<0.5){
|
||||||
tt->active=true;
|
readingSensor->active=true;
|
||||||
if (stream != NULL) StringFormatter::send(stream, F("<Q %d>"), tt->data.snum);
|
if (stream != NULL) StringFormatter::send(stream, F("<Q %d>"), readingSensor->data.snum);
|
||||||
} else if(tt->active && tt->signal>0.9){
|
} else if(readingSensor->active && readingSensor->signal>0.9){
|
||||||
tt->active=false;
|
readingSensor->active=false;
|
||||||
if (stream != NULL) StringFormatter::send(stream, F("<q %d>"), tt->data.snum);
|
if (stream != NULL) StringFormatter::send(stream, F("<q %d>"), readingSensor->data.snum);
|
||||||
}
|
}
|
||||||
} // loop over all sensors
|
readingSensor=readingSensor->nextSensor;
|
||||||
|
|
||||||
} // Sensor::checkAll
|
} // Sensor::checkAll
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -159,6 +160,7 @@ bool Sensor::remove(int n){
|
||||||
else
|
else
|
||||||
pp->nextSensor=tt->nextSensor;
|
pp->nextSensor=tt->nextSensor;
|
||||||
|
|
||||||
|
if (readingSensor==tt) readingSensor=tt->nextSensor;
|
||||||
free(tt);
|
free(tt);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -196,3 +198,4 @@ void Sensor::store(){
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
Sensor *Sensor::firstSensor=NULL;
|
Sensor *Sensor::firstSensor=NULL;
|
||||||
|
Sensor *Sensor::readingSensor=NULL;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user