/* * Detector.cpp * * Created on: Apr 5, 2018 * Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert, Rafael Vinci, Dr. Franca Rupprecht */ #include "Detector.h" #include #include #include "../utilities/config.h" namespace Input { Detector::Detector(InputGPIOInterface* input_gpio_interface, std::map events, EventNotifier* event_notifier) : input_gpio_interface(input_gpio_interface), events(events), is_running(true), event_notifier(event_notifier) { detect_thread = std::thread(&Detector::detect, this); } Detector::~Detector() { is_running = false; detect_thread.join(); delete this->input_gpio_interface; this->input_gpio_interface = NULL; delete this->event_notifier; this->event_notifier = NULL; } // Cycles over all s and enqueues an event if detected. void Detector::detect() { while(is_running) { char address; if(check_inputs(address)) { try { Event& event = events.at(address); event_notifier->distribute_event(event); } catch(std::out_of_range& e) { CLOG(WARNING, INPUT_LOGGER) << "Did not found event for address: " << address << " check config-file"; } } } } bool Detector::check_inputs(char& address) { for(int pin = 0; pin < MATRIX_SIZE * MATRIX_SIZE; pin++) { if(input_gpio_interface->read_input_data(pin)) { address = pin; return true; } } return false; } }