relay: [#9] control the power mode

This commit is contained in:
Vasily Davydov 2023-05-13 01:05:49 +03:00
parent c468a0d828
commit b7196b769e
2 changed files with 69 additions and 7 deletions

View File

@ -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<Event::EventType>(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<ThreadCommon::CommonManagers*>(pvParams);
Relay r(manager->qm);
}
}

View File

@ -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},