diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index dc58bd8..b03805b 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -250,8 +250,11 @@ void DCCEXParser::parse(Print * stream, byte *com, bool blocking) { return; case 'Q': // SENSORS - Sensor::status(stream); - break; + Sensor::checkAll(); + for(Sensor * tt=Sensor::firstSensor;tt!=NULL;tt=tt->nextSensor){ + StringFormatter::send(stream,F("<%c %d>"), tt->active?'Q':'q', tt->data.snum); + } + return; case 's': // StringFormatter::send(stream,F(""),DCCWaveform::mainTrack.getPowerMode()==POWERMODE::ON ); @@ -325,8 +328,14 @@ bool DCCEXParser::parseZ( Print * stream,int params, int p[]){ return Output::remove(p[0]); case 0: // - return Output::showAll(stream); - + { + bool gotone=false; + for(Output * tt=Output::firstOutput;tt!=NULL;tt=tt->nextOutput){ + gotone=true; + StringFormatter::send(stream,F(""), tt->data.id, tt->data.pin, tt->data.iFlag, tt->data.oStatus); + } + return gotone; + } default: return false; } @@ -367,20 +376,31 @@ void DCCEXParser::funcmap(int cab, byte value, byte fstart, byte fstop) { //=================================== bool DCCEXParser::parseT(Print * stream, int params, int p[]) { switch(params){ - case 0: // - return (Turnout::showAll(stream)); break; - - case 1: // + case 0: // show all turnouts + { + bool gotOne=false; + for(Turnout *tt=Turnout::firstTurnout;tt!=NULL;tt=tt->nextTurnout){ + gotOne=true; + StringFormatter::send(stream,F(""), tt->data.id, tt->data.tStatus & STATUS_ACTIVE); + } + return gotOne; // will if none found + } + + case 1: // delete turnout if (!Turnout::remove(p[0])) return false; StringFormatter::send(stream,F("")); return true; - case 2: // - if (!Turnout::activate(p[0],p[1])) return false; - Turnout::show(stream,p[0]); + case 2: // activate turnout + { + Turnout* tt=Turnout::get(p[0]); + if (!tt) return false; + tt->activate(p[1]); + StringFormatter::send(stream,F(""), tt->data.id, tt->data.tStatus & STATUS_ACTIVE); + } return true; - case 3: // + case 3: // define turnout if (!Turnout::create(p[0],p[1],p[2])) return false; StringFormatter::send(stream,F("")); return true; @@ -392,18 +412,19 @@ bool DCCEXParser::parseT(Print * stream, int params, int p[]) { bool DCCEXParser::parseS( Print * stream,int params, int p[]) { - switch(params){ - - case 3: // argument is string with id number of sensor followed by a pin number and pullUp indicator (0=LOW/1=HIGH) + switch(params){ + case 3: // create sensor. pullUp indicator (0=LOW/1=HIGH) Sensor::create(p[0],p[1],p[2]); return true; - case 1: // argument is a string with id number only + case 1: // S id> remove sensor if (Sensor::remove(p[0])) return true; break; - case -1: // no arguments - Sensor::show(stream); + case 0: // lit sensor states + for(Sensor * tt=Sensor::firstSensor;tt!=NULL;tt=tt->nextSensor){ + StringFormatter::send(stream, F(""), tt->data.snum, tt->data.pin, tt->data.pullUp); + } return true; default: // invalid number of arguments diff --git a/Outputs.cpp b/Outputs.cpp index 3064b43..50a8eda 100644 --- a/Outputs.cpp +++ b/Outputs.cpp @@ -83,7 +83,7 @@ the state of any outputs being monitored or controlled by a separate interface o #include "Outputs.h" #include "EEStore.h" -#include "StringFormatter.h" + void Output::activate(int s){ data.oStatus=(s>0); // if s>0, set status to active, else inactive @@ -121,23 +121,6 @@ bool Output::remove(int n){ /////////////////////////////////////////////////////////////////////////////// -bool Output::showAll(Print * stream){ - bool gotone=false; - for(Output * tt=firstOutput;tt!=NULL;tt=tt->nextOutput){ - gotone=true; - StringFormatter::send(stream,F(""), tt->data.id, tt->data.pin, tt->data.iFlag, tt->data.oStatus); - } - return gotone; -} - -void Output::show(Print * stream){ - for(Output * tt=firstOutput;tt!=NULL;tt=tt->nextOutput){ - StringFormatter::send(stream,F(""), tt->data.id, tt->data.oStatus); - } -} - -/////////////////////////////////////////////////////////////////////////////// - void Output::load(){ struct OutputData data; Output *tt; diff --git a/Outputs.h b/Outputs.h index 736123f..891cd9b 100644 --- a/Outputs.h +++ b/Outputs.h @@ -36,15 +36,12 @@ class Output{ static void load(); static void store(); static Output *create(int, int, int, int=0); - static void show(Print * stream); - static bool showAll(Print * stream); - - private: static Output *firstOutput; - int num; struct OutputData data; Output *nextOutput; - + private: + int num; // Chris has no idea what this is all about! + }; // Output #endif diff --git a/Sensors.cpp b/Sensors.cpp index 2cdcae3..3f55c5f 100644 --- a/Sensors.cpp +++ b/Sensors.cpp @@ -68,27 +68,23 @@ decide to ignore the return and only react to triggers. #include "Sensors.h" #include "EEStore.h" -#include "StringFormatter.h" /////////////////////////////////////////////////////////////////////////////// -void Sensor::check(Print * stream){ - Sensor *tt; - - for(tt=firstSensor;tt!=NULL;tt=tt->nextSensor){ +void Sensor::checkAll(){ + + for(Sensor * tt=firstSensor;tt!=NULL;tt=tt->nextSensor){ tt->signal=tt->signal*(1.0-SENSOR_DECAY)+digitalRead(tt->data.pin)*SENSOR_DECAY; if(!tt->active && tt->signal<0.5){ tt->active=true; - StringFormatter::send(stream,F(""), tt->data.snum); } else if(tt->active && tt->signal>0.9){ tt->active=false; - StringFormatter::send(stream,F(""), tt->data.snum); } } // loop over all sensors -} // Sensor::check +} // Sensor::checkAll /////////////////////////////////////////////////////////////////////////////// @@ -148,22 +144,6 @@ bool Sensor::remove(int n){ /////////////////////////////////////////////////////////////////////////////// -void Sensor::show(Print * stream){ - for(Sensor * tt=firstSensor;tt!=NULL;tt=tt->nextSensor){ - StringFormatter::send(stream, F(""), tt->data.snum, tt->data.pin, tt->data.pullUp); - } -} - -/////////////////////////////////////////////////////////////////////////////// - -void Sensor::status(Print * stream){ - for(Sensor * tt=firstSensor;tt!=NULL;tt=tt->nextSensor){ - StringFormatter::send(stream,F("<%c %d>"), tt->active?'Q':'q', tt->data.snum); - } -} - -/////////////////////////////////////////////////////////////////////////////// - void Sensor::load(){ struct SensorData data; Sensor *tt; diff --git a/Sensors.h b/Sensors.h index 3f37df3..71f60ba 100644 --- a/Sensors.h +++ b/Sensors.h @@ -40,9 +40,7 @@ struct Sensor{ static Sensor *create(int, int, int); static Sensor* get(int); static bool remove(int); - static void show(Print * stream); - static void status(Print * stream); - static void check(Print * stream); + static void checkAll(); }; // Sensor #endif diff --git a/Turnouts.cpp b/Turnouts.cpp index ceff11f..bf146bf 100644 --- a/Turnouts.cpp +++ b/Turnouts.cpp @@ -18,10 +18,7 @@ */ #include "Turnouts.h" #include "EEStore.h" -#include "StringFormatter.h" - #include "PWMServoDriver.h" -//#include "DIAG.h" // uncomment if you need DIAG below bool Turnout::activate(int n,bool state){ //DIAG(F("\nTurnout::activate(%d,%d)\n"),n,state); @@ -41,7 +38,6 @@ // activate is virtual here so that it can be overridden by a non-DCC turnout mechanism void Turnout::activate(bool state) { - //DIAG(F("\nTurnout::activate\n")); if (state) data.tStatus|=STATUS_ACTIVE; else data.tStatus &= ~STATUS_ACTIVE; if (data.tStatus & STATUS_PWM) PWMServoDriver::setServo(data.tStatus & STATUS_PWMPIN, (data.inactiveAngle+(state?data.moveAngle:0))); @@ -70,31 +66,9 @@ bool Turnout::remove(int n){ free(tt); turnoutlistHash++; - return true; - + return true; } -/////////////////////////////////////////////////////////////////////////////// - -void Turnout::show(Print * stream, int n){ - for(Turnout *tt=firstTurnout;tt!=NULL;tt=tt->nextTurnout){ - if (tt->data.id==n) { - StringFormatter::send(stream,F(""), tt->data.id, tt->data.tStatus & STATUS_ACTIVE); - return; - } - } -} - -bool Turnout::showAll(Print * stream){ - bool gotOne=false; - for(Turnout * tt=firstTurnout;tt!=NULL;tt=tt->nextTurnout){ - StringFormatter::send(stream,F(""), tt->data.id, tt->data.address, tt->data.subAddress, (tt->data.tStatus & STATUS_ACTIVE)!=0); - gotOne=true; - } - return gotOne; -} - - /////////////////////////////////////////////////////////////////////////////// void Turnout::load(){ @@ -159,4 +133,3 @@ Turnout *Turnout::create(int id){ Turnout *Turnout::firstTurnout=NULL; int Turnout::turnoutlistHash=0; //bump on every change so clients know when to refresh their lists - diff --git a/Turnouts.h b/Turnouts.h index 6c08dc2..5c9b590 100644 --- a/Turnouts.h +++ b/Turnouts.h @@ -48,8 +48,6 @@ class Turnout { static Turnout *create(int id , int address , int subAddress); static Turnout *create(int id , byte pin , int activeAngle, int inactiveAngle); static Turnout *create(int id); - static void show(Print * stream, int n); - static bool showAll(Print * stream); void activate(bool state); }; // Turnout