building events

This commit is contained in:
Neeflix
2018-05-31 21:35:54 +02:00
parent 424e1fafde
commit 3f1419cb29
4 changed files with 44 additions and 15 deletions

View File

@@ -19,7 +19,8 @@ namespace Input
class Event class Event
{ {
public: 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; CLOG_IF(VLOG_IS_ON(HIGH_VERBOSITY), INFO, INPUT_LOGGER) << "Created event: " << name << ", address: " << address;
} }

View File

@@ -6,6 +6,7 @@
*/ */
#include "../utilities/config.h" #include "../utilities/config.h"
#include "Detector.h"
#ifndef SRC_INPUT_INPUTDRIVER_HPP_ #ifndef SRC_INPUT_INPUTDRIVER_HPP_
@@ -24,8 +25,9 @@ class InputDriver
{ {
public: public:
InputDriver(EventNotifier* event_notifier) : InputDriver(EventNotifier* event_notifier, Detector* detector) :
event_notifier(event_notifier) event_notifier(event_notifier),
detector(detector)
{ {
CLOG(INFO, INPUT_LOGGER) << "Created InputDriver"; CLOG(INFO, INPUT_LOGGER) << "Created InputDriver";
} }
@@ -34,6 +36,9 @@ public:
{ {
delete event_notifier; delete event_notifier;
event_notifier = NULL; event_notifier = NULL;
delete detector;
detector = NULL;
} }
void register_event_handler(EventHandler* handler) void register_event_handler(EventHandler* handler)
@@ -48,6 +53,7 @@ public:
private: private:
EventNotifier* event_notifier; EventNotifier* event_notifier;
Detector* detector;
}; };
} }

View File

@@ -29,34 +29,55 @@ class InputFactory
{ {
public: public:
static std::shared_ptr<Detector> get_detector(std::string& input_config_path, std::string& matrix_config_path) static shared_ptr<InputDriver*> 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<InputDriver*>(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); std::ifstream input_config_stream(input_config_path);
json input_config; json input_config;
input_config << input_config_stream; 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(); auto input_notifier = new InputEventNotifier();
std::map<char, InputEvent> input_events = create_input_events(matrix_config); std::map<char, InputEvent> input_events = this->create_input_events(matrix_config);
return std::shared_ptr<Detector*>(new Detector(input_gpio_interface, input_events, input_notifier)); return new Detector(input_gpio_interface, input_events, input_notifier);
} }
private: static std::map<char, Event> create_input_events(json matrix_config)
static std::map<char, InputEvent> create_input_events(json matrix_config)
{ {
std::map<char, InputEvent> input_events; std::map<char, Event> events;
for(auto& key : matrix_config) for(auto& key : matrix_config)
{ {
InputEvent event(matrix_config[key], key); auto event = this->GetEvent(key);
input_events.emplace(key, event);
events.emplace(key, event);
} }
return input_events; return events;
}
static Event GetEvent(json json_event)
{
Event event;
return event;
} }
static void ConfigureLogger() static void ConfigureLogger()

View File

@@ -16,11 +16,12 @@
#include <fstream> #include <fstream>
#include "../lib/wiringPi/wiringPi.h" #include "../lib/wiringPi/wiringPi.h"
#include "../lib/json/json.hpp"
class GPIOInterface class GPIOInterface
{ {
public: public:
GPIOInterface(std::string config_path); GPIOInterface(nlohmann::json config);
virtual ~GPIOInterface(); virtual ~GPIOInterface();
static void write_pin(char address, char data) static void write_pin(char address, char data)