Merge branch 'master' of https://github.com/swinginbird/flippr-code
This commit is contained in:
1
FlippR-Driver/.gitignore
vendored
1
FlippR-Driver/.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
build
|
||||
src/Debug
|
||||
/Debug/
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#include "../utilities/config.h"
|
||||
#include "Detector.h"
|
||||
|
||||
|
||||
#ifndef SRC_INPUT_INPUTDRIVER_HPP_
|
||||
@@ -26,8 +27,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";
|
||||
}
|
||||
@@ -36,6 +38,9 @@ public:
|
||||
{
|
||||
delete event_notifier;
|
||||
event_notifier = NULL;
|
||||
|
||||
delete detector;
|
||||
detector = NULL;
|
||||
}
|
||||
|
||||
void register_event_handler(EventHandler* handler)
|
||||
@@ -50,6 +55,7 @@ public:
|
||||
|
||||
private:
|
||||
EventNotifier* event_notifier;
|
||||
Detector* detector;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -29,34 +29,59 @@ 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)
|
||||
for(auto& json_event : matrix_config)
|
||||
{
|
||||
InputEvent event(matrix_config[key], key);
|
||||
input_events.emplace(key, event);
|
||||
try
|
||||
{
|
||||
std::string name = json_event.at("name");
|
||||
char address = json_event.at("address");
|
||||
int priority = json_event.at("priority");
|
||||
|
||||
Event event(address, priority, name);
|
||||
|
||||
events.emplace(address, event);
|
||||
}
|
||||
catch(json::exception& e)
|
||||
{
|
||||
CLOG(ERROR, INPUT_LOGGER) << "Matrix config-file corrupted: " << e.what();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
return input_events;
|
||||
return events;
|
||||
}
|
||||
|
||||
static void ConfigureLogger()
|
||||
|
||||
@@ -20,7 +20,7 @@ class BlockingQueue
|
||||
private:
|
||||
std::mutex d_mutex;
|
||||
std::condition_variable d_condition;
|
||||
heap::priority_queue<T, heap::stable<T>> p_queue;
|
||||
heap::priority_queue<T, heap::stable<true>> p_queue;
|
||||
|
||||
public:
|
||||
void push(T const& value)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user