From 868ba0cd0381033f213cabda1d8c382c4ecf29ce Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 28 Nov 2022 08:56:36 +0100 Subject: [PATCH] improvements for heater handler --- mission/controller/ThermalController.cpp | 18 ++++++++++-------- mission/controller/ThermalController.h | 3 +-- mission/devices/HeaterHandler.cpp | 9 +++++++-- mission/devices/HeaterHandler.h | 8 ++++---- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/mission/controller/ThermalController.cpp b/mission/controller/ThermalController.cpp index f4ada487..aeaeb209 100644 --- a/mission/controller/ThermalController.cpp +++ b/mission/controller/ThermalController.cpp @@ -105,23 +105,25 @@ void ThermalController::performControlOperation() { } // TODO: Heater control - //TODO: Hysterese offset - if(heaterHandler.heaterVec[heater::HEATER_4_CAMERA].switchState == HeaterHandler::SwitchState::OFF){ - if(sensorTemperatures.sensor_4k_camera.value < cameraLimits.opLowerLimit) { + // TODO: Hysterese offset + if (heaterHandler.heaterVec[heater::HEATER_4_CAMERA].switchState == + HeaterHandler::SwitchState::OFF) { + if (sensorTemperatures.sensor_4k_camera.value < cameraLimits.opLowerLimit) { heaterHandler.heaterVec[heater::HEATER_4_CAMERA].cmdActive = true; heaterHandler.heaterVec[heater::HEATER_4_CAMERA].action = HeaterHandler::SET_SWITCH_ON; heaterHandler.handleSwitchOnCommand(heater::HEATER_4_CAMERA); heater4Countdown.resetTimer(); } - }else if(heaterHandler.heaterVec[heater::HEATER_4_CAMERA].switchState == HeaterHandler::SwitchState::ON){ - if(sensorTemperatures.sensor_4k_camera.value < cameraLimits.opLowerLimit){ - if(heater4Countdown.hasTimedOut()){ + } else if (heaterHandler.heaterVec[heater::HEATER_4_CAMERA].switchState == + HeaterHandler::SwitchState::ON) { + if (sensorTemperatures.sensor_4k_camera.value < cameraLimits.opLowerLimit) { + if (heater4Countdown.hasTimedOut()) { heaterHandler.heaterVec[heater::HEATER_4_CAMERA].cmdActive = true; heaterHandler.heaterVec[heater::HEATER_4_CAMERA].action = HeaterHandler::SET_SWITCH_OFF; - //triggerEvent(HEATER_TIMEOUT, heater::HEATER_4_CAMERA); + // triggerEvent(HEATER_TIMEOUT, heater::HEATER_4_CAMERA); heaterHandler.handleSwitchOffCommand(heater::HEATER_4_CAMERA); } - }else { + } else { heaterHandler.heaterVec[heater::HEATER_4_CAMERA].cmdActive = true; heaterHandler.heaterVec[heater::HEATER_4_CAMERA].action = HeaterHandler::SET_SWITCH_OFF; heaterHandler.handleSwitchOffCommand(heater::HEATER_4_CAMERA); diff --git a/mission/controller/ThermalController.h b/mission/controller/ThermalController.h index ab8eff0a..a91e531d 100644 --- a/mission/controller/ThermalController.h +++ b/mission/controller/ThermalController.h @@ -53,11 +53,10 @@ class ThermalController : public ExtendedControllerBase { private: static const uint32_t DELAY = 500; - static const uint32_t OP_TIME = 1000; //TODO to be changed + static const uint32_t OP_TIME = 1000; // TODO to be changed enum class InternalState { STARTUP, INITIAL_DELAY, READY }; - InternalState internalState = InternalState::STARTUP; HeaterHandler& heaterHandler; diff --git a/mission/devices/HeaterHandler.cpp b/mission/devices/HeaterHandler.cpp index 61a44de6..a2e4a451 100644 --- a/mission/devices/HeaterHandler.cpp +++ b/mission/devices/HeaterHandler.cpp @@ -321,8 +321,13 @@ HeaterHandler::SwitchState HeaterHandler::checkSwitchState(heater::Switchers swi return heaterVec.at(switchNr).switchState; } -ReturnValue_t HeaterHandler::switchHeater(heater::Switchers heater, ReturnValue_t onOff) { - return sendSwitchCommand(heater, onOff); +ReturnValue_t HeaterHandler::switchHeater(heater::Switchers heater, SwitchState switchState) { + if (switchState == SwitchState::ON) { + return sendSwitchCommand(heater, PowerSwitchIF::SWITCH_ON); + } else if (switchState == SwitchState::OFF) { + return sendSwitchCommand(heater, PowerSwitchIF::SWITCH_OFF); + } + return returnvalue::FAILED; } bool HeaterHandler::allSwitchesOff() { diff --git a/mission/devices/HeaterHandler.h b/mission/devices/HeaterHandler.h index 18bb7240..ede7c422 100644 --- a/mission/devices/HeaterHandler.h +++ b/mission/devices/HeaterHandler.h @@ -64,7 +64,10 @@ class HeaterHandler : public ExecutableObjectIF, virtual ~HeaterHandler(); protected: - ReturnValue_t switchHeater(heater::Switchers heater, ReturnValue_t onOff); + enum SwitchState : bool { ON = true, OFF = false }; + enum SwitchAction : uint8_t { SET_SWITCH_OFF, SET_SWITCH_ON, NONE }; + + ReturnValue_t switchHeater(heater::Switchers heater, SwitchState switchState); ReturnValue_t performOperation(uint8_t operationCode = 0) override; ReturnValue_t sendSwitchCommand(uint8_t switchNr, ReturnValue_t onOff) override; @@ -96,9 +99,6 @@ class HeaterHandler : public ExecutableObjectIF, static const MessageQueueId_t NO_COMMANDER = 0; - enum SwitchState : bool { ON = true, OFF = false }; - enum SwitchAction : uint8_t { SET_SWITCH_OFF, SET_SWITCH_ON, NONE }; - /** * @brief Struct holding information about a heater command to execute. *