relay: [#9] control the power mode
This commit is contained in:
parent
c468a0d828
commit
b7196b769e
@ -9,14 +9,17 @@
|
|||||||
#include "Event.h"
|
#include "Event.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
|
|
||||||
// TODO Remove en pins
|
|
||||||
RelayDevice::RelayDevice(uint8_t pha_pin,
|
RelayDevice::RelayDevice(uint8_t pha_pin,
|
||||||
uint8_t pha_port,
|
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);
|
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()
|
RelayDevice::~RelayDevice()
|
||||||
@ -24,6 +27,17 @@ RelayDevice::~RelayDevice()
|
|||||||
LOG_ERROR("Deleting 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)
|
Relay::Relay(ThreadCommon::QueueManager* qm): _qm(qm)
|
||||||
{
|
{
|
||||||
LOG_DEBUG("Creating Relay");
|
LOG_DEBUG("Creating Relay");
|
||||||
@ -34,6 +48,34 @@ Relay::~Relay()
|
|||||||
LOG_ERROR("Deleting 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()
|
void Relay::taskFunction()
|
||||||
{
|
{
|
||||||
Event data(Event::Null, 0);
|
Event data(Event::Null, 0);
|
||||||
@ -48,7 +90,7 @@ void Relay::parseEvent(Event* d)
|
|||||||
{
|
{
|
||||||
for (uint8_t i = Event::ExternalTemp; i <= Event::SetPoint; i++)
|
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)
|
if(rd == ERROR_RETURN)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
@ -60,8 +102,10 @@ void Relay::parseEvent(Event* d)
|
|||||||
break;
|
break;
|
||||||
case Event::SetPoint:
|
case Event::SetPoint:
|
||||||
setpoint = rd;
|
setpoint = rd;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
assert(0);
|
assert(0);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -71,4 +115,4 @@ void thread_relay(void * pvParams)
|
|||||||
{
|
{
|
||||||
ThreadCommon::CommonManagers * manager = static_cast<ThreadCommon::CommonManagers*>(pvParams);
|
ThreadCommon::CommonManagers * manager = static_cast<ThreadCommon::CommonManagers*>(pvParams);
|
||||||
Relay r(manager->qm);
|
Relay r(manager->qm);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,22 +11,40 @@
|
|||||||
#include "ThreadCommon.h"
|
#include "ThreadCommon.h"
|
||||||
#include "DigitalIoPin.h"
|
#include "DigitalIoPin.h"
|
||||||
#include "Counter.h"
|
#include "Counter.h"
|
||||||
|
#include "Event.h"
|
||||||
|
|
||||||
class RelayDevice {
|
class RelayDevice {
|
||||||
public:
|
public:
|
||||||
RelayDevice(uint8_t pha_pin,
|
RelayDevice(uint8_t pha_pin,
|
||||||
uint8_t pha_port,
|
uint8_t pha_port,
|
||||||
uint8_t relay_device_index);
|
uint8_t relay_device_index,
|
||||||
|
bool heat_output_1 = true);
|
||||||
virtual ~RelayDevice();
|
virtual ~RelayDevice();
|
||||||
|
void RelayOn();
|
||||||
|
void RelayOff();
|
||||||
private:
|
private:
|
||||||
DigitalIoPin * pha;
|
DigitalIoPin * pha;
|
||||||
|
bool heat_output_one;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Relay {
|
class Relay {
|
||||||
|
enum PowerMode
|
||||||
|
{
|
||||||
|
POWER_0,
|
||||||
|
POWER_1,
|
||||||
|
POWER_2,
|
||||||
|
POWER_3
|
||||||
|
};
|
||||||
|
enum RelayType
|
||||||
|
{
|
||||||
|
INF_RELAY,
|
||||||
|
SUP_RELAY
|
||||||
|
};
|
||||||
public:
|
public:
|
||||||
Relay(ThreadCommon::QueueManager* qm);
|
Relay(ThreadCommon::QueueManager* qm);
|
||||||
virtual ~Relay();
|
virtual ~Relay();
|
||||||
void taskFunction();
|
void taskFunction();
|
||||||
|
void setPowerMode(PowerMode pm);
|
||||||
private:
|
private:
|
||||||
ThreadCommon::QueueManager* _qm;
|
ThreadCommon::QueueManager* _qm;
|
||||||
RelayDevice relays [2] = {{0, 24, 0},
|
RelayDevice relays [2] = {{0, 24, 0},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user