From 3f1419cb29fab331add9c24bc9f63035c312abdb Mon Sep 17 00:00:00 2001 From: Neeflix Date: Thu, 31 May 2018 21:35:54 +0200 Subject: [PATCH 1/5] building events --- FlippR-Driver/src/input/Event.hpp | 3 +- FlippR-Driver/src/input/InputDriver.hpp | 10 ++++- .../src/input/InputDriverFactory.hpp | 43 ++++++++++++++----- FlippR-Driver/src/utilities/GPIOInterface.hpp | 3 +- 4 files changed, 44 insertions(+), 15 deletions(-) diff --git a/FlippR-Driver/src/input/Event.hpp b/FlippR-Driver/src/input/Event.hpp index 26c867d..451ca10 100644 --- a/FlippR-Driver/src/input/Event.hpp +++ b/FlippR-Driver/src/input/Event.hpp @@ -19,7 +19,8 @@ namespace Input class Event { public: - Event(char address, char priority, std::string name) : address(address), priority(priority), name(name) + Event(char address, char priority, std::string name) : + address(address), priority(priority), name(name) { CLOG_IF(VLOG_IS_ON(HIGH_VERBOSITY), INFO, INPUT_LOGGER) << "Created event: " << name << ", address: " << address; } diff --git a/FlippR-Driver/src/input/InputDriver.hpp b/FlippR-Driver/src/input/InputDriver.hpp index 81a43dc..848c8b1 100644 --- a/FlippR-Driver/src/input/InputDriver.hpp +++ b/FlippR-Driver/src/input/InputDriver.hpp @@ -6,6 +6,7 @@ */ #include "../utilities/config.h" +#include "Detector.h" #ifndef SRC_INPUT_INPUTDRIVER_HPP_ @@ -24,8 +25,9 @@ class InputDriver { public: - InputDriver(EventNotifier* event_notifier) : - event_notifier(event_notifier) + InputDriver(EventNotifier* event_notifier, Detector* detector) : + event_notifier(event_notifier), + detector(detector) { CLOG(INFO, INPUT_LOGGER) << "Created InputDriver"; } @@ -34,6 +36,9 @@ public: { delete event_notifier; event_notifier = NULL; + + delete detector; + detector = NULL; } void register_event_handler(EventHandler* handler) @@ -48,6 +53,7 @@ public: private: EventNotifier* event_notifier; + Detector* detector; }; } diff --git a/FlippR-Driver/src/input/InputDriverFactory.hpp b/FlippR-Driver/src/input/InputDriverFactory.hpp index 2e30768..ed43819 100644 --- a/FlippR-Driver/src/input/InputDriverFactory.hpp +++ b/FlippR-Driver/src/input/InputDriverFactory.hpp @@ -29,34 +29,55 @@ class InputFactory { public: - static std::shared_ptr get_detector(std::string& input_config_path, std::string& matrix_config_path) + static shared_ptr get_InputDriver(std::string& input_config_path, std::string& matrix_config_path) + { + this->ConfigureLogger(); + auto event_notifier = new EventNotifier(); + + auto detector = this->get_detector(input_config_path, matrix_config_path); + + return shared_ptr(new InputDriver(event_notifier, detector)); + } + +private: + static Detector* get_detector(std::string& input_config_path, std::string& matrix_config_path) { - // todo this in gpiointerface std::ifstream input_config_stream(input_config_path); json input_config; input_config << input_config_stream; + std::ifstream matrix_config_stream(matrix_config_path); + json matrix_config; + matrix_config << matrix_config_stream; - auto input_gpio_interface = new InputGPIOInterface(); + + auto input_gpio_interface = new InputGPIOInterface(input_config); auto input_notifier = new InputEventNotifier(); - std::map input_events = create_input_events(matrix_config); + std::map input_events = this->create_input_events(matrix_config); - return std::shared_ptr(new Detector(input_gpio_interface, input_events, input_notifier)); + return new Detector(input_gpio_interface, input_events, input_notifier); } -private: - static std::map create_input_events(json matrix_config) + static std::map create_input_events(json matrix_config) { - std::map input_events; + std::map events; for(auto& key : matrix_config) { - InputEvent event(matrix_config[key], key); - input_events.emplace(key, event); + auto event = this->GetEvent(key); + + events.emplace(key, event); } - return input_events; + return events; + } + + static Event GetEvent(json json_event) + { + Event event; + + return event; } static void ConfigureLogger() diff --git a/FlippR-Driver/src/utilities/GPIOInterface.hpp b/FlippR-Driver/src/utilities/GPIOInterface.hpp index c047ea7..1a86ca8 100644 --- a/FlippR-Driver/src/utilities/GPIOInterface.hpp +++ b/FlippR-Driver/src/utilities/GPIOInterface.hpp @@ -16,11 +16,12 @@ #include #include "../lib/wiringPi/wiringPi.h" +#include "../lib/json/json.hpp" class GPIOInterface { public: - GPIOInterface(std::string config_path); + GPIOInterface(nlohmann::json config); virtual ~GPIOInterface(); static void write_pin(char address, char data) From b033429ab0a587e9e840390ff154c0bd0a4aff78 Mon Sep 17 00:00:00 2001 From: Neeflix Date: Thu, 31 May 2018 21:51:54 +0200 Subject: [PATCH 2/5] finished input factory --- .../src/input/InputDriverFactory.hpp | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/FlippR-Driver/src/input/InputDriverFactory.hpp b/FlippR-Driver/src/input/InputDriverFactory.hpp index ed43819..ff078f3 100644 --- a/FlippR-Driver/src/input/InputDriverFactory.hpp +++ b/FlippR-Driver/src/input/InputDriverFactory.hpp @@ -63,23 +63,28 @@ private: { std::map events; - for(auto& key : matrix_config) + for(auto& json_event : matrix_config) { - auto event = this->GetEvent(key); + try + { + std::string name = json_event.at("name"); + char address = json_event.at("address"); + int priority = json_event.at("priority"); - events.emplace(key, event); + Event event(address, priority, name); + + events.emplace(address, event); + } + catch(json::exception& e) + { + CLOG(ERROR, INPUT_LOGGER) << "Matrix config corrupted, check all events!"; + exit(EXIT_FAILURE); + } } return events; } - static Event GetEvent(json json_event) - { - Event event; - - return event; - } - static void ConfigureLogger() { el::Loggers::getLogger(INPUT_LOGGER); From 335d858756f0ccadef946da5eb22878be3e3e7df Mon Sep 17 00:00:00 2001 From: Neeflix Date: Thu, 31 May 2018 21:59:53 +0200 Subject: [PATCH 3/5] little changes :tada --- FlippR-Driver/src/input/InputDriverFactory.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FlippR-Driver/src/input/InputDriverFactory.hpp b/FlippR-Driver/src/input/InputDriverFactory.hpp index ff078f3..ce9778e 100644 --- a/FlippR-Driver/src/input/InputDriverFactory.hpp +++ b/FlippR-Driver/src/input/InputDriverFactory.hpp @@ -77,7 +77,7 @@ private: } catch(json::exception& e) { - CLOG(ERROR, INPUT_LOGGER) << "Matrix config corrupted, check all events!"; + CLOG(ERROR, INPUT_LOGGER) << "Matrix config-file corrupted: " << e.what(); exit(EXIT_FAILURE); } } From 9be260815cf58bbe3750f2788e57c032bba1539e Mon Sep 17 00:00:00 2001 From: Neeflix Date: Thu, 31 May 2018 22:03:54 +0200 Subject: [PATCH 4/5] just smiley commit :tada: --- FlippR-Driver/src/input/InputDriverFactory.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/FlippR-Driver/src/input/InputDriverFactory.hpp b/FlippR-Driver/src/input/InputDriverFactory.hpp index ce9778e..f3fc19f 100644 --- a/FlippR-Driver/src/input/InputDriverFactory.hpp +++ b/FlippR-Driver/src/input/InputDriverFactory.hpp @@ -50,7 +50,6 @@ private: json matrix_config; matrix_config << matrix_config_stream; - auto input_gpio_interface = new InputGPIOInterface(input_config); auto input_notifier = new InputEventNotifier(); From 5446ee23b9000f30f082df9e280a96772dfce1d1 Mon Sep 17 00:00:00 2001 From: Neeflix Date: Thu, 7 Jun 2018 20:23:12 +0200 Subject: [PATCH 5/5] added order :wheelchair: --- FlippR-Driver/.gitignore | 1 + FlippR-Driver/{ => etc}/Input_Config.json | 0 FlippR-Driver/{ => etc}/Input_Matrix_Config.json | 0 FlippR-Driver/src/utilities/BlockingQueue.hpp | 2 +- 4 files changed, 2 insertions(+), 1 deletion(-) rename FlippR-Driver/{ => etc}/Input_Config.json (100%) rename FlippR-Driver/{ => etc}/Input_Matrix_Config.json (100%) diff --git a/FlippR-Driver/.gitignore b/FlippR-Driver/.gitignore index 92708ce..efc2322 100644 --- a/FlippR-Driver/.gitignore +++ b/FlippR-Driver/.gitignore @@ -1,2 +1,3 @@ build src/Debug +/Debug/ diff --git a/FlippR-Driver/Input_Config.json b/FlippR-Driver/etc/Input_Config.json similarity index 100% rename from FlippR-Driver/Input_Config.json rename to FlippR-Driver/etc/Input_Config.json diff --git a/FlippR-Driver/Input_Matrix_Config.json b/FlippR-Driver/etc/Input_Matrix_Config.json similarity index 100% rename from FlippR-Driver/Input_Matrix_Config.json rename to FlippR-Driver/etc/Input_Matrix_Config.json diff --git a/FlippR-Driver/src/utilities/BlockingQueue.hpp b/FlippR-Driver/src/utilities/BlockingQueue.hpp index 350f6ad..81e2f9f 100644 --- a/FlippR-Driver/src/utilities/BlockingQueue.hpp +++ b/FlippR-Driver/src/utilities/BlockingQueue.hpp @@ -20,7 +20,7 @@ class BlockingQueue private: std::mutex d_mutex; std::condition_variable d_condition; - heap::priority_queue> p_queue; + heap::priority_queue> p_queue; public: void push(T const& value)