Program for the water play project for the course Software Testing Practical 2016 given at the VU University
Dependencies: mbed DRV88255 TextLCD Ping mbed-rtos
Diff: TemperatureController.cpp
- Revision:
- 13:1323e2c0b697
- Parent:
- 10:fd4670ec0806
- Child:
- 35:c9261391a995
--- a/TemperatureController.cpp Sat Jun 11 10:14:40 2016 +0000 +++ b/TemperatureController.cpp Sat Jun 11 13:19:20 2016 +0000 @@ -1,5 +1,6 @@ #include "TemperatureController.h" #include "rtos.h" +#include "testing.h" AnalogIn temperature_sensor(p20); DigitalOut heater(p18); @@ -16,6 +17,29 @@ this->temperature = readSensor(); } +bool TemperatureController::is_heating() { + return this->heating; +} + +void TemperatureController::set_heating(bool enabled) { + if(enabled == this->heating) return; + + this->heating = enabled; + if(enabled) { + #ifdef RUN_TESTS + printf("Should set heater to 1\r\n"); + #else + heater = 1; + #endif + } else { + #ifdef RUN_TESTS + printf("Should set heater to 0\r\n"); + #else + heater = 0; + #endif + } +} + // Function reads sensor values and averages N sensor values float TemperatureController::readSensor() { @@ -121,13 +145,6 @@ void TemperatureController::controlHeater() { - if(readSensor() < 32.0f) - { - //heater = 1; - printf("Should set heater to 1\r\n"); - } else { - //heater = 0; - printf("Should set heater to 0\r\n"); - } + this->set_heating(this->getValue() < 32.0f); } \ No newline at end of file