Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: Thermostat.cpp
- Revision:
- 5:4cbe44452889
- Parent:
- 2:ed17e258da0d
- Child:
- 13:142a142a7ac5
diff -r d8914369bf82 -r 4cbe44452889 Thermostat.cpp
--- a/Thermostat.cpp Fri Jun 17 09:24:01 2016 +0000
+++ b/Thermostat.cpp Fri Jun 17 11:03:37 2016 +0000
@@ -6,44 +6,51 @@
#include "mbed.h"
Thermostat::Thermostat(
- mbed::Serial &serial,
+ Printer &printer,
PinName pin,
PinName led_pin
):
- _serial(serial),
+ _printer(printer),
_analog_out(pin),
- _led(led_pin)
+ _led(led_pin),
+ _status(STATUS_OFF)
{
- off();
+}
+
+int Thermostat::update(){
+ this->_analog_out = this->_status;
+ this->_led = this->_status;
+
+ return(this->_status);
}
int Thermostat::on()
{
- this->_analog_out = 1;
- this->_led = 1;
- _serial.printf("thermostat: ON\n\r");
-
- return(this->_analog_out);
+ this->_status = STATUS_ON;
+ this->_strStatus = "Thermostat: ON\n\r";
+ return(this->_status);
}
int Thermostat::off()
{
- this->_analog_out = 0;
- this->_led = 0;
- _serial.printf("thermostat: OFF\n\r");
-
- return(this->_analog_out);
+ this->_status = STATUS_OFF;
+ this->_strStatus = "Thermostat: OFF\n\r";
+ return(this->_status);
}
int Thermostat::react(double temperature)
{
int retVal = 0;
-
- if(temperature < 0.0){
+
+ if(temperature < 0.0) {
retVal = this->on();
- }else{
+ } else {
retVal = this->off();
}
-
+
return(retVal);
+}
+
+char* Thermostat::getStrStatus(){
+ return(this->_strStatus);
}
\ No newline at end of file