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
{
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;
}

View File

@@ -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;
};
}

View File

@@ -29,34 +29,55 @@ class InputFactory
{
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);
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<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, InputEvent> create_input_events(json matrix_config)
static std::map<char, Event> create_input_events(json matrix_config)
{
std::map<char, InputEvent> input_events;
std::map<char, Event> 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()

View File

@@ -16,11 +16,12 @@
#include <fstream>
#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)