From f87e7c4c6fec9cc18f0af67cb453f697855c246d Mon Sep 17 00:00:00 2001 From: Jonas Zeunert Date: Thu, 7 Jun 2018 23:29:15 +0200 Subject: [PATCH] meeeerged --- FlippR-Driver/src/input/Event.hpp | 14 ++++---- FlippR-Driver/src/input/EventHandler.hpp | 13 ++++++-- FlippR-Driver/src/input/EventNotifier.cpp | 2 +- FlippR-Driver/src/input/InputDriver.hpp | 15 +++------ FlippR-Driver/src/utilities/BlockingQueue.hpp | 6 ++-- FlippR-Driver/src/utilities/GPIOInterface.hpp | 3 +- .../src/utilities/InputGPIOInterface.cpp | 33 +++++++++++-------- .../src/utilities/InputGPIOInterface.h | 2 +- FlippR-Driver/src/utilities/config.h | 1 + 9 files changed, 50 insertions(+), 39 deletions(-) diff --git a/FlippR-Driver/src/input/Event.hpp b/FlippR-Driver/src/input/Event.hpp index 451ca10..ce55f6f 100644 --- a/FlippR-Driver/src/input/Event.hpp +++ b/FlippR-Driver/src/input/Event.hpp @@ -18,6 +18,7 @@ namespace Input class Event { + public: Event(char address, char priority, std::string name) : address(address), priority(priority), name(name) @@ -30,15 +31,16 @@ public: return this->name == other.name; } - bool operator<(const Event& other) + friend bool operator<(const Event& left, const Event& right) { - return this->priority < other.priority; + return left.priority < right.priority; } - private: - const char address; - const char priority; - const std::string name; + char address; + char priority; + std::string name; + + }; } diff --git a/FlippR-Driver/src/input/EventHandler.hpp b/FlippR-Driver/src/input/EventHandler.hpp index ad681d2..465364b 100644 --- a/FlippR-Driver/src/input/EventHandler.hpp +++ b/FlippR-Driver/src/input/EventHandler.hpp @@ -12,13 +12,20 @@ #ifndef INPUTEVENTHANDLER_H_ #define INPUTEVENTHANDLER_H_ -#include "InputDriver.hpp" -#include "Event.hpp" -#include "Detector.h" #include "../utilities/config.h" +#include "Event.hpp" + namespace Input { +class EventHandler; + +class InputDriver +{ +public: + void register_event_handler(EventHandler* handler); + void unregister_event_handler(EventHandler* handler); +}; class EventHandler { diff --git a/FlippR-Driver/src/input/EventNotifier.cpp b/FlippR-Driver/src/input/EventNotifier.cpp index 0446c29..e0248a2 100644 --- a/FlippR-Driver/src/input/EventNotifier.cpp +++ b/FlippR-Driver/src/input/EventNotifier.cpp @@ -56,7 +56,7 @@ void EventNotifier::notify() std::lock_guard event_handler_guard(event_handler_mutex); for(auto handler : event_handler) { - boost::thread handler_caller(handler, &EventHandler::handle, event); + boost::thread handler_caller(boost::bind(&EventHandler::handle, handler, event)); if(!handler_caller.timed_join(boost::posix_time::milliseconds(HANDLER_TIMEOUT))) { diff --git a/FlippR-Driver/src/input/InputDriver.hpp b/FlippR-Driver/src/input/InputDriver.hpp index d9b2138..6fec0cd 100644 --- a/FlippR-Driver/src/input/InputDriver.hpp +++ b/FlippR-Driver/src/input/InputDriver.hpp @@ -4,25 +4,18 @@ * Created on: May 31, 2018 * Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert, Rafael Vinci, Dr. Franca Rupprecht */ - -#include "../utilities/config.h" -#include "Detector.h" - - #ifndef SRC_INPUT_INPUTDRIVER_HPP_ #define SRC_INPUT_INPUTDRIVER_HPP_ +#include "../utilities/config.h" + +#include "EventHandler.h" #include "EventNotifier.h" +#include "Detector.h" namespace Input { -class EventHandler -{ -public: - void handle(Event& event); -}; - class InputDriver { diff --git a/FlippR-Driver/src/utilities/BlockingQueue.hpp b/FlippR-Driver/src/utilities/BlockingQueue.hpp index 81e2f9f..2ba177f 100644 --- a/FlippR-Driver/src/utilities/BlockingQueue.hpp +++ b/FlippR-Driver/src/utilities/BlockingQueue.hpp @@ -26,7 +26,7 @@ public: void push(T const& value) { std::unique_lock lock(this->d_mutex); - p_queue.push_front(value); + p_queue.push(value); this->d_condition.notify_one(); } @@ -34,8 +34,8 @@ public: { std::unique_lock lock(this->d_mutex); this->d_condition.wait(lock, [=]{ return !this->p_queue.empty(); }); - T rc(std::move(this->p_queue.back())); - this->p_queue.pop_back(); + T rc = *this->p_queue.end(); + this->p_queue.pop(); return rc; } }; diff --git a/FlippR-Driver/src/utilities/GPIOInterface.hpp b/FlippR-Driver/src/utilities/GPIOInterface.hpp index 1a86ca8..c098c81 100644 --- a/FlippR-Driver/src/utilities/GPIOInterface.hpp +++ b/FlippR-Driver/src/utilities/GPIOInterface.hpp @@ -14,6 +14,7 @@ #define SRC_UTILITIES_GPIOINTERFACE_HPP_ #include +#include "config.h" #include "../lib/wiringPi/wiringPi.h" #include "../lib/json/json.hpp" @@ -21,7 +22,7 @@ class GPIOInterface { public: - GPIOInterface(nlohmann::json config); + GPIOInterface(); virtual ~GPIOInterface(); static void write_pin(char address, char data) diff --git a/FlippR-Driver/src/utilities/InputGPIOInterface.cpp b/FlippR-Driver/src/utilities/InputGPIOInterface.cpp index 069e3d4..5724d60 100644 --- a/FlippR-Driver/src/utilities/InputGPIOInterface.cpp +++ b/FlippR-Driver/src/utilities/InputGPIOInterface.cpp @@ -6,22 +6,23 @@ */ #include +#include #include "InputGPIOInterface.h" #include "../lib/json/json.hpp" #include "../lib/easylogging/easylogging++.h" #include "config.h" - +#include using namespace nlohmann; bool InputGPIOInterface::read_input_data(char pin) { // setting address to read - write_input_row(pin / MATRIX_SIZE); - write_input_col(pin % MATRIX_SIZE); + write_input_row(pin / INPUT_MATRIX_SIZE); + write_input_col(pin % INPUT_MATRIX_SIZE); // wait for mux to set address - std::this_thread::sleep_for(std::chrono::nanoseconds(SLEEP_DURATION_NANO)); + std::this_thread::sleep_for(std::chrono::nanoseconds(INPUT_SLEEP_DURATION_NANO)); return read_pin(this->input_data_address); } @@ -41,20 +42,26 @@ void InputGPIOInterface::write_input_col(char data) } -InputGPIOInterface::InputGPIOInterface() +InputGPIOInterface::InputGPIOInterface(std::string matrix_config_path) { std::ifstream matrix_config_stream(matrix_config_path); json matrix_config; - matrix_config << matrix_config_stream; + matrix_config_stream >> matrix_config; + try { json matrix_config_input = matrix_config.at("input"); - input_row_address_A = matrix_config.at("row").at("A"); - input_row_address_B = matrix_config.at("row").at("B"); - input_row_address_C = matrix_config.at("row").at("C"); - input_col_address_A = matrix_config.at("col").at("A"); - input_col_address_B = matrix_config.at("col").at("B"); - input_col_address_C = matrix_config.at("col").at("C"); - input_data_address = matrix_config.at("data"); + + json row_json = matrix_config.at("row"); + input_row_address_A = row_json.at("A").get(); + input_row_address_B = row_json.at("B").get(); + input_row_address_C = row_json.at("C").get(); + + json col_json = matrix_config.at("col"); + input_col_address_A = col_json.at("A").get(); + input_col_address_B = col_json.at("B").get(); + input_col_address_C = col_json.at("C").get(); + + input_data_address = matrix_config.at("data").get(); } catch (json::type_error& e) { CLOG(ERROR, INPUT_LOGGER) << "ERROR"; } catch (json::out_of_range& e) { diff --git a/FlippR-Driver/src/utilities/InputGPIOInterface.h b/FlippR-Driver/src/utilities/InputGPIOInterface.h index 9d99496..b375c48 100644 --- a/FlippR-Driver/src/utilities/InputGPIOInterface.h +++ b/FlippR-Driver/src/utilities/InputGPIOInterface.h @@ -15,7 +15,7 @@ class InputGPIOInterface : GPIOInterface { public: - InputGPIOInterface(); + InputGPIOInterface(std::string matrix_config_path); bool read_input_data(char pin); private: diff --git a/FlippR-Driver/src/utilities/config.h b/FlippR-Driver/src/utilities/config.h index cc08fe1..148461c 100644 --- a/FlippR-Driver/src/utilities/config.h +++ b/FlippR-Driver/src/utilities/config.h @@ -13,3 +13,4 @@ #define HIGH_VERBOSITY 10 #define INPUT_MATRIX_SIZE 8 +#define INPUT_SLEEP_DURATION_NANO 800