From b7196b769edbd2510ee34e2b13c49e1ed28c03f6 Mon Sep 17 00:00:00 2001 From: Vasily Davydov Date: Sat, 13 May 2023 01:05:49 +0300 Subject: [PATCH] relay: [#9] control the power mode --- source/shoh/src/threads/relay/Relay.cpp | 56 ++++++++++++++++++++++--- source/shoh/src/threads/relay/Relay.h | 20 ++++++++- 2 files changed, 69 insertions(+), 7 deletions(-) diff --git a/source/shoh/src/threads/relay/Relay.cpp b/source/shoh/src/threads/relay/Relay.cpp index 9e3adb7..d6013f8 100644 --- a/source/shoh/src/threads/relay/Relay.cpp +++ b/source/shoh/src/threads/relay/Relay.cpp @@ -9,14 +9,17 @@ #include "Event.h" #include "Log.h" -// TODO Remove en pins RelayDevice::RelayDevice(uint8_t pha_pin, uint8_t pha_port, - uint8_t relay_device_index - ) + uint8_t relay_device_index, + bool heat_output_1 + ) : + heat_output_one(heat_output_1) { pha = new DigitalIoPin(pha_pin, pha_port, false); - LOG_DEBUG("Creating RelayDevice"); + LOG_DEBUG("Creating RelayDevice with output %d", + heat_output_one ? 1 : 2); + pha->write(heat_output_one); } RelayDevice::~RelayDevice() @@ -24,6 +27,17 @@ RelayDevice::~RelayDevice() LOG_ERROR("Deleting RelayDevice"); } +void inline RelayDevice::RelayOn() +{ + pha->write(!heat_output_one); +} + +void inline RelayDevice::RelayOff() +{ + pha->write(heat_output_one); +} + + Relay::Relay(ThreadCommon::QueueManager* qm): _qm(qm) { LOG_DEBUG("Creating Relay"); @@ -34,6 +48,34 @@ Relay::~Relay() LOG_ERROR("Deleting Relay"); } +void Relay::setPowerMode(PowerMode pm) +{ + switch (pm) + { + case PowerMode::POWER_0: + relays[INF_RELAY].RelayOff(); + relays[SUP_RELAY].RelayOff(); + LOG_INFO("Heater is turned OFF"); + case PowerMode::POWER_1: + relays[INF_RELAY].RelayOn(); + relays[SUP_RELAY].RelayOff(); + LOG_INFO("Heater using power mode 1"); + break; + case PowerMode::POWER_2: + relays[INF_RELAY].RelayOff(); + relays[SUP_RELAY].RelayOn(); + LOG_INFO("Heater using power mode 2"); + break; + case PowerMode::POWER_3: + relays[INF_RELAY].RelayOn(); + relays[SUP_RELAY].RelayOn(); + LOG_INFO("Heater using power mode 3"); + break; + default: + break; + } +} + void Relay::taskFunction() { Event data(Event::Null, 0); @@ -48,7 +90,7 @@ void Relay::parseEvent(Event* d) { for (uint8_t i = Event::ExternalTemp; i <= Event::SetPoint; i++) { - EventRawData rd = data.getDataOf(i); + EventRawData rd = d->getDataOf(static_cast(i)); if(rd == ERROR_RETURN) { continue; @@ -60,8 +102,10 @@ void Relay::parseEvent(Event* d) break; case Event::SetPoint: setpoint = rd; + break; default: assert(0); + break; } } @@ -71,4 +115,4 @@ void thread_relay(void * pvParams) { ThreadCommon::CommonManagers * manager = static_cast(pvParams); Relay r(manager->qm); -} \ No newline at end of file +} diff --git a/source/shoh/src/threads/relay/Relay.h b/source/shoh/src/threads/relay/Relay.h index b46c2d2..7f92424 100644 --- a/source/shoh/src/threads/relay/Relay.h +++ b/source/shoh/src/threads/relay/Relay.h @@ -11,22 +11,40 @@ #include "ThreadCommon.h" #include "DigitalIoPin.h" #include "Counter.h" +#include "Event.h" class RelayDevice { public: RelayDevice(uint8_t pha_pin, uint8_t pha_port, - uint8_t relay_device_index); + uint8_t relay_device_index, + bool heat_output_1 = true); virtual ~RelayDevice(); + void RelayOn(); + void RelayOff(); private: DigitalIoPin * pha; + bool heat_output_one; }; class Relay { + enum PowerMode + { + POWER_0, + POWER_1, + POWER_2, + POWER_3 + }; + enum RelayType + { + INF_RELAY, + SUP_RELAY + }; public: Relay(ThreadCommon::QueueManager* qm); virtual ~Relay(); void taskFunction(); + void setPowerMode(PowerMode pm); private: ThreadCommon::QueueManager* _qm; RelayDevice relays [2] = {{0, 24, 0},