//TemperatureRecorder class //Written by Napoleon Leoni, February 2014 //This class takes a pointer to an LM75B sensor on the MBED //application board and reads it temperature value, keeps track //of the max and min values (since a last reset of the values) and also //keeps a circular buffer of recorded temperature values
Revision 1:8ec88bb8425f, committed 2014-02-21
- Comitter:
- nleoni
- Date:
- Fri Feb 21 06:57:23 2014 +0000
- Parent:
- 0:aca019487653
- Commit message:
- Updated testing of class
Changed in this revision
temperatureRecorder.cpp | Show annotated file Show diff for this revision Revisions of this file |
temperatureRecorder.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/temperatureRecorder.cpp Thu Feb 13 07:59:09 2014 +0000 +++ b/temperatureRecorder.cpp Fri Feb 21 06:57:23 2014 +0000 @@ -43,6 +43,7 @@ temperatureRecorder::temperatureRecorder(int bufferSize,LM75B *ptrTsensor){ this->sensorValid=false; this->resetTemperatureFlag=true; + this->externalSensor=false; if(bufferSize <= this->maxRecordingBufferSize){ this->recordingBufferSize=bufferSize; } else { @@ -72,6 +73,7 @@ //check if Trecorder is set in farehnheit if so make the conversion if(this->temperatureInFarenheit) this->currentTemperature=convertToFarenheit(this->currentTemperature); //TODO store temperature into buffer + } if(this->resetTemperatureFlag){ //reset max an min values this->maxTemperature=this->currentTemperature; @@ -82,8 +84,32 @@ if((this->currentTemperature) > (this->maxTemperature)) this->maxTemperature=this->currentTemperature; if((this->currentTemperature) < (this->minTemperature)) this->minTemperature=this->currentTemperature; } - } }//end of temperatureRecorder::makeReading() + +//**********************************************************************************************// +// void temperatureRecorder::makeReading(float temperatureInC) // +// Makes a temperature reading from an external sensor, stores the reading in the appropiate // +// units in the object's member this->currentTemperature and updates the maxTemperature and // +// minTemperature // +// Inputs: float temperatureInC, provide an external reading as opposed to the internally used // +// LM75B // +//**********************************************************************************************// +void temperatureRecorder::makeReading(float temperatureInC){ + this->currentTemperature=temperatureInC; + //check if Trecorder is set in farehnheit if so make the conversion + if(this->temperatureInFarenheit) this->currentTemperature=convertToFarenheit(this->currentTemperature); + //TODO store temperature into buffer + if(this->resetTemperatureFlag){ + //reset max an min values + this->maxTemperature=this->currentTemperature; + this->minTemperature=this->currentTemperature; + this->resetTemperatureFlag=false; + } else { + //compare current temperature to stored esxtremes,replace if neccesary + if((this->currentTemperature) > (this->maxTemperature)) this->maxTemperature=this->currentTemperature; + if((this->currentTemperature) < (this->minTemperature)) this->minTemperature=this->currentTemperature; + } +}//end of temperatureRecorder::makeReading() //**********************************************************************************************// // void temperatureRecorder::getTemperature(void){ // @@ -195,3 +221,33 @@ bool temperatureRecorder::isTemperatureInFarenheit(void){ return this->temperatureInFarenheit; } + +//**********************************************************************************************// +// void temperatureRecorder::enableExternalSensor(void){ // +// enables the external sensor mode which allows for manual setting of the temperature // +// Inputs: void // +//**********************************************************************************************// + void temperatureRecorder::enableExternalSensor(void){ + this->externalSensor=true; + } + +//**********************************************************************************************// +// void temperatureRecorder::enableExternalSensor(void){ // +// disables the external sensor mode which allows for manual setting of the temperature // +// Inputs: void // +//**********************************************************************************************// + void temperatureRecorder::disableExternalSensor(void){ + this->externalSensor=false; + } + +//**********************************************************************************************// +// void temperatureRecorder::inputExternalSensorTemperatureInC(float inputTemperatureInC)){ // +// sets the external sensor temperature which is what is recorded and processed when then // +// the externalSensor flag is set to true. this enables feeding a synthetic temperature // +// waveform for testing purposes +// Inputs: void // +//**********************************************************************************************// + void temperatureRecorder::inputExternalSensorTemperatureInC(float inputTemperatureInC){ + this->externalSensorTemperatureInC=inputTemperatureInC; + } +
--- a/temperatureRecorder.h Thu Feb 13 07:59:09 2014 +0000 +++ b/temperatureRecorder.h Fri Feb 21 06:57:23 2014 +0000 @@ -30,11 +30,12 @@ public: private: - bool recordingEnabled,resetTemperatureFlag,sensorValid,temperatureInFarenheit; + bool recordingEnabled,resetTemperatureFlag,sensorValid,temperatureInFarenheit,externalSensor; int recordingBufferSize; static const int maxRecordingBufferSize=MAXRECORDINGBUFFER; float currentTemperature,maxTemperature,minTemperature; LM75B *tsensor;//pointer to temperature sensor type + float externalSensorTemperatureInC; //public Methods public: @@ -44,11 +45,15 @@ temperatureRecorder(int bufferSize,LM75B *ptrTsensor); void makeReading(void); + void makeReading(float); float getTemperature(void); float getMaxTemperature(void); float getMinTemperature(void); + void enableExternalSensor(void) + void disableExternalSensor(void); + void setTemperatureToCelsius(void); void setTemperatureToFarenheit(void); bool isTemperatureInFarenheit(void);