Thermostat class implements basic functionality of a thermostat

Committer:
nleoni
Date:
Fri Feb 21 06:59:01 2014 +0000
Revision:
1:909cb1aef872
Parent:
0:cd3a00aa2dbc
1st checkin of Thermostat class: includes class tests

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nleoni 0:cd3a00aa2dbc 1 //Thermostat class
nleoni 0:cd3a00aa2dbc 2 //Napoleon Leoni
nleoni 0:cd3a00aa2dbc 3 //Thermostat with Joystick control input
nleoni 0:cd3a00aa2dbc 4 //Class Thermostat:
nleoni 0:cd3a00aa2dbc 5 //Has a control loop enable/disable(I will refer to this as Heater on/off), an over-ride enable/disable.
nleoni 0:cd3a00aa2dbc 6 //an object TemperatureRecording (keeps current temperature, max and min since last reset
nleoni 0:cd3a00aa2dbc 7 //and circular buffer with recorded data)
nleoni 0:cd3a00aa2dbc 8 //Functions to check user input on joystick
nleoni 0:cd3a00aa2dbc 9 //sets interrupt on accelerometer (To be implemented)
nleoni 0:cd3a00aa2dbc 10
nleoni 1:909cb1aef872 11 //***************************** TESTING ********************************************************//
nleoni 1:909cb1aef872 12 // TEST TEST DESCRIPTION STATUS //
nleoni 1:909cb1aef872 13 // 1 Time display is inceremented in seconds and date shown PASS //
nleoni 1:909cb1aef872 14 // corresponds to date set in code //
nleoni 1:909cb1aef872 15 // 2 Joystick input works as expected up/down to increase PASS //
nleoni 1:909cb1aef872 16 // decrease the temperature settting by the selected //
nleoni 1:909cb1aef872 17 // granularity and left/right to turn heater on/off //
nleoni 1:909cb1aef872 18 // LCD display shows correct changes in values as well //
nleoni 1:909cb1aef872 19 // 3 Automated thermostatCycle test includes feeding a known PASS //
nleoni 1:909cb1aef872 20 // array of temperatures and verifying sample by sample that //
nleoni 1:909cb1aef872 21 // the thermostat loop is enabled when it should be. this loop //
nleoni 1:909cb1aef872 22 // also checks what happens when the heater is set to on or off //
nleoni 1:909cb1aef872 23 // this test issues a PASS status only if the results are correct //
nleoni 1:909cb1aef872 24 // for every sample
nleoni 1:909cb1aef872 25 //**********************************************************************************************//
nleoni 1:909cb1aef872 26
nleoni 0:cd3a00aa2dbc 27 #include "mbed.h"
nleoni 0:cd3a00aa2dbc 28 #include "LM75B.h"
nleoni 0:cd3a00aa2dbc 29 #include "temperatureRecorder.h"
nleoni 0:cd3a00aa2dbc 30 #include "joystickAppBoard.h"
nleoni 0:cd3a00aa2dbc 31
nleoni 0:cd3a00aa2dbc 32 #ifndef THERMOSTAT
nleoni 0:cd3a00aa2dbc 33 #define THERMOSTAT
nleoni 0:cd3a00aa2dbc 34 #define DEFAULTHYSTERESYS 5 //degrees F, dead band of controller to prevent excessive turn on/off
nleoni 0:cd3a00aa2dbc 35 #define DEFAULTGRANULARITY 2 //degrees F, increment in temperaure setting per joystick click
nleoni 0:cd3a00aa2dbc 36 #define DEFAULTTEMPSETTING 60 //degrees F, default setting for thermostat
nleoni 0:cd3a00aa2dbc 37 #define DEFAULTMAXTEMPSETTING 96 //degrees F, max temperature setting to avoid user over shooting setting with joystick
nleoni 0:cd3a00aa2dbc 38 #define DEFAULTMINTEMPSETTING 44 //degrees F, min temperature setting to avoid user under shooting setting with joystick
nleoni 0:cd3a00aa2dbc 39 #define DEFAULTTIME
nleoni 0:cd3a00aa2dbc 40
nleoni 0:cd3a00aa2dbc 41 class thermostat{
nleoni 0:cd3a00aa2dbc 42 //public members
nleoni 0:cd3a00aa2dbc 43 public:
nleoni 0:cd3a00aa2dbc 44 //private members
nleoni 0:cd3a00aa2dbc 45 private:
nleoni 0:cd3a00aa2dbc 46 temperatureRecorder *trecord; //pointer to TemperatureRecordeObject
nleoni 0:cd3a00aa2dbc 47 joystickAppBoard *inputJoystick; //pointer to input joystick object
nleoni 0:cd3a00aa2dbc 48 DigitalOut *actuatorOutput; //pointer to Digital Output for actuator, this would run the relay for the heater
nleoni 0:cd3a00aa2dbc 49 //temporarily we could use an LED as output so that the heating action is signaled
nleoni 0:cd3a00aa2dbc 50 //by the turning on and off of an LED
nleoni 0:cd3a00aa2dbc 51 struct tm timeKeeper; //structure to hold date/time type
nleoni 0:cd3a00aa2dbc 52 time_t timeInSeconds; //variable to keep absolute time
nleoni 0:cd3a00aa2dbc 53 float hysteresisGap, temperatureGranularity, defaultTemperature, maxTemperature, minTemperature;
nleoni 0:cd3a00aa2dbc 54 bool heaterEnabled; //This flag corresponds to whether the thermostat control is on
nleoni 0:cd3a00aa2dbc 55 bool heatingActionOn; //this flag corresponds to whether the thermostat has turned the heating action (relay) on
nleoni 0:cd3a00aa2dbc 56 //public methods
nleoni 0:cd3a00aa2dbc 57 public:
nleoni 0:cd3a00aa2dbc 58 thermostat();//default constructor
nleoni 0:cd3a00aa2dbc 59 thermostat(temperatureRecorder *,joystickAppBoard *,DigitalOut *);//regular constructor
nleoni 0:cd3a00aa2dbc 60 void enableHeater(void);
nleoni 0:cd3a00aa2dbc 61 void disableHeater(void);
nleoni 0:cd3a00aa2dbc 62 void checkJoystickInput(void);
nleoni 0:cd3a00aa2dbc 63 void runThermostatControlCycle(void);
nleoni 0:cd3a00aa2dbc 64 float getTemperature(void);//Read current temperature
nleoni 0:cd3a00aa2dbc 65 float getMaxTemperature(void);//read Maximum Temperature
nleoni 0:cd3a00aa2dbc 66 float getMinTemperature(void);//read Maximum Temperature
nleoni 0:cd3a00aa2dbc 67 float getTemperatureSetting(void); //read temperature setting
nleoni 0:cd3a00aa2dbc 68 bool getThermostatStatus(void); //returns true if heaterEnabled, that is thermostat control is on
nleoni 0:cd3a00aa2dbc 69 void setDay(int,int,int);
nleoni 0:cd3a00aa2dbc 70 void setTime(int,int,int);
nleoni 0:cd3a00aa2dbc 71 void getDateandTime(char*,int); //return Date and time as a formatted string in the provided char buffer
nleoni 1:909cb1aef872 72 void ThermostatUnitTest(char *,int);//unit test for thermostat class, injects a synthetic temperature to test the operation
nleoni 0:cd3a00aa2dbc 73 //private methods
nleoni 0:cd3a00aa2dbc 74 private:
nleoni 0:cd3a00aa2dbc 75 }; //end of thermostat class prototype
nleoni 0:cd3a00aa2dbc 76 #endif