You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
200 lines
4.7 KiB
C++
200 lines
4.7 KiB
C++
/*
|
|
* FanControl.cpp
|
|
*
|
|
* Author: Aleksey Gerasimenko
|
|
* gerasimenko.aleksey.n@gmail.com
|
|
*/
|
|
|
|
#include "SYSCTRL/FanControl.h"
|
|
|
|
|
|
#define KM11_TURN_OFF (Uint16)0
|
|
#define KM11_TURN_ON (Uint16)1
|
|
|
|
namespace SYSCTRL
|
|
{
|
|
//CONSTRUCTOR
|
|
FanControl::FanControl():
|
|
m_mode(SYSCTRL::FanControl::UNDEFINED),
|
|
m_time_sample(-1.0),
|
|
m_contact_bounce_period(FP_ZERO),
|
|
m_voltage_level_on(FP_ZERO),
|
|
m_voltage_level_off(FP_ZERO),
|
|
m_km11_control(0),
|
|
m_km11t_control(0),
|
|
m_fan_state(false),
|
|
m_fault(false),
|
|
m_voltage_relay(),
|
|
m_delay_off_timer(),
|
|
m_control_state_timer(),
|
|
_execute(&SYSCTRL::FanControl::_execute_undef)
|
|
//
|
|
{}//CONSTRUCTOR
|
|
|
|
|
|
|
|
void FanControl::setup(float time_sample)
|
|
{
|
|
static bool status = true;
|
|
if(m_mode == SYSCTRL::FanControl::UNDEFINED)
|
|
{
|
|
m_time_sample = time_sample;
|
|
|
|
m_delay_off_timer.setup(m_time_sample);
|
|
m_control_state_timer.setup(m_time_sample);
|
|
|
|
status &= m_time_sample > FP_ZERO ? true : false;
|
|
status &= m_delay_off_timer.compare(FLTSYSLIB::FTimer::CONFIGURATE);
|
|
status &= m_control_state_timer.compare(FLTSYSLIB::FTimer::CONFIGURATE);
|
|
|
|
if(status)
|
|
{
|
|
m_mode = SYSCTRL::FanControl::CONFIGURATE;
|
|
//
|
|
}//if
|
|
//
|
|
}//if
|
|
//
|
|
}//setup()
|
|
//
|
|
void FanControl::configure(const FanControlConfiguration& config)
|
|
{
|
|
static bool status = true;
|
|
if(m_mode == SYSCTRL::FanControl::CONFIGURATE)
|
|
{
|
|
m_voltage_level_on = config.voltage_level_on;
|
|
m_voltage_level_off = config.voltage_level_off;
|
|
|
|
FLTSYSLIB::HysteresisConfiguration hyst_config;
|
|
hyst_config.level_high = 1.0;
|
|
hyst_config.level_low = FP_ZERO;
|
|
hyst_config.off = m_voltage_level_off;
|
|
hyst_config.on = m_voltage_level_on;
|
|
m_voltage_relay.configure(hyst_config);
|
|
|
|
FLTSYSLIB::FTimerConfiguration tm_config;
|
|
tm_config.period = config.delay_off_timer;
|
|
m_delay_off_timer.configure(tm_config);
|
|
tm_config.period = config.control_state_timer;
|
|
m_control_state_timer.configure(tm_config);
|
|
|
|
status &= m_voltage_relay.compare(FLTSYSLIB::Hysteresis::OPERATIONAL);
|
|
status &= m_delay_off_timer.compare(FLTSYSLIB::FTimer::OPERATIONAL);
|
|
status &= m_control_state_timer.compare(FLTSYSLIB::FTimer::OPERATIONAL);
|
|
|
|
if(status)
|
|
{
|
|
m_mode = SYSCTRL::FanControl::OPERATIONAL;
|
|
_execute = &SYSCTRL::FanControl::_execute_undef;
|
|
//
|
|
}//if
|
|
//
|
|
}//if
|
|
//
|
|
}//configure()
|
|
//
|
|
#pragma CODE_SECTION("ramfuncs");
|
|
SYSCTRL::FanControl::mode_t FanControl::get_mode()
|
|
{
|
|
return m_mode;
|
|
//
|
|
}//get_mode()
|
|
//
|
|
#pragma CODE_SECTION("ramfuncs");
|
|
bool FanControl::compare(SYSCTRL::FanControl::mode_t mode)
|
|
{
|
|
return m_mode == mode;
|
|
//
|
|
}//compare()
|
|
//
|
|
#pragma CODE_SECTION("ramfuncs");
|
|
Uint16 FanControl::get_km11_control()
|
|
{
|
|
return m_km11_control;
|
|
//
|
|
}//get_km11_control()
|
|
//
|
|
#pragma CODE_SECTION("ramfuncs");
|
|
Uint16 FanControl::get_km11t_control()
|
|
{
|
|
return m_km11t_control;
|
|
//
|
|
}//get_km11t_control()
|
|
//
|
|
#pragma CODE_SECTION("ramfuncs");
|
|
bool FanControl::is_on()
|
|
{
|
|
return m_fan_state;
|
|
//
|
|
}//is_on()
|
|
//
|
|
#pragma CODE_SECTION("ramfuncs");
|
|
bool FanControl::is_off()
|
|
{
|
|
return !m_fan_state;
|
|
//
|
|
}//is_off()
|
|
//
|
|
#pragma CODE_SECTION("ramfuncs");
|
|
bool FanControl::is_fault()
|
|
{
|
|
return m_fault;
|
|
//
|
|
}//get_fault()
|
|
//
|
|
#pragma CODE_SECTION("ramfuncs");
|
|
void FanControl::execute(float voltage, FLTSYSLIB::DigitalInput& aux_km)
|
|
{
|
|
(this->*_execute)(voltage, aux_km);
|
|
//
|
|
}//execute()
|
|
//
|
|
#pragma CODE_SECTION("ramfuncs");
|
|
void FanControl::_execute_undef(float voltage, FLTSYSLIB::DigitalInput& aux_km)
|
|
{
|
|
//
|
|
}//_execute_undef()
|
|
//
|
|
#pragma CODE_SECTION("ramfuncs");
|
|
void FanControl::_execute_operational(float voltage, FLTSYSLIB::DigitalInput& aux_km)
|
|
{
|
|
|
|
m_fan_state = aux_km.is_on();
|
|
m_voltage_relay.execute(voltage);
|
|
m_delay_off_timer.execute();
|
|
m_control_state_timer.execute();
|
|
|
|
|
|
if(m_voltage_relay.is_on())
|
|
{
|
|
m_km11_control = KM11_TURN_ON;
|
|
m_km11t_control = KM11_TURN_OFF;
|
|
m_delay_off_timer.reset();
|
|
}
|
|
else
|
|
{
|
|
if((m_delay_off_timer.is_running()) || (m_voltage_relay.is_switched_to_off()))
|
|
{
|
|
m_km11_control = KM11_TURN_OFF;
|
|
m_km11t_control = KM11_TURN_ON;
|
|
//
|
|
}//if
|
|
//
|
|
if(m_voltage_relay.is_switched_to_off())
|
|
{
|
|
m_delay_off_timer.start();
|
|
}//if
|
|
|
|
if(m_delay_off_timer.is_finished())
|
|
{
|
|
m_km11_control = KM11_TURN_OFF;
|
|
m_km11t_control = KM11_TURN_OFF;
|
|
//
|
|
}//if
|
|
//
|
|
}//if else
|
|
//
|
|
}//_execute_operational()
|
|
//
|
|
} /* namespace SYSCTRL */
|