napoleon leoni / temperatureRecorder
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers temperatureRecorder.cpp Source File

temperatureRecorder.cpp

00001 //TemperatureRecorder class
00002 //Written by Napoleon Leoni, February 2014
00003 //This class takes a pointer to an LM75B sensor
00004 //and reads it temperature value, keeps track of the max and
00005 //min values (since a last reset of the values) and also keeps 
00006 //a circular buffer of recorded temperature values
00007 
00008 //***************************** TESTING ********************************************************//
00009 //  TEST        TEST DESCRIPTION                                                STATUS          //
00010 //  1           Time display is inceremented in seconds and date shown          PASS            //
00011 //              corresponds to date set in code                                                 //
00012 //  2           Max temperature displayed is highest reached                    PASS            //
00013 //              during a heating event (finger touch)                                           //
00014 //  3           Min Temperature displayed is lowest reached                     PASS            //
00015 //              during a cooling event                                                          //
00016 //  4           Changing from degrees C to degress F and back retains           PASS            //
00017 //              Max and min values and displays proper conversion                               //
00018 //**********************************************************************************************//
00019 
00020 
00021 #include "temperatureRecorder.h"
00022 
00023     //temperature Recorder class definition
00024 
00025     //default constructor, sets default buffer size to max
00026     temperatureRecorder::temperatureRecorder(){
00027         //set size of circular buffer for temperature history
00028         this->recordingBufferSize=maxRecordingBufferSize;
00029         this->sensorValid=false;
00030         this->resetTemperatureFlag=true;
00031     }
00032     
00033 //**********************************************************************************************//
00034 // temperatureRecorder::temperatureRecorder(int bufferSize,LM75B *ptrTsensor)                   //
00035 // Constructor with buffer size specified and ptr to temperature sensor object                  //
00036 // Inputs: bufferSize       integer, buffer size for circular buffer use to record temperatures //
00037 //                          limited to max value set in MAXRECORDINGBUFFER, internally enforced //
00038 //                          no error or warning displayed                                       //
00039 //         *ptrTsensor      pointer to LM75B sensor object, if sensor is valid temperature      //
00040 //                          readings can be made, otherwise the object is still created but     //
00041 //                          temperatures are returned as zero.                                  //
00042 //**********************************************************************************************//
00043     temperatureRecorder::temperatureRecorder(int bufferSize,LM75B *ptrTsensor){
00044         this->sensorValid=false;
00045         this->resetTemperatureFlag=true;
00046         this->externalSensor=false;
00047         if(bufferSize <= this->maxRecordingBufferSize){
00048             this->recordingBufferSize=bufferSize;
00049         } else {
00050             this->recordingBufferSize=maxRecordingBufferSize;
00051             //TODO return error message, but to where?
00052         }
00053         this->tsensor=ptrTsensor;
00054         //Check if sensor is valid
00055         if (this->tsensor->open()) {
00056             this->sensorValid=true;
00057             this->makeReading();
00058         } else {
00059             //TODO: how to return error condition here
00060         }    
00061     }
00062     
00063 //**********************************************************************************************//
00064 // void temperatureRecorder::makeReading(void){                                                 //
00065 // Makes a temperature reading from the LM75B, stores the reading in the appropiate units       //
00066 // in the object's member this->currentTemperature and updates the maxTemperature and           //  
00067 // minTemperature                                                                               //
00068 // Inputs: void                                                                                 //
00069 //**********************************************************************************************//
00070     void temperatureRecorder::makeReading(void){
00071         if(this->sensorValid){
00072             this->currentTemperature=this->tsensor->temp();
00073             //check if Trecorder is set in farehnheit if so make the conversion
00074             if(this->temperatureInFarenheit) this->currentTemperature=convertToFarenheit(this->currentTemperature);
00075             //TODO store temperature into buffer
00076         }
00077             if(this->resetTemperatureFlag){
00078                 //reset max an min values
00079                 this->maxTemperature=this->currentTemperature;
00080                 this->minTemperature=this->currentTemperature;
00081                 this->resetTemperatureFlag=false;
00082             } else {
00083                 //compare current temperature to stored esxtremes,replace if neccesary
00084                 if((this->currentTemperature) > (this->maxTemperature)) this->maxTemperature=this->currentTemperature;
00085                 if((this->currentTemperature) < (this->minTemperature)) this->minTemperature=this->currentTemperature;   
00086             }
00087     }//end of temperatureRecorder::makeReading()
00088 
00089 //**********************************************************************************************//
00090 // void temperatureRecorder::makeReading(float temperatureInC)                                 //
00091 // Makes a temperature reading from an external sensor, stores the reading in the appropiate    //
00092 // units in the object's member this->currentTemperature and updates the maxTemperature and     //  
00093 // minTemperature                                                                               //
00094 // Inputs: float temperatureInC, provide an external reading as opposed to the internally used  //
00095 //         LM75B                                                                                //
00096 //**********************************************************************************************//
00097 void temperatureRecorder::makeReading(float temperatureInC){
00098             this->currentTemperature=temperatureInC;
00099             //check if Trecorder is set in farehnheit if so make the conversion
00100             if(this->temperatureInFarenheit) this->currentTemperature=convertToFarenheit(this->currentTemperature);
00101             //TODO store temperature into buffer
00102             if(this->resetTemperatureFlag){
00103                 //reset max an min values
00104                 this->maxTemperature=this->currentTemperature;
00105                 this->minTemperature=this->currentTemperature;
00106                 this->resetTemperatureFlag=false;
00107             } else {
00108                 //compare current temperature to stored esxtremes,replace if neccesary
00109                 if((this->currentTemperature) > (this->maxTemperature)) this->maxTemperature=this->currentTemperature;
00110                 if((this->currentTemperature) < (this->minTemperature)) this->minTemperature=this->currentTemperature;   
00111             }
00112 }//end of temperatureRecorder::makeReading()
00113     
00114 //**********************************************************************************************//
00115 // void temperatureRecorder::getTemperature(void){                                              //
00116 // returns this->currentTemperature (last reading made) in the set units                        //
00117 // if the sensor is not valid returns 0                                                         //
00118 // Inputs: void                                                                                 //
00119 //**********************************************************************************************//
00120     float temperatureRecorder::getTemperature(void){ 
00121         if(this->sensorValid){
00122             return this->currentTemperature;
00123         } else {
00124             return 0;
00125         }             
00126     }
00127     
00128 //**********************************************************************************************//
00129 // void temperatureRecorder::getMaxTemperature(void){                                           //
00130 // returns this->maxTemperature (last reading made) in the set units                            //  
00131 // if the sensor is not valid returns 0                                                         //
00132 // Inputs: void                                                                                 //
00133 //**********************************************************************************************//
00134     float temperatureRecorder::getMaxTemperature(void){
00135         if(this->sensorValid){
00136             return this->maxTemperature;
00137         } else {
00138             return 0;
00139         }             
00140    }
00141    
00142 //**********************************************************************************************//
00143 // void temperatureRecorder::getMinTemperature(void){                                           //
00144 // returns this->minTemperature (last reading made) in the set units                            //  
00145 // if the sensor is not valid returns 0                                                         //
00146 // Inputs: void                                                                                 //
00147 //**********************************************************************************************//
00148     float temperatureRecorder::getMinTemperature(void){
00149          if(this->sensorValid){
00150             return this->minTemperature;  
00151         } else {
00152             return 0;
00153         }             
00154    }
00155     
00156 //**********************************************************************************************//
00157 // void temperatureRecorder::resetTemperatureExtremes(void){                                    //
00158 // sets an object internal flag that will trigger a reset of the Max and Min Temepratures       //  
00159 // recorded when the next reading is made from temperature sensor                               //
00160 // Inputs: void                                                                                 //
00161 //**********************************************************************************************//
00162     void temperatureRecorder::resetTemperatureExtremes(void){
00163         this->resetTemperatureFlag=true;    
00164     }
00165     
00166 //**********************************************************************************************//
00167 // void temperatureRecorder::setTemperatureToCelsius(void){                                    //
00168 // sets all recorded values to celsius and converts all future readings as well                //  
00169 // Inputs: void                                                                                 //
00170 //**********************************************************************************************//
00171     void temperatureRecorder::setTemperatureToCelsius(void){
00172         if(this->temperatureInFarenheit){
00173             this->temperatureInFarenheit=false;    
00174             this->currentTemperature=this->convertToCelsius(this->currentTemperature);
00175             this->maxTemperature=this->convertToCelsius(this->maxTemperature);
00176             this->minTemperature=this->convertToCelsius(this->minTemperature);
00177         }
00178     }
00179 
00180 //**********************************************************************************************//
00181 // void temperatureRecorder::setTemperatureToFarenheit(void){                                    //
00182 // sets all recorded values to farenheit and converts all future readings as well                //  
00183 // Inputs: void                                                                                 //
00184 //**********************************************************************************************//
00185     void temperatureRecorder::setTemperatureToFarenheit(void){
00186         if(!this->temperatureInFarenheit){
00187             this->temperatureInFarenheit=true;    
00188             this->currentTemperature=this->convertToFarenheit(this->currentTemperature);
00189             this->maxTemperature=this->convertToFarenheit(this->maxTemperature);
00190             this->minTemperature=this->convertToFarenheit(this->minTemperature);
00191         }
00192     }
00193     
00194 //**********************************************************************************************//
00195 // void temperatureRecorder::convertToCelsius(void){                                            //
00196 // returns a float resulting from converting farenheit to celcius                               //  
00197 // Inputs: float Tfarenheit....Input Temperature in farenheit to be converted to Celsius        //                                                  //
00198 //**********************************************************************************************//
00199     float temperatureRecorder::convertToCelsius(float Tfarenheit){
00200         float Tc;
00201         Tc=(Tfarenheit-32.0)*5.0/9.0;
00202         return Tc;
00203     }
00204 
00205 //**********************************************************************************************//
00206 // void temperatureRecorder::convertToFarenheit(void){                                          //
00207 // returns a float resulting from converting celcius to farenheit                               //  
00208 // Inputs: float Tcelsius....Input Temperature in Celsius to be converted to farenheit          //                                                  //
00209 //**********************************************************************************************//
00210     float temperatureRecorder::convertToFarenheit(float Tcelsius){
00211         float Tf;
00212         Tf=(Tcelsius*9.0/5.0)+32.0;
00213         return Tf;
00214     }
00215 
00216 //**********************************************************************************************//
00217 // void temperatureRecorder::isTemperatureInFarenheit(void){                                    //
00218 // returns a BOOL value which is true if the current units are farenheit otherwise false        //  
00219 // Inputs: void                                                                                 //
00220 //**********************************************************************************************//
00221     bool temperatureRecorder::isTemperatureInFarenheit(void){
00222         return this->temperatureInFarenheit;
00223     }
00224     
00225 //**********************************************************************************************//
00226 // void temperatureRecorder::enableExternalSensor(void){                                        //
00227 // enables the external sensor mode which allows for manual setting of the temperature          //  
00228 // Inputs: void                                                                                 //
00229 //**********************************************************************************************//
00230     void temperatureRecorder::enableExternalSensor(void){
00231                 this->externalSensor=true;
00232     }
00233     
00234 //**********************************************************************************************//
00235 // void temperatureRecorder::enableExternalSensor(void){                                        //
00236 // disables the external sensor mode which allows for manual setting of the temperature          //  
00237 // Inputs: void                                                                                 //
00238 //**********************************************************************************************//
00239     void temperatureRecorder::disableExternalSensor(void){
00240                 this->externalSensor=false;
00241     }
00242 
00243 //**********************************************************************************************//
00244 // void temperatureRecorder::inputExternalSensorTemperatureInC(float inputTemperatureInC)){     //
00245 // sets the external sensor temperature which is what is recorded and processed when then       //
00246 // the externalSensor flag is set to true. this enables feeding a synthetic temperature         //
00247 // waveform for testing purposes
00248 // Inputs: void                                                                                 //
00249 //**********************************************************************************************//
00250     void temperatureRecorder::inputExternalSensorTemperatureInC(float inputTemperatureInC){
00251                 this->externalSensorTemperatureInC=inputTemperatureInC;
00252     }
00253