MotorControlModuleSDFM_TMS3.../Projects/EFC_Communication/UMLibrary/driver/DiscreteOutputDelayed.cpp
2024-06-07 11:12:56 +03:00

45 lines
1.0 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* DiscreteOutputDelayed.cpp
*
* Created on: 12 янв. 2018 г.
* Author: titov
*/
#include "DiscreteOutputDelayed.hh"
void driver::detail::DiscreteOutputDelayed::on() {
gpio_pin.write(active_level);
if( not prev_state_on )
timer_completed.start(timeout);
prev_state_on = true;
}
void driver::detail::DiscreteOutputDelayed::off() {
gpio_pin.write(!active_level);
if( prev_state_on )
timer_completed.start(timeout);
prev_state_on = false;
}
bool driver::detail::DiscreteOutputDelayed::isCompleted() const {
return timer_completed.delayElapsed();
}
driver::detail::DiscreteOutputDelayed::DiscreteOutputDelayed(
peripheral::IGpio & gpio_pin, bool active_level,
unsigned int timeout_in_ms) :
gpio_pin(gpio_pin), active_level(active_level), timeout(timeout_in_ms), prev_state_on(false) {
gpio_pin.write(!active_level);
timer_completed.start(timeout);
}
driver::detail::DiscreteOutputDelayed::~DiscreteOutputDelayed() noexcept {
gpio_pin.write(!active_level);
}