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)