From 744f25c19cebaa2794c03943dfbde64723da15ab Mon Sep 17 00:00:00 2001 From: Jonas Zeunert Date: Mon, 7 May 2018 18:50:17 +0200 Subject: [PATCH] commenting and fixing bugs --- FlippR-Driver/src/input/Detector.cpp | 17 +++++++++++++---- FlippR-Driver/src/input/Detector.h | 6 ++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/FlippR-Driver/src/input/Detector.cpp b/FlippR-Driver/src/input/Detector.cpp index d6ffd2b..89007d2 100644 --- a/FlippR-Driver/src/input/Detector.cpp +++ b/FlippR-Driver/src/input/Detector.cpp @@ -27,8 +27,8 @@ Detector::~Detector() { is_running = false; - detect_thread.join(); notify_thread.join(); + detect_thread.join(); } void Detector::register_input_event_handler(InputEventHandler* handler) @@ -61,12 +61,13 @@ void Detector::notify_handlers() LOCK_EVENT_HANDLER(); for(auto* handler : event_handler) { + // todo timeout! handler->handle(event); } } } - +// Cycles over all inputs and enqueues an input event if detected. void Detector::detect() { while(is_running) @@ -74,12 +75,20 @@ void Detector::detect() char address; if(check_inputs(address)) { - InputEvent& event = input_events.at(address); - event_queue.emplace(event); + try + { + InputEvent& event = input_events.at(address); + event_queue.emplace(event); + } + catch(std::out_of_range& e) + { + // todo log exception! + } } } } +// todo work with gpiointerface bool Detector::check_inputs(char& address) { for(int row = 0; row < 8; row++) diff --git a/FlippR-Driver/src/input/Detector.h b/FlippR-Driver/src/input/Detector.h index 7482641..6cc611d 100644 --- a/FlippR-Driver/src/input/Detector.h +++ b/FlippR-Driver/src/input/Detector.h @@ -1,6 +1,12 @@ /* * Detector.h * + * Responsible for detecting InputEvents. + * + * Creates two Threads; + * One cycles over the inputs gpios and pushes detected input events to a queue. + * The other cycles over the queue and notifies input event handlers. + * * Created on: Apr 5, 2018 * Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert, Rafael Vinci, Dr. Franca Rupprecht */