commenting and fixing bugs

This commit is contained in:
Jonas Zeunert
2018-05-07 18:50:17 +02:00
parent 23f04f472f
commit 744f25c19c
2 changed files with 19 additions and 4 deletions

View File

@@ -27,8 +27,8 @@ Detector::~Detector()
{ {
is_running = false; is_running = false;
detect_thread.join();
notify_thread.join(); notify_thread.join();
detect_thread.join();
} }
void Detector::register_input_event_handler(InputEventHandler* handler) void Detector::register_input_event_handler(InputEventHandler* handler)
@@ -61,25 +61,34 @@ void Detector::notify_handlers()
LOCK_EVENT_HANDLER(); LOCK_EVENT_HANDLER();
for(auto* handler : event_handler) for(auto* handler : event_handler)
{ {
// todo timeout!
handler->handle(event); handler->handle(event);
} }
} }
} }
// Cycles over all inputs and enqueues an input event if detected.
void Detector::detect() void Detector::detect()
{ {
while(is_running) while(is_running)
{ {
char address; char address;
if(check_inputs(address)) if(check_inputs(address))
{
try
{ {
InputEvent& event = input_events.at(address); InputEvent& event = input_events.at(address);
event_queue.emplace(event); event_queue.emplace(event);
} }
catch(std::out_of_range& e)
{
// todo log exception!
}
}
} }
} }
// todo work with gpiointerface
bool Detector::check_inputs(char& address) bool Detector::check_inputs(char& address)
{ {
for(int row = 0; row < 8; row++) for(int row = 0; row < 8; row++)

View File

@@ -1,6 +1,12 @@
/* /*
* Detector.h * 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 * Created on: Apr 5, 2018
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert, Rafael Vinci, Dr. Franca Rupprecht * Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert, Rafael Vinci, Dr. Franca Rupprecht
*/ */