79 lines
1.8 KiB
C++
79 lines
1.8 KiB
C++
/*
|
|
* InputFactory.h
|
|
*
|
|
* Created on: Apr 5, 2018
|
|
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert, Rafael Vinci, Dr. Franca Rupprecht
|
|
*/
|
|
|
|
#ifndef INPUTFACTORY_H_
|
|
#define INPUTFACTORY_H_
|
|
|
|
#include <fstream>
|
|
|
|
#include "Detector.h"
|
|
|
|
#include "../utilities/InputGPIOInterface.h"
|
|
#include "../utilities/config.h"
|
|
#include "../lib/json/json.hpp"
|
|
#include "../lib/easylogging/easylogging++.h"
|
|
#include "EventNotifier.h"
|
|
|
|
using namespace nlohmann;
|
|
|
|
|
|
INITIALIZE_EASYLOGGINGPP
|
|
|
|
namespace Input
|
|
{
|
|
class InputFactory
|
|
{
|
|
|
|
public:
|
|
static std::shared_ptr<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;
|
|
|
|
|
|
auto input_gpio_interface = new InputGPIOInterface();
|
|
auto input_notifier = new InputEventNotifier();
|
|
|
|
std::map<char, InputEvent> input_events = create_input_events(matrix_config);
|
|
|
|
return std::shared_ptr<Detector*>(new Detector(input_gpio_interface, input_events, input_notifier));
|
|
}
|
|
|
|
private:
|
|
static std::map<char, InputEvent> create_input_events(json matrix_config)
|
|
{
|
|
std::map<char, InputEvent> input_events;
|
|
|
|
for(auto& key : matrix_config)
|
|
{
|
|
InputEvent event(matrix_config[key], key);
|
|
input_events.emplace(key, event);
|
|
}
|
|
|
|
return input_events;
|
|
}
|
|
|
|
static void ConfigureLogger()
|
|
{
|
|
el::Loggers::getLogger(INPUT_LOGGER);
|
|
|
|
//TODO may configure?
|
|
el::Configurations conf;
|
|
conf.setToDefault();
|
|
conf.set(el::Level::Global, el::ConfigurationType::Filename, DRIVER_LOG_FILE);
|
|
conf.set(el::Level::Global, el::ConfigurationType::Format, "%datetime [%level] [%func] : %msg");
|
|
|
|
el::Loggers::reconfigureLogger(INPUT_LOGGER, conf);
|
|
}
|
|
|
|
};
|
|
}
|
|
|
|
#endif /* INPUTFACTORY_H_ */
|