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.
136 lines
2.6 KiB
C++
136 lines
2.6 KiB
C++
7 months ago
|
/*
|
||
|
* FanTimerControl.cpp
|
||
|
*
|
||
|
* Author: Aleksey Gerasimenko
|
||
|
* gerasimenko.aleksey.n@gmail.com
|
||
|
*/
|
||
|
|
||
|
#include "SYSCTRL/FanTimerControl.h"
|
||
|
|
||
|
namespace SYSCTRL
|
||
|
{
|
||
|
|
||
|
FanTimerControl::FanTimerControl():
|
||
|
m_mode(SYSCTRL::FanTimerControl::UNDEFINED),
|
||
|
m_time_sample(-1.0),
|
||
|
m_timer_counter(FP_ZERO),
|
||
|
m_timer_period(FP_ZERO),
|
||
|
m_state(false),
|
||
|
_execute(&SYSCTRL::FanTimerControl::_execute_undef)
|
||
|
{}//
|
||
|
|
||
|
|
||
|
void FanTimerControl::setup(float time_sample)
|
||
|
{
|
||
|
if(m_mode == SYSCTRL::FanTimerControl::UNDEFINED)
|
||
|
{
|
||
|
if(time_sample >= FP_ZERO)
|
||
|
{
|
||
|
m_time_sample = time_sample;
|
||
|
m_mode = SYSCTRL::FanTimerControl::CONFIGURATE;
|
||
|
//
|
||
|
}//if
|
||
|
//
|
||
|
}//if
|
||
|
//
|
||
|
}//
|
||
|
//
|
||
|
void FanTimerControl::configure(const FanTimerControlConfiguration& config)
|
||
|
{
|
||
|
if(compare(SYSCTRL::FanTimerControl::CONFIGURATE))
|
||
|
{
|
||
|
if(config.timer_period > m_time_sample)
|
||
|
{
|
||
|
m_timer_period = config.timer_period;
|
||
|
m_timer_counter = config.timer_period;
|
||
|
m_mode = SYSCTRL::FanTimerControl::OPERATIONAL;
|
||
|
_execute = &SYSCTRL::FanTimerControl::_execute_operational;
|
||
|
//
|
||
|
}//if
|
||
|
//
|
||
|
}//if
|
||
|
//
|
||
|
//
|
||
|
}//
|
||
|
//
|
||
|
FanTimerControl::mode_t FanTimerControl::get_mode()
|
||
|
{
|
||
|
return m_mode;
|
||
|
//
|
||
|
}//
|
||
|
//
|
||
|
bool FanTimerControl::compare(mode_t mode)
|
||
|
{
|
||
|
return m_mode == mode;
|
||
|
//
|
||
|
}//
|
||
|
//
|
||
|
#pragma CODE_SECTION("ramfuncs");
|
||
|
bool FanTimerControl::is_on()
|
||
|
{
|
||
|
return m_state;
|
||
|
//
|
||
|
}//
|
||
|
//
|
||
|
#pragma CODE_SECTION("ramfuncs");
|
||
|
bool FanTimerControl::is_off()
|
||
|
{
|
||
|
return !m_state;
|
||
|
//
|
||
|
}//
|
||
|
//
|
||
|
#pragma CODE_SECTION("ramfuncs");
|
||
|
void FanTimerControl::execute(bool is_switched_on, bool is_switched_off)
|
||
|
{
|
||
|
(this->*_execute)(is_switched_on, is_switched_off);
|
||
|
//
|
||
|
}//
|
||
|
//
|
||
|
#pragma CODE_SECTION("ramfuncs");
|
||
|
void FanTimerControl::_execute_undef(bool is_switched_on, bool is_switched_off)
|
||
|
{
|
||
|
//
|
||
|
}//
|
||
|
//
|
||
|
#pragma CODE_SECTION("ramfuncs");
|
||
|
void FanTimerControl::_execute_operational(bool is_switched_on, bool is_switched_off)
|
||
|
{
|
||
|
if(m_state)
|
||
|
{
|
||
|
// is on
|
||
|
if(m_timer_counter >= FP_ZERO)
|
||
|
{
|
||
|
m_timer_counter -= m_time_sample;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
m_state = false;
|
||
|
m_timer_counter = m_timer_period;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
// is off
|
||
|
if(is_switched_off)
|
||
|
{
|
||
|
m_state = true;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
m_timer_counter = m_timer_period;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
//
|
||
|
if(is_switched_on)
|
||
|
{
|
||
|
m_state = false;
|
||
|
m_timer_counter = m_timer_period;
|
||
|
}
|
||
|
//
|
||
|
}//
|
||
|
//
|
||
|
|
||
|
} /* namespace SYSCTRL */
|