From 4f9373ddfff96eb43b52e9c49b2839ad78676bf4 Mon Sep 17 00:00:00 2001 From: EmanueleDajko Date: Mon, 4 Dec 2023 17:09:43 +0100 Subject: [PATCH 1/8] Update temperature display format --- smart_bridge/src/tasks/TemperatureTask.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/smart_bridge/src/tasks/TemperatureTask.cpp b/smart_bridge/src/tasks/TemperatureTask.cpp index e1681e9..dbe7d84 100644 --- a/smart_bridge/src/tasks/TemperatureTask.cpp +++ b/smart_bridge/src/tasks/TemperatureTask.cpp @@ -2,7 +2,7 @@ TemperatureTask::TemperatureTask() : Task(), - voltageConversionFactor(100), + voltageConversionFactor(30), voltageOffset(0.5) { Serial.println("TemperatureTask created"); @@ -39,7 +39,7 @@ 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() From 12cfd65755f1597469a95269bf4c0c01b10cce00 Mon Sep 17 00:00:00 2001 From: EmanueleDajko Date: Mon, 4 Dec 2023 17:09:56 +0100 Subject: [PATCH 2/8] Fix issue with countDownTask and temperatureTask in handleStartsCountdown() method --- smart_bridge/src/tasks/WashingTask.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/smart_bridge/src/tasks/WashingTask.cpp b/smart_bridge/src/tasks/WashingTask.cpp index 4215930..5a8faa6 100644 --- a/smart_bridge/src/tasks/WashingTask.cpp +++ b/smart_bridge/src/tasks/WashingTask.cpp @@ -53,13 +53,15 @@ 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(); + // this->countDownTask->tick(); + // this->temperatureTask->tick(); if (this->temperatureTask->checkForCriticalTemperature() == true && this->countDownTask->getStatus() == false) { this->setState(ERROR); From c952a561b9b7b27156147c4cb8d639e325745126 Mon Sep 17 00:00:00 2001 From: EmanueleDajko Date: Mon, 4 Dec 2023 17:17:07 +0100 Subject: [PATCH 3/8] Add temperatureTask completion in WashingTask --- smart_bridge/src/tasks/WashingTask.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/smart_bridge/src/tasks/WashingTask.cpp b/smart_bridge/src/tasks/WashingTask.cpp index 5a8faa6..82cdb13 100644 --- a/smart_bridge/src/tasks/WashingTask.cpp +++ b/smart_bridge/src/tasks/WashingTask.cpp @@ -78,6 +78,7 @@ void WashingTask::handleEndsCountdown() this->blinkTask->setActive(false); this->L3->switchOn(); this->printWashingCompletedMessage(); + this->temperatureTask->setCompleted(); this->setCompleted(); } From 41fad5355772902b2792c9d92be0d5a3b19d1bb3 Mon Sep 17 00:00:00 2001 From: EmanueleDajko Date: Mon, 4 Dec 2023 17:17:18 +0100 Subject: [PATCH 4/8] Add debug message to CountDownTask constructor --- smart_bridge/src/tasks/CountDown.cpp | 1 + 1 file changed, 1 insertion(+) 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); From 34eeae4f36adbae80475dadf20e0effefded036a Mon Sep 17 00:00:00 2001 From: EmanueleDajko Date: Mon, 4 Dec 2023 18:14:20 +0100 Subject: [PATCH 5/8] Refactor WashingTask.h: Update variable names and add checkInterval --- smart_bridge/src/tasks/WashingTask.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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. From fae0ac34524fb776ec4e22858d854e002cb60e07 Mon Sep 17 00:00:00 2001 From: EmanueleDajko Date: Mon, 4 Dec 2023 18:14:27 +0100 Subject: [PATCH 6/8] Fix issue with handling countdown in WashingTask --- smart_bridge/src/tasks/WashingTask.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/smart_bridge/src/tasks/WashingTask.cpp b/smart_bridge/src/tasks/WashingTask.cpp index 82cdb13..6164790 100644 --- a/smart_bridge/src/tasks/WashingTask.cpp +++ b/smart_bridge/src/tasks/WashingTask.cpp @@ -62,23 +62,27 @@ void WashingTask::handleStartsCountdown() { // this->countDownTask->tick(); // this->temperatureTask->tick(); - if (this->temperatureTask->checkForCriticalTemperature() == true && this->countDownTask->getStatus() == false) + 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(); - this->temperatureTask->setCompleted(); this->setCompleted(); } From ca9f5349cc2846bdcd47f96d2001330db10309d5 Mon Sep 17 00:00:00 2001 From: EmanueleDajko Date: Mon, 4 Dec 2023 18:14:34 +0100 Subject: [PATCH 7/8] Update TemperatureTask to inherit from TaskWithTimer --- smart_bridge/src/tasks/TemperatureTask.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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: /** From 4657bfd85751da6416b7333b5e8f30a6bdc7d1f0 Mon Sep 17 00:00:00 2001 From: EmanueleDajko Date: Mon, 4 Dec 2023 18:14:41 +0100 Subject: [PATCH 8/8] Refactor TemperatureTask class --- smart_bridge/src/tasks/TemperatureTask.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/smart_bridge/src/tasks/TemperatureTask.cpp b/smart_bridge/src/tasks/TemperatureTask.cpp index dbe7d84..5b60edd 100644 --- a/smart_bridge/src/tasks/TemperatureTask.cpp +++ b/smart_bridge/src/tasks/TemperatureTask.cpp @@ -1,7 +1,7 @@ #include "TemperatureTask.h" TemperatureTask::TemperatureTask() - : Task(), + : TaskWithTimer(), voltageConversionFactor(30), voltageOffset(0.5) { @@ -46,18 +46,14 @@ 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; }