From 404563f1315d1f67372e68765e765c8addad7d09 Mon Sep 17 00:00:00 2001 From: EmanueleDajko Date: Tue, 5 Dec 2023 12:24:28 +0100 Subject: [PATCH] Refactor WashingTask dependencies and initialization --- smart_bridge/src/tasks/WashingTask.cpp | 37 +++++++++++++++----------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/smart_bridge/src/tasks/WashingTask.cpp b/smart_bridge/src/tasks/WashingTask.cpp index 6164790..5b7978a 100644 --- a/smart_bridge/src/tasks/WashingTask.cpp +++ b/smart_bridge/src/tasks/WashingTask.cpp @@ -16,33 +16,40 @@ WashingTask::WashingTask(BlinkTask *blinkTask, this->blinkTask->setActive(false); // TODO: Check if this is necessary this->countDownTask = countDownTask; this->temperatureTask = temperatureTask; - this->init(1000); + this->countDownTask->setActive(false); + this->temperatureTask->setActive(false); + this->init(); this->setState(START_WASHING); } void WashingTask::tick() { - if (this->DependantTask::getDependency(0)->isCompleted()) + if (this->getDependency(0) != nullptr) { - switch (this->getState()) + if (this->DependantTask::getDependency(0)->isCompleted()) { - case START_WASHING: - handleStartWashing(); - break; + switch (this->getState()) + { + case START_WASHING: + handleStartWashing(); + break; - case STARTS_COUNTDOWN: - handleStartsCountdown(); - break; + case STARTS_COUNTDOWN: + handleStartsCountdown(); + break; - case ENDS_COUNTDOWN: - handleEndsCountdown(); - break; + case ENDS_COUNTDOWN: + handleEndsCountdown(); + break; - case ERROR: - handleError(); - break; + case ERROR: + handleError(); + break; + } } } + else + Serial.println("WashingTask::tick()::getDependency(0) is nullptr"); } void WashingTask::printWashingCompletedMessage()