fixed distribution event
This commit is contained in:
@@ -5,18 +5,47 @@
|
||||
#include "DistributingEvent.h"
|
||||
|
||||
FlippR_Driver::Input::DistributingEvent::DistributingEvent(char address, int priority, std::string name,
|
||||
std::chrono::milliseconds deactivation_time, std::shared_ptr<IEventNotifier> event_notifier)
|
||||
: Event(address, priority, name), deactivation_time(deactivation_time), event_notifier(event_notifier)
|
||||
std::chrono::milliseconds bounce_time, std::shared_ptr<IEventNotifier> event_notifier)
|
||||
: Event(address, priority, name), bounce_time(bounce_time), event_notifier(event_notifier)
|
||||
{}
|
||||
|
||||
void FlippR_Driver::Input::DistributingEvent::distribute()
|
||||
{
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> now = std::chrono::high_resolution_clock::now();
|
||||
std::chrono::milliseconds elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(now - last_activation);
|
||||
if(elapsed_time > deactivation_time)
|
||||
event_notifier->distribute_event(*this);
|
||||
}
|
||||
|
||||
void FlippR_Driver::Input::DistributingEvent::active()
|
||||
{
|
||||
if(!is_bouncing())
|
||||
{
|
||||
event_notifier->distribute_event(*this);
|
||||
this->last_activation = now;
|
||||
if(activation_state != ACTIVATED)
|
||||
{
|
||||
activation_state = static_cast<ActivationState>(static_cast<int>(activation_state) + 1);
|
||||
}
|
||||
|
||||
last_activation = std::chrono::high_resolution_clock::now();
|
||||
|
||||
if(activation_state == ACTIVATED)
|
||||
{
|
||||
this->distribute();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool FlippR_Driver::Input::DistributingEvent::is_bouncing()
|
||||
{
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> now = std::chrono::high_resolution_clock::now();
|
||||
std::chrono::milliseconds elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(now - last_activation);
|
||||
|
||||
return elapsed_time < bounce_time;
|
||||
}
|
||||
|
||||
void FlippR_Driver::Input::DistributingEvent::inactive()
|
||||
{
|
||||
if(activation_state == 2)
|
||||
{
|
||||
this->last_activation = std::chrono::high_resolution_clock::now();
|
||||
activation_state = ActivationState::NOT_ACTIVATED;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user