diff --git a/smart_bridge/src/tasks/CountDown.cpp b/smart_bridge/src/tasks/CountDown.cpp index 07b5cdc..1ffafef 100644 --- a/smart_bridge/src/tasks/CountDown.cpp +++ b/smart_bridge/src/tasks/CountDown.cpp @@ -2,6 +2,7 @@ CountDown::CountDown(int countDown) : Task() { + Serial.println("CountDownTask created"); this->setStatus(false); this->lcd = new LCD(0x27, 16, 2); this->resetCountDown(N3); diff --git a/smart_bridge/src/tasks/TemperatureTask.cpp b/smart_bridge/src/tasks/TemperatureTask.cpp index e1681e9..5b60edd 100644 --- a/smart_bridge/src/tasks/TemperatureTask.cpp +++ b/smart_bridge/src/tasks/TemperatureTask.cpp @@ -1,8 +1,8 @@ #include "TemperatureTask.h" TemperatureTask::TemperatureTask() - : Task(), - voltageConversionFactor(100), + : TaskWithTimer(), + voltageConversionFactor(30), voltageOffset(0.5) { Serial.println("TemperatureTask created"); @@ -39,25 +39,21 @@ void TemperatureTask::setTemperature(int temperature) void TemperatureTask::printTemperature() { int temp = getTemperature(); - lcd->write(("Temperature: " + String(temp) + "°C").c_str(), 0, 0); + lcd->write(("Temperature: " + String(temp) + (char)223 + "C").c_str(), 0, 0); } bool TemperatureTask::checkForCriticalTemperature() { if (temperature > MAXTEMP) { - if (timeExceededMaxTemp == 0) - { - timeExceededMaxTemp = millis(); - } - else if (millis() - timeExceededMaxTemp >= N5 * 1000) + if (this->elapsedTime() >= N5 * 1000) { return true; } } else { - timeExceededMaxTemp = 0; + this->resetTime(); } return false; } diff --git a/smart_bridge/src/tasks/TemperatureTask.h b/smart_bridge/src/tasks/TemperatureTask.h index 48c97fc..00a4c71 100644 --- a/smart_bridge/src/tasks/TemperatureTask.h +++ b/smart_bridge/src/tasks/TemperatureTask.h @@ -1,7 +1,7 @@ #ifndef __TEMPERATURE_TASK__ #define __TEMPERATURE_TASK__ -#include "kernel/Task.h" +#include "kernel/TaskWithTimer.h" #include "Arduino.h" #include "config/config.h" #include "components/api/LCD.h" @@ -14,7 +14,7 @@ * * @extends Task */ -class TemperatureTask : public Task +class TemperatureTask : public TaskWithTimer { public: /** diff --git a/smart_bridge/src/tasks/WashingTask.cpp b/smart_bridge/src/tasks/WashingTask.cpp index 4215930..6164790 100644 --- a/smart_bridge/src/tasks/WashingTask.cpp +++ b/smart_bridge/src/tasks/WashingTask.cpp @@ -53,26 +53,33 @@ void WashingTask::printWashingCompletedMessage() void WashingTask::handleStartWashing() { this->blinkTask->setActive(true); + this->countDownTask->setActive(true); + this->temperatureTask->setActive(true); this->setState(STARTS_COUNTDOWN); } void WashingTask::handleStartsCountdown() { - this->countDownTask->tick(); - this->temperatureTask->tick(); - if (this->temperatureTask->checkForCriticalTemperature() == true && this->countDownTask->getStatus() == false) + // this->countDownTask->tick(); + // this->temperatureTask->tick(); + if (this->elapsedTime() >= checkInterval) { - this->setState(ERROR); - } - if (this->countDownTask->getStatus() == true) - { - this->setState(ENDS_COUNTDOWN); + this->resetTime(); + if (this->temperatureTask->checkForCriticalTemperature() == true && this->countDownTask->getStatus() == false) + { + this->setState(ERROR); + } + if (this->countDownTask->getStatus() == true) + { + this->setState(ENDS_COUNTDOWN); + } } } void WashingTask::handleEndsCountdown() { this->countDownTask->endsCountDown(); + this->temperatureTask->setCompleted(); this->blinkTask->setActive(false); this->L3->switchOn(); this->printWashingCompletedMessage(); diff --git a/smart_bridge/src/tasks/WashingTask.h b/smart_bridge/src/tasks/WashingTask.h index 735fa30..5745b53 100644 --- a/smart_bridge/src/tasks/WashingTask.h +++ b/smart_bridge/src/tasks/WashingTask.h @@ -86,9 +86,10 @@ class WashingTask : public DependantTaskWithState ERROR, ///< The task is currently handling an error. }; - int savedCountDown; - unsigned long savedTimeInState; - int countDown; + int savedCountDown; ///< The saved value of the countdown. + unsigned long savedTimeInState; ///< The time that the task has been in the current state. + int checkInterval = 5000; ///< 5 seconds + int countDown; ///< The current value of the countdown. Led *L2; ///< Pointer to the L2 LED object. Led *L3; ///< Pointer to the L3 LED object. Temp *tempSensor; ///< Pointer to the temperature sensor object.