working on big refactor
This commit is contained in:
55
FlippR-Driver/src/input/impl/Detector.cpp
Normal file
55
FlippR-Driver/src/input/impl/Detector.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Detector.cpp
|
||||
*
|
||||
* Created on: Apr 5, 2018
|
||||
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
|
||||
*/
|
||||
|
||||
#include "Detector.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "utility/config.h"
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace input
|
||||
{
|
||||
namespace impl
|
||||
{
|
||||
|
||||
Detector::Detector(std::unique_ptr<InputPinController> input_gpio_interface, std::vector<std::shared_ptr<DistributingEvent>> events)
|
||||
:
|
||||
input_gpio_interface(std::move(input_gpio_interface)), events(std::move(events)), is_running(true)
|
||||
{
|
||||
this->detect_thread = std::thread(&Detector::detect, this);
|
||||
|
||||
CLOG(INFO, INPUT_LOGGER) << "Created Detector and started detecting!";
|
||||
}
|
||||
|
||||
Detector::~Detector()
|
||||
{
|
||||
this->is_running = false;
|
||||
|
||||
this->detect_thread.join();
|
||||
}
|
||||
|
||||
void Detector::detect()
|
||||
{
|
||||
while(this->is_running)
|
||||
{
|
||||
check_inputs();
|
||||
}
|
||||
}
|
||||
|
||||
void Detector::check_inputs()
|
||||
{
|
||||
for(auto &event : events)
|
||||
{
|
||||
input_gpio_interface->read_data(event->address) ? event->active() : event->inactive();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user