working on big refactor

This commit is contained in:
Jonas Zeunert
2018-12-14 01:09:54 +01:00
parent f3100004b9
commit 2aee0f4f9d
67 changed files with 914 additions and 619 deletions

View File

@@ -1,55 +1,27 @@
/*
* Detector.h
*
* Responsible for detecting InputEvents.
*
* Creates two Threads;
* One cycles over the inputs gpios and pushes detected input events to a queue.
* The other cycles over the queue and notifies input event handlers.
*
* Created on: Apr 5, 2018
* Created on: Jun 13, 2018
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
*/
#ifndef DETECTOR_H_
#define DETECTOR_H_
#ifndef SRC_INPUT_DETECTOR_H_
#define SRC_INPUT_DETECTOR_H_
#include <thread>
#include <vector>
#include <map>
#include "IInputGPIOInterface.h"
#include "IDetector.h"
#include "DistributingEvent.h"
#include "IEventNotifier.h"
namespace flippR_driver
{
namespace input
{
class Detector : public IDetector
class Detector
{
public:
Detector(std::unique_ptr<IInputGPIOInterface> input_gpio_interface, std::vector<std::shared_ptr<DistributingEvent>> events);
~Detector() override;
private:
void detect();
void check_inputs();
private:
const std::unique_ptr<IInputGPIOInterface> input_gpio_interface;
const std::vector<std::shared_ptr<DistributingEvent>> events;
bool is_running;
std::thread detect_thread;
virtual ~Detector() = default;
};
}
}
#endif
#endif

View File

@@ -4,20 +4,26 @@
#include "DistributingEvent.h"
flippR_driver::input::DistributingEvent::DistributingEvent(char address, int priority, std::string name,
std::chrono::milliseconds bounce_time, std::shared_ptr<IEventNotifier> event_notifier):
Event(address, priority, std::move(name)),
bounce_time(bounce_time),
event_notifier(std::move(event_notifier)),
activation_state(NOT_ACTIVATED)
namespace flippR_driver
{
namespace input
{
DistributingEvent::DistributingEvent(char address, int priority, std::string name,
std::chrono::milliseconds bounce_time, std::shared_ptr<EventNotifier> event_notifier)
:
Event(address, priority, std::move(name)),
bounce_time(bounce_time),
event_notifier(std::move(event_notifier)),
activation_state(NOT_ACTIVATED)
{}
void flippR_driver::input::DistributingEvent::distribute()
void DistributingEvent::distribute()
{
event_notifier->distribute_event(*this);
}
void flippR_driver::input::DistributingEvent::active()
void DistributingEvent::active()
{
if(!is_bouncing())
{
@@ -35,7 +41,7 @@ void flippR_driver::input::DistributingEvent::active()
}
}
bool flippR_driver::input::DistributingEvent::is_bouncing()
bool DistributingEvent::is_bouncing()
{
std::chrono::time_point<std::chrono::high_resolution_clock> now = std::chrono::high_resolution_clock::now();
std::chrono::milliseconds elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(now - last_activation);
@@ -43,7 +49,7 @@ bool flippR_driver::input::DistributingEvent::is_bouncing()
return elapsed_time < bounce_time;
}
void flippR_driver::input::DistributingEvent::inactive()
void DistributingEvent::inactive()
{
if(activation_state == ACTIVATED)
{
@@ -52,3 +58,5 @@ void flippR_driver::input::DistributingEvent::inactive()
}
}
}
}

View File

@@ -6,17 +6,18 @@
#define flippR_driver_DISTRIBUTINGEVENT_H
#include "input/Event.h"
#include "IEventNotifier.h"
#include "input/EventNotifier.h"
namespace flippR_driver
{
namespace input
{
class DistributingEvent : public Event
{
public:
DistributingEvent(char address, int priority, std::string name,
std::chrono::milliseconds bounce_time, std::shared_ptr<IEventNotifier> event_notifier);
std::chrono::milliseconds bounce_time, std::shared_ptr<EventNotifier> event_notifier);
void active();
void inactive();
@@ -37,11 +38,12 @@ private:
ACTIVATED
};
const std::shared_ptr<IEventNotifier> event_notifier;
const std::shared_ptr<EventNotifier> event_notifier;
ActivationState activation_state;
};
}
}

View File

@@ -13,8 +13,7 @@ namespace flippR_driver
namespace input
{
// todo unsigned char address
Event::Event(char address, int priority, std::string name) :
Event::Event(uint8_t address, int priority, std::string name) :
address(address), priority(priority), name(name)
{
CLOG_IF(VLOG_IS_ON(0), INFO, INPUT_LOGGER) << "Created event: " << name << ", address: " << address;

View File

@@ -1,57 +1,33 @@
/*
* InputEventNotifier.h
* EventNotifier.h
*
* Created on: May 17, 2018
* Created on: Jun 13, 2018
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
*/
#ifndef SRC_INPUT_EVENTNOTIFIER_H_
#define SRC_INPUT_EVENTNOTIFIER_H_
#ifndef SRC_INPUT_IEVENTNOTIFIER_H_
#define SRC_INPUT_IEVENTNOTIFIER_H_
#include "IEventNotifier.h"
#include <set>
#include <thread>
#include <mutex>
#include "utility/BlockingQueue.hpp"
#include "utility/IBlockingQueue.h"
#include "input/Event.h"
#include "input/EventHandler.h"
#define HANDLER_TIMEOUT 2000
#include <memory>
namespace flippR_driver
{
namespace input
{
class EventNotifier : public IEventNotifier
class EventNotifier
{
public:
explicit EventNotifier(utility::IBlockingQueue<Event>* queue);
~EventNotifier() override;
virtual ~EventNotifier() = default;
void register_event_handler(IEventHandler* handler) override;
void unregister_event_handler(IEventHandler* handler) override;
virtual void register_event_handler(EventHandler* handler) = 0;
virtual void unregister_event_handler(EventHandler* handler) = 0;
void distribute_event(Event &event) override;
private:
void notify();
private:
utility::IBlockingQueue<Event>* event_queue;
std::set<IEventHandler*> event_handlers;
bool is_running;
std::thread notify_thread;
std::mutex event_handler_mutex;
virtual void distribute_event(Event &event) = 0;
};
}
}
#endif
}
#endif

View File

@@ -1,27 +0,0 @@
/*
* IDetector.h
*
* Created on: Jun 13, 2018
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
*/
#ifndef SRC_INPUT_IDETECTOR_H_
#define SRC_INPUT_IDETECTOR_H_
namespace flippR_driver
{
namespace input
{
class IDetector
{
public:
virtual ~IDetector() = default;
};
}
}
#endif

View File

@@ -1,33 +0,0 @@
/*
* IEventNotifier.h
*
* Created on: Jun 13, 2018
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
*/
#ifndef SRC_INPUT_IEVENTNOTIFIER_H_
#define SRC_INPUT_IEVENTNOTIFIER_H_
#include "input/Event.h"
#include "input/IEventHandler.h"
#include <memory>
namespace flippR_driver
{
namespace input
{
class IEventNotifier
{
public:
virtual ~IEventNotifier() = default;
virtual void register_event_handler(IEventHandler* handler) = 0;
virtual void unregister_event_handler(IEventHandler* handler) = 0;
virtual void distribute_event(Event &event) = 0;
};
}
}
#endif

View File

@@ -1,43 +0,0 @@
/*
* InputDriver.hpp
*
* Created on: May 31, 2018
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
*/
#ifndef SRC_INPUT_INPUTDRIVER_H_
#define SRC_INPUT_INPUTDRIVER_H_
#include "input/IInputDriver.h"
#include <map>
#include "IEventNotifier.h"
#include "IDetector.h"
namespace flippR_driver
{
namespace input
{
class InputDriver : public IInputDriver
{
public:
InputDriver(std::shared_ptr<IEventNotifier> event_notifier, std::unique_ptr<IDetector> detector, std::map<std::string, std::shared_ptr<Event>> events);
void register_event_handler(IEventHandler* handler) override;
void unregister_event_handler(IEventHandler* handler) override;
boost::optional<std::shared_ptr<Event>> get_event(std::string name) override;
private:
const std::shared_ptr<IEventNotifier> event_notifier;
const std::unique_ptr<IDetector> detector;
const std::map<std::string, std::shared_ptr<Event>> events;
};
}
}
#endif

View File

@@ -12,9 +12,9 @@
#include "utility/LoggerFactory.h"
#include "InputDriver.h"
#include "EventNotifier.h"
#include "Detector.h"
#include "input/impl/InputDriver.h"
#include "input/impl/EventNotifier.h"
#include "input/impl/Detector.h"
namespace flippR_driver
{
@@ -26,63 +26,64 @@ namespace InputDriverFactory
using namespace nlohmann;
using namespace flippR_driver::utility;
std::shared_ptr<IInputDriver> get_InputDriver(std::istream &input_pin_stream, std::istream &matrix_config_stream)
std::shared_ptr<InputDriver> get_InputDriver(std::istream &input_pin_stream, std::istream &matrix_config_stream)
{
LoggerFactory::CreateInputLogger();
IBlockingQueue<Event> *event_queue = new BlockingQueue<Event>;
std::shared_ptr<IEventNotifier> event_notifier(new EventNotifier(event_queue));
std::shared_ptr<EventNotifier> event_notifier(new impl::EventNotifier(event_queue));
std::vector<std::shared_ptr<DistributingEvent>> events;
std::map<std::string, std::shared_ptr<Event>> name_event_map;
create_events(matrix_config_stream, events, name_event_map, event_notifier);
std::unique_ptr<IInputGPIOInterface> input_gpio_interface(new InputGPIOInterface(create_pin_map(input_pin_stream)));
std::unique_ptr<IDetector> detector(new Detector(std::move(input_gpio_interface), events));
std::unique_ptr<InputPinController> input_gpio_interface(new impl::InputPinController(create_pin_map(input_pin_stream)));
std::unique_ptr<Detector> detector(new impl::Detector(std::move(input_gpio_interface), events));
return std::make_shared<InputDriver>(event_notifier, std::move(detector), name_event_map);
return std::make_shared<impl::InputDriver>(event_notifier, std::move(detector), name_event_map);
}
namespace
{
void create_events(std::istream &matrix_config_stream, std::vector<std::shared_ptr<DistributingEvent>> &events,
std::map<std::string, std::shared_ptr<Event>> &name_event_map,
std::shared_ptr<IEventNotifier> event_notifier)
std::shared_ptr<EventNotifier> event_notifier)
{
json matrix_config;
matrix_config_stream >> matrix_config;
int global_bounce_time = matrix_config.at("global_bounce_time").get<uint8_t>();
auto &json_events = matrix_config.at("input_matrix");
for(auto &json_event : json_events)
try
{
int global_bounce_time = matrix_config.at("global_bounce_time").get<uint8_t>();
auto &json_events = matrix_config.at("input_matrix");
for(auto &json_event : json_events)
{
std::shared_ptr<DistributingEvent> event = create_event(json_event, event_notifier, global_bounce_time);
events.push_back(event);
name_event_map.emplace(event->name, event);
}
}
std::shared_ptr<DistributingEvent> create_event(json &json_event, std::shared_ptr<IEventNotifier> event_notifier, int bounce_time)
{
try
{
std::string name = json_event.at("name");
char address = json_event.at("address").get<uint8_t>();
int priority = json_event.at("priority").get<uint8_t>();
set_individual_bounce_time(json_event, bounce_time);
return std::make_shared<DistributingEvent>(address, priority, name, std::chrono::milliseconds(bounce_time), event_notifier);
}
}
catch(json::exception &e)
{
CLOG(ERROR, INPUT_LOGGER) << "Matrix config-file corrupted: " << e.what();
CLOG(ERROR, INPUT_LOGGER) << "Event matrix config file corrupted: " << e.what();
exit(EXIT_FAILURE);
}
}
std::shared_ptr<DistributingEvent> create_event(json &json_event, std::shared_ptr<EventNotifier> event_notifier, int bounce_time)
{
std::string name = json_event.at("name");
char address = json_event.at("address").get<uint8_t>();
int priority = json_event.at("priority").get<uint8_t>();
set_individual_bounce_time(json_event, bounce_time);
return std::make_shared<DistributingEvent>(address, priority, name, std::chrono::milliseconds(bounce_time), event_notifier);
}
void set_individual_bounce_time(json &json_event, int &bounce_time)
{
auto it_bounce_time = json_event.find("bounce_time");
@@ -114,14 +115,9 @@ namespace
input_pin_map["data_address"] = pin_config.at("data").get<uint8_t>();
}
catch(json::type_error &e)
catch(json::exception &e)
{
CLOG(ERROR, INPUT_LOGGER) << "Input json corrupted! " << e.what();
exit(EXIT_FAILURE);
}
catch(json::out_of_range &e)
{
CLOG(ERROR, INPUT_LOGGER) << "Input json corrupted! " << e.what();
CLOG(ERROR, INPUT_LOGGER) << "Input pin config file corrupted! " << e.what();
exit(EXIT_FAILURE);
}

View File

@@ -11,10 +11,10 @@
#include <istream>
#include "json/json.hpp"
#include "input/IInputDriver.h"
#include "input/InputDriver.h"
#include "DistributingEvent.h"
#include "InputGPIOInterface.h"
#include "IEventNotifier.h"
#include "input/impl/InputPinController.h"
#include "input/EventNotifier.h"
namespace flippR_driver
{
@@ -22,16 +22,16 @@ namespace input
{
namespace InputDriverFactory
{
std::shared_ptr<IInputDriver> get_InputDriver(std::istream &input_pin_stream, std::istream &matrix_config_stream);
std::shared_ptr<InputDriver> get_InputDriver(std::istream &input_pin_stream, std::istream &matrix_config_stream);
namespace
{
static void create_events(std::istream &matrix_config,
std::vector<std::shared_ptr<DistributingEvent>> &events,
std::map<std::string, std::shared_ptr<Event>> &name_event_map,
std::shared_ptr<IEventNotifier> event_notifier);
std::shared_ptr<EventNotifier> event_notifier);
static std::shared_ptr<DistributingEvent> create_event(nlohmann::json &json_event, std::shared_ptr<IEventNotifier> event_notifier, int bounce_time);
static std::shared_ptr<DistributingEvent> create_event(nlohmann::json &json_event, std::shared_ptr<EventNotifier> event_notifier, int bounce_time);
static void set_individual_bounce_time(nlohmann::json &json_event, int &bounce_time);
static std::map<std::string, uint8_t> create_pin_map(std::istream &input_pin_stream);

View File

@@ -1,5 +1,5 @@
/*
* InputGPIOInterface.h
* InputPinController.h
*
* Created on: May 31, 2018
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
@@ -15,10 +15,10 @@ namespace flippR_driver
namespace input
{
class IInputGPIOInterface
class InputPinController
{
public:
virtual ~IInputGPIOInterface() = default;
virtual ~InputGPIOInterface() = default;
virtual bool read_data(uint8_t pin) const = 0;
};

View File

@@ -15,9 +15,12 @@ namespace flippR_driver
{
namespace input
{
namespace impl
{
Detector::Detector(std::unique_ptr<IInputGPIOInterface> input_gpio_interface, std::vector<std::shared_ptr<DistributingEvent>> events) :
input_gpio_interface(std::move(input_gpio_interface)), events(std::move(events)), is_running(true)
Detector::Detector(std::unique_ptr<InputPinController> input_gpio_interface, std::vector<std::shared_ptr<DistributingEvent>> events)
:
input_gpio_interface(std::move(input_gpio_interface)), events(std::move(events)), is_running(true)
{
this->detect_thread = std::thread(&Detector::detect, this);
@@ -41,7 +44,7 @@ void Detector::detect()
void Detector::check_inputs()
{
for(auto& event : events)
for(auto &event : events)
{
input_gpio_interface->read_data(event->address) ? event->active() : event->inactive();
}
@@ -49,3 +52,4 @@ void Detector::check_inputs()
}
}
}

View File

@@ -0,0 +1,58 @@
/*
* Detector.h
*
* Responsible for detecting InputEvents.
*
* Creates two Threads;
* One cycles over the inputs gpios and pushes detected input events to a queue.
* The other cycles over the queue and notifies input event handlers.
*
* Created on: Apr 5, 2018
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
*/
#ifndef INPUT_IMPL_DETECTOR_H_
#define INPUT_IMPL_DETECTOR_H_
#include <thread>
#include <vector>
#include <map>
#include "input/InputPinController.h"
#include "input/Detector.h"
#include "input/DistributingEvent.h"
#include "input/EventNotifier.h"
namespace flippR_driver
{
namespace input
{
namespace impl
{
class Detector : public input::Detector
{
public:
Detector(std::unique_ptr<input::InputPinController> input_gpio_interface, std::vector<std::shared_ptr<DistributingEvent>> events);
~Detector() override;
private:
void detect();
void check_inputs();
private:
const std::unique_ptr<input::InputPinController> input_gpio_interface;
const std::vector<std::shared_ptr<DistributingEvent>> events;
bool is_running;
std::thread detect_thread;
};
}
}
}
#endif

View File

@@ -4,16 +4,18 @@
* Created on: Jun 14, 2018
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
*/
#include "input/EventHandler.h"
#include "EventHandler.h"
#include "utility/config.h"
namespace flippR_driver
{
namespace input
{
namespace impl
{
EventHandler::EventHandler(std::shared_ptr<IInputDriver> input_driver) :
input_driver(std::move(input_driver))
EventHandler::EventHandler(std::shared_ptr<InputDriver> input_driver) :
input_driver(std::move(input_driver))
{
this->input_driver->register_event_handler(this);
@@ -26,10 +28,11 @@ EventHandler::~EventHandler()
}
// This function is intended to be non pure, if it is called when the derived class doesn't exist anymore
void EventHandler::handle(Event& event)
void EventHandler::handle(Event &event)
{
CLOG(WARNING, INPUT_LOGGER) << "Called EventHandler parent class";
}
}
}
}

View File

@@ -9,32 +9,35 @@
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
*/
#ifndef INPUTEVENTHANDLER_H_
#define INPUTEVENTHANDLER_H_
#ifndef INPUT_IMPL_EVENTHANDLER_H_
#define INPUT_IMPL_EVENTHANDLER_H_
#include "input/IInputDriver.h"
#include "input/InputDriver.h"
#include "input/IEventHandler.h"
#include "input/EventHandler.h"
#include "input/Event.h"
namespace flippR_driver
{
namespace input
{
namespace impl
{
class EventHandler;
class EventHandler : public IEventHandler
class EventHandler : public input::EventHandler
{
public:
explicit EventHandler(std::shared_ptr<IInputDriver> input_driver);
explicit EventHandler(std::shared_ptr<InputDriver> input_driver);
~EventHandler() override;
void handle(Event& event) override;
void handle(Event &event) override;
private:
const std::shared_ptr<IInputDriver> input_driver;
const std::shared_ptr<InputDriver> input_driver;
};
}
}
}
#endif

View File

@@ -15,10 +15,12 @@ namespace flippR_driver
{
namespace input
{
namespace impl
{
EventNotifier::EventNotifier(utility::IBlockingQueue<Event>* queue) :
is_running(true),
event_queue(queue)
EventNotifier::EventNotifier(utility::IBlockingQueue<Event> *queue) :
is_running(true),
event_queue(queue)
{
this->notify_thread = std::thread(&EventNotifier::notify, this);
@@ -37,13 +39,13 @@ EventNotifier::~EventNotifier()
delete this->event_queue;
}
void EventNotifier::register_event_handler(IEventHandler* handler)
void EventNotifier::register_event_handler(EventHandler *handler)
{
std::lock_guard<std::mutex> event_handler_guard(event_handler_mutex);
this->event_handlers.insert(handler);
}
void EventNotifier::unregister_event_handler(IEventHandler* handler)
void EventNotifier::unregister_event_handler(EventHandler *handler)
{
std::lock_guard<std::mutex> event_handler_guard(event_handler_mutex);
this->event_handlers.erase(handler);
@@ -63,19 +65,19 @@ void EventNotifier::notify()
// TODO schoener machen
if(event.name == "END")
{
return;
return;
}
// getting a guard and calling all registered handlers
std::lock_guard<std::mutex> event_handler_guard(this->event_handler_mutex);
for(auto handler : this->event_handlers)
{
boost::thread handler_caller(boost::bind(&IEventHandler::handle, handler, event));
boost::thread handler_caller(boost::bind(&EventHandler::handle, handler, event));
if(!handler_caller.timed_join(boost::posix_time::milliseconds(HANDLER_TIMEOUT)))
if(!handler_caller.timed_join(boost::posix_time::milliseconds(INPUT_HANDLER_TIMEOUT_MILLI)))
{
CLOG(WARNING, INPUT_LOGGER) << "Handler " << typeid(handler).name() << " didn't finish in "
<< HANDLER_TIMEOUT << " milliseconds. Aborting Execution!";
<< INPUT_HANDLER_TIMEOUT_MILLI << " milliseconds. Aborting Execution!";
}
}
}
@@ -83,3 +85,4 @@ void EventNotifier::notify()
}
}
}

View File

@@ -0,0 +1,58 @@
/*
* InputEventNotifier.h
*
* Created on: May 17, 2018
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
*/
#ifndef INPUT_IMPL_EVENTNOTIFIER_H_
#define INPUT_IMPL_EVENTNOTIFIER_H_
#include "input/EventNotifier.h"
#include "input/Event.h"
#include "input/EventHandler.h"
#include "utility/BlockingQueue.hpp"
#include "utility/IBlockingQueue.h"
#include <set>
#include <thread>
#include <mutex>
namespace flippR_driver
{
namespace input
{
namespace impl
{
class EventNotifier : public input::EventNotifier
{
public:
explicit EventNotifier(utility::IBlockingQueue<Event> *queue);
~EventNotifier() override;
void register_event_handler(EventHandler *handler) override;
void unregister_event_handler(EventHandler *handler) override;
void distribute_event(Event &event) override;
private:
void notify();
private:
utility::IBlockingQueue<Event> *event_queue;
std::set<EventHandler *> event_handlers;
bool is_running;
std::thread notify_thread;
std::mutex event_handler_mutex;
};
}
}
}
#endif

View File

@@ -12,20 +12,22 @@ namespace flippR_driver
{
namespace input
{
namespace impl
{
InputDriver::InputDriver(std::shared_ptr<IEventNotifier> event_notifier, std::unique_ptr<IDetector> detector,
InputDriver::InputDriver(std::shared_ptr<EventNotifier> event_notifier, std::unique_ptr<Detector> detector,
std::map<std::string, std::shared_ptr<Event>> events) :
event_notifier(std::move(event_notifier)), detector(std::move(detector)), events(std::move(events))
{
CLOG(INFO, INPUT_LOGGER) << "Created InputDriver";
}
void InputDriver::register_event_handler(IEventHandler *handler)
void InputDriver::register_event_handler(EventHandler *handler)
{
this->event_notifier->register_event_handler(handler);
}
void InputDriver::unregister_event_handler(IEventHandler *handler)
void InputDriver::unregister_event_handler(EventHandler *handler)
{
this->event_notifier->unregister_event_handler(handler);
}
@@ -40,9 +42,10 @@ boost::optional<std::shared_ptr<Event>> InputDriver::get_event(std::string name)
{
CLOG_N_TIMES(1, WARNING, OUTPUT_LOGGER) << "Did not found event " << name << " please check config file!";
}
return boost::optional<std::shared_ptr<Event>>{};
return boost::optional<std::shared_ptr<Event>> {};
}
}
}
}

View File

@@ -0,0 +1,45 @@
/*
* InputDriver.hpp
*
* Created on: May 31, 2018
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
*/
#ifndef INPUT_IMPL_INPUTDRIVER_H_
#define INPUT_IMPL_INPUTDRIVER_H_
#include "input/InputDriver.h"
#include <map>
#include "input/EventNotifier.h"
#include "input/Detector.h"
namespace flippR_driver
{
namespace input
{
namespace impl
{
class InputDriver : public input::InputDriver
{
public:
InputDriver(std::shared_ptr<EventNotifier> event_notifier, std::unique_ptr<Detector> detector, std::map<std::string, std::shared_ptr<Event>> events);
void register_event_handler(EventHandler *handler) override;
void unregister_event_handler(EventHandler *handler) override;
boost::optional<std::shared_ptr<Event>> get_event(std::string name) override;
private:
const std::shared_ptr<EventNotifier> event_notifier;
const std::unique_ptr<Detector> detector;
const std::map<std::string, std::shared_ptr<Event>> events;
};
}
}
}
#endif

View File

@@ -1,11 +1,11 @@
/*
* InputGPIOInterface.cpp
* InputPinController.cpp
*
* Created on: May 31, 2018
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
*/
#include "InputGPIOInterface.h"
#include "InputPinController.h"
#include <thread>
@@ -17,17 +17,18 @@ namespace flippR_driver
{
namespace input
{
namespace impl
{
using namespace nlohmann;
InputGPIOInterface::InputGPIOInterface(std::map<std::string, uint8_t> pins)
: pins(std::move(pins))
InputPinController::InputPinController(std::map<std::string, uint8_t> pins)
: pins(std::move(pins))
{
init_pins();
}
bool InputGPIOInterface::read_data(uint8_t pin) const
bool InputPinController::read_data(uint8_t pin) const
{
// setting address to read
write_row(pin / INPUT_MATRIX_SIZE);
@@ -39,21 +40,21 @@ bool InputGPIOInterface::read_data(uint8_t pin) const
return read_pin(this->pins.at("data_address"));
}
void InputGPIOInterface::write_row(u_int8_t data) const
void InputPinController::write_row(u_int8_t data) const
{
write_pin(this->pins.at("row_address_A"), data & 0b001u);
write_pin(this->pins.at("row_address_B"), data & 0b010u);
write_pin(this->pins.at("row_address_C"), data & 0b100u);
}
void InputGPIOInterface::write_col(uint8_t data) const
void InputPinController::write_col(uint8_t data) const
{
write_pin(this->pins.at("col_address_A"), data & 0b001u);
write_pin(this->pins.at("col_address_B"), data & 0b010u);
write_pin(this->pins.at("col_address_C"), data & 0b100u);
}
void InputGPIOInterface::init_pins() const
void InputPinController::init_pins() const
{
initialize_output_pin(this->pins.at("col_address_A"));
initialize_output_pin(this->pins.at("col_address_B"));
@@ -68,3 +69,4 @@ void InputGPIOInterface::init_pins() const
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* InputGPIOInterface.h
* InputPinController.h
*
* Created on: May 31, 2018
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
@@ -8,22 +8,24 @@
#ifndef SRC_UTILITIES_INPUTGPIOINTERFACE_H_
#define SRC_UTILITIES_INPUTGPIOINTERFACE_H_
#include "IInputGPIOInterface.h"
#include "input/InputPinController.h"
#include <istream>
#include <map>
#include "GPIOInterface.h"
#include "PinController.h"
namespace flippR_driver
{
namespace input
{
namespace impl
{
class InputGPIOInterface : public IInputGPIOInterface, public GPIOInterface
class InputPinController : public input::InputPinController, public PinController
{
public:
explicit InputGPIOInterface(std::map<std::string, uint8_t> pins);
explicit InputPinController(std::map<std::string, uint8_t> pins);
bool read_data(uint8_t pin) const override;
private:
@@ -36,6 +38,7 @@ private:
};
}
}
}
#endif