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

@@ -5,7 +5,7 @@
#include "PrintHandler.h" #include "PrintHandler.h"
#include <iostream> #include <iostream>
PrintHandler::PrintHandler(std::shared_ptr<flippR_driver::input::IInputDriver> driver) : PrintHandler::PrintHandler(std::shared_ptr<flippR_driver::input::InputDriver> driver) :
flippR_driver::input::EventHandler(driver) flippR_driver::input::EventHandler(driver)
{ {

View File

@@ -6,13 +6,13 @@
#define flippR_driver_PRINTHANDLER_H #define flippR_driver_PRINTHANDLER_H
#include <memory> #include <memory>
#include "../src/input/EventHandler.h" #include "../src/input/implementation/EventHandler.h"
#include "input/IInputDriver.h" #include "input/InputDriver.h"
class PrintHandler : public flippR_driver::input::EventHandler class PrintHandler : public flippR_driver::input::EventHandler
{ {
public: public:
PrintHandler(std::shared_ptr<flippR_driver::input::IInputDriver> driver); PrintHandler(std::shared_ptr<flippR_driver::input::InputDriver> driver);
virtual void handle(flippR_driver::input::Event& event) override; virtual void handle(flippR_driver::input::Event& event) override;
}; };

View File

@@ -7,7 +7,7 @@
#include <signal.h> #include <signal.h>
#include "DriverFactory.h" #include "DriverFactory.h"
#include "input/IInputDriver.h" #include "input/InputDriver.h"
#include "PrintHandler.h" #include "PrintHandler.h"
@@ -45,7 +45,7 @@ int main (int argc, char *argv[])
exit(2); exit(2);
} }
std::shared_ptr<input::IInputDriver> driver = flippR_driver::get_InputDriver(input_config, matrix_config); std::shared_ptr<input::InputDriver> driver = flippR_driver::get_InputDriver(input_config, matrix_config);
PrintHandler* print_handler = new PrintHandler(driver); PrintHandler* print_handler = new PrintHandler(driver);

View File

@@ -1,7 +1,28 @@
{ {
"display_board" : "display_board" :
{ {
"display_select" :
{
"1" : 0,
"2" : 0,
"3" : 0,
"4" : 0,
"5" : 0,
},
"segment_select" :
{
"A" : 0,
"B" : 0,
"C" : 0
},
"digit_select" :
{
"A": 0,
"B": 0,
"C": 0,
"D": 0
},
"run" : 0
}, },
"driver_board" : "driver_board" :
{ {
@@ -30,7 +51,7 @@
"i2c_address" : 33, "i2c_address" : 33,
"pin_base" : 81, "pin_base" : 81,
"fire" : 7, "fire" : 7,
"sound_address" : "sound_address_select" :
{ {
"A" : 0, "A" : 0,
"B" : 1, "B" : 1,

View File

@@ -8,13 +8,13 @@
#include <istream> #include <istream>
#include <memory> #include <memory>
#include "input/IInputDriver.h" #include "input/InputDriver.h"
#include "output/IOutputDriver.h" #include "output/OutputDriver.h"
namespace flippR_driver namespace flippR_driver
{ {
std::shared_ptr<input::IInputDriver> get_InputDriver(std::istream& input_config_stream, std::istream& matrix_config_stream); std::shared_ptr<input::InputDriver> get_InputDriver(std::istream& input_config_stream, std::istream& matrix_config_stream);
std::shared_ptr<output::IOutputDriver> get_OutputDriver(std::istream &output_pin_config, std::shared_ptr<output::OutputDriver> get_OutputDriver(std::istream &output_pin_config,
std::istream &lamp_config, std::istream &lamp_config,
std::istream &solenoid_config, std::istream &solenoid_config,
std::istream &sound_config, std::istream &sound_config,

View File

@@ -13,30 +13,30 @@
#include <chrono> #include <chrono>
namespace flippR_driver { namespace flippR_driver {
namespace input { namespace input {
class Event { class Event {
public: public:
Event(char address, int priority, std::string name); Event(uint8_t address, int priority, std::string name);
friend bool operator==(const Event &left, const Event &right); friend bool operator==(const Event &left, const Event &right);
friend bool operator<(const Event &left, const Event &right) {
return left.priority < right.priority;
}
public:
std::string name;
uint8_t address;
int priority;
std::chrono::time_point<std::chrono::high_resolution_clock> last_activation;
};
bool operator==(const Event &left, const Event &right);
friend bool operator<(const Event &left, const Event &right) {
return left.priority < right.priority;
} }
public:
std::string name;
uint8_t address;
int priority;
std::chrono::time_point<std::chrono::high_resolution_clock> last_activation;
};
bool operator==(const Event &left, const Event &right);
}
} }
#endif /* INPUTEVENT_H_ */ #endif /* INPUTEVENT_H_ */

View File

@@ -1,5 +1,5 @@
/* /*
* IEventHandler.h * EventHandler.h
* *
* Created on: Jun 13, 2018 * Created on: Jun 13, 2018
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert * Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
@@ -10,12 +10,19 @@
#include "input/Event.h" #include "input/Event.h"
class IEventHandler namespace flippR_driver
{
namespace input
{
class EventHandler
{ {
public: public:
virtual ~IEventHandler(){}; virtual ~EventHandler() = default;
virtual void handle(flippR_driver::input::Event& event) = 0; virtual void handle(flippR_driver::input::Event &event) = 0;
}; };
}
}
#endif /* SRC_IEVENTHANDLER_H_ */ #endif /* SRC_IEVENTHANDLER_H_ */

View File

@@ -1,32 +0,0 @@
/*
* IInputDriver.h
*
* Created on: Jun 14, 2018
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
*/
#ifndef SRC_INPUT_IINPUTDRIVER_H_
#define SRC_INPUT_IINPUTDRIVER_H_
#include <memory>
#include <boost/optional.hpp>
#include "input/IEventHandler.h"
namespace flippR_driver
{
namespace input
{
class IInputDriver {
public:
virtual ~IInputDriver() {};
virtual void register_event_handler(IEventHandler *handler) = 0;
virtual void unregister_event_handler(IEventHandler *handler) = 0;
virtual boost::optional<std::shared_ptr<Event>> get_event(std::string name) = 0;
};
}
}
#endif /* SRC_INPUT_IINPUTDRIVER_H_ */

View File

@@ -0,0 +1,34 @@
/*
* InputDriver.h
*
* Created on: Jun 14, 2018
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
*/
#ifndef SRC_INPUT_IINPUTDRIVER_H_
#define SRC_INPUT_IINPUTDRIVER_H_
#include <memory>
#include <boost/optional.hpp>
#include "input/EventHandler.h"
namespace flippR_driver
{
namespace input
{
class InputDriver {
public:
virtual ~InputDriver() = default;
virtual void register_event_handler(EventHandler *handler) = 0;
virtual void unregister_event_handler(EventHandler *handler) = 0;
virtual boost::optional<std::shared_ptr<Event>> get_event(std::string name) = 0;
};
}
}
#endif /* SRC_INPUT_IINPUTDRIVER_H_ */

View File

@@ -1,5 +1,5 @@
/* /*
* IOutputDriver.h * OutputDriver.h
* *
* Created on: Aug 2, 2018 * Created on: Aug 2, 2018
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert * Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
@@ -22,10 +22,10 @@ namespace flippR_driver
namespace output namespace output
{ {
class IOutputDriver class OutputDriver
{ {
public: public:
virtual ~IOutputDriver() = default; virtual ~OutputDriver() = default;
virtual std::vector<std::shared_ptr<items::ILamp>> get_lamps() = 0; virtual std::vector<std::shared_ptr<items::ILamp>> get_lamps() = 0;
virtual std::vector<std::shared_ptr<items::ISolenoid>> get_solenoids() = 0; virtual std::vector<std::shared_ptr<items::ISolenoid>> get_solenoids() = 0;

View File

@@ -270,7 +270,7 @@ using enable_if_t = typename std::enable_if<B, T>::type;
template<typename T> template<typename T>
using uncvref_t = typename std::remove_cv<typename std::remove_reference<T>::type>::type; using uncvref_t = typename std::remove_cv<typename std::remove_reference<T>::type>::type;
// implementation of C++14 index_sequence and affiliates // impl of C++14 index_sequence and affiliates
// source: https://stackoverflow.com/a/32223343 // source: https://stackoverflow.com/a/32223343
template<std::size_t... Ints> template<std::size_t... Ints>
struct index_sequence struct index_sequence
@@ -7369,7 +7369,7 @@ boundaries compute_boundaries(FloatType value)
// value = 1.F * 2^(E - bias) = (2^(p-1) + F) * 2^(E - bias - (p-1)) // value = 1.F * 2^(E - bias) = (2^(p-1) + F) * 2^(E - bias - (p-1))
static_assert(std::numeric_limits<FloatType>::is_iec559, static_assert(std::numeric_limits<FloatType>::is_iec559,
"internal error: dtoa_short requires an IEEE-754 floating-point implementation"); "internal error: dtoa_short requires an IEEE-754 floating-point impl");
constexpr int kPrecision = std::numeric_limits<FloatType>::digits; // = p (includes the hidden bit) constexpr int kPrecision = std::numeric_limits<FloatType>::digits; // = p (includes the hidden bit)
constexpr int kBias = std::numeric_limits<FloatType>::max_exponent - 1 + (kPrecision - 1); constexpr int kBias = std::numeric_limits<FloatType>::max_exponent - 1 + (kPrecision - 1);

View File

@@ -4,17 +4,17 @@
#include "DriverFactory.h" #include "DriverFactory.h"
#include "input/InputDriverFactory.h" #include "input/implementation/InputDriverFactory.h"
#include "output/OutputDriverFactory.h" #include "output/OutputDriverFactory.h"
namespace flippR_driver namespace flippR_driver
{ {
std::shared_ptr<input::IInputDriver> get_InputDriver(std::istream& input_config_stream, std::istream& matrix_config_stream) std::shared_ptr<input::InputDriver> get_InputDriver(std::istream& input_config_stream, std::istream& matrix_config_stream)
{ {
return input::InputDriverFactory::get_InputDriver(input_config_stream, matrix_config_stream); return input::InputDriverFactory::get_InputDriver(input_config_stream, matrix_config_stream);
} }
std::shared_ptr<output::IOutputDriver> get_OutputDriver(std::istream &output_pin_config, std::shared_ptr<output::OutputDriver> get_OutputDriver(std::istream &output_pin_config,
std::istream &lamp_config, std::istream &lamp_config,
std::istream &solenoid_config, std::istream &solenoid_config,
std::istream &sound_config, std::istream &sound_config,

View File

@@ -1,11 +1,11 @@
/* /*
* GPIOInterface.cpp * PinController.cpp
* *
* Created on: Jun 15, 2018 * Created on: Jun 15, 2018
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert * Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
*/ */
#include "GPIOInterface.h" #include "PinController.h"
#include "utility/config.h" #include "utility/config.h"
@@ -15,29 +15,29 @@
namespace flippR_driver namespace flippR_driver
{ {
std::once_flag GPIOInterface::GPIO_LIB_INITIALIZED; std::once_flag PinController::GPIO_LIB_INITIALIZED;
GPIOInterface::GPIOInterface() PinController::PinController()
{ {
std::call_once(GPIO_LIB_INITIALIZED, wiringPiSetup); std::call_once(GPIO_LIB_INITIALIZED, wiringPiSetup);
} }
void GPIOInterface::initialize_input_pin(uint8_t address) void PinController::initialize_input_pin(uint8_t address)
{ {
pinMode(address, INPUT); pinMode(address, INPUT);
} }
void GPIOInterface::initialize_output_pin(uint8_t address) void PinController::initialize_output_pin(uint8_t address)
{ {
pinMode(address, OUTPUT); pinMode(address, OUTPUT);
} }
void GPIOInterface::write_pin(uint8_t address, uint8_t data) void PinController::write_pin(uint8_t address, bool value)
{ {
digitalWrite(address, data); digitalWrite(address, value);
} }
bool GPIOInterface::read_pin(uint8_t address) bool PinController::read_pin(uint8_t address)
{ {
return PULLDOWN == digitalRead(address); return PULLDOWN == digitalRead(address);
} }

View File

@@ -1,5 +1,5 @@
/* /*
* GPIOInterface.hpp * PinController.hpp
* *
* Responsible for communicating with the actual GPIO hardware. * Responsible for communicating with the actual GPIO hardware.
* *
@@ -18,18 +18,18 @@
namespace flippR_driver namespace flippR_driver
{ {
class GPIOInterface class PinController
{ {
public: public:
GPIOInterface(); PinController();
virtual ~GPIOInterface() = default; virtual ~PinController() = default;
protected: protected:
static void initialize_input_pin(uint8_t address); static void initialize_input_pin(uint8_t address);
static void initialize_output_pin(uint8_t address); static void initialize_output_pin(uint8_t address);
static void write_pin(uint8_t address, uint8_t data); static void write_pin(uint8_t address, bool value);
static bool read_pin(uint8_t address); static bool read_pin(uint8_t address);

View File

@@ -1,55 +1,27 @@
/* /*
* Detector.h * Detector.h
* *
* Responsible for detecting InputEvents. * Created on: Jun 13, 2018
*
* 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 * Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
*/ */
#ifndef DETECTOR_H_ #ifndef SRC_INPUT_DETECTOR_H_
#define 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 flippR_driver
{ {
namespace input namespace input
{ {
class Detector : public IDetector class Detector
{ {
public: public:
Detector(std::unique_ptr<IInputGPIOInterface> input_gpio_interface, std::vector<std::shared_ptr<DistributingEvent>> events); virtual ~Detector() = default;
~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;
}; };
} }
} }
#endif #endif

View File

@@ -4,20 +4,26 @@
#include "DistributingEvent.h" #include "DistributingEvent.h"
flippR_driver::input::DistributingEvent::DistributingEvent(char address, int priority, std::string name, namespace flippR_driver
std::chrono::milliseconds bounce_time, std::shared_ptr<IEventNotifier> event_notifier): {
Event(address, priority, std::move(name)), namespace input
bounce_time(bounce_time), {
event_notifier(std::move(event_notifier)),
activation_state(NOT_ACTIVATED) 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); event_notifier->distribute_event(*this);
} }
void flippR_driver::input::DistributingEvent::active() void DistributingEvent::active()
{ {
if(!is_bouncing()) 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::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); 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; return elapsed_time < bounce_time;
} }
void flippR_driver::input::DistributingEvent::inactive() void DistributingEvent::inactive()
{ {
if(activation_state == ACTIVATED) 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 #define flippR_driver_DISTRIBUTINGEVENT_H
#include "input/Event.h" #include "input/Event.h"
#include "IEventNotifier.h" #include "input/EventNotifier.h"
namespace flippR_driver namespace flippR_driver
{ {
namespace input namespace input
{ {
class DistributingEvent : public Event class DistributingEvent : public Event
{ {
public: public:
DistributingEvent(char address, int priority, std::string name, 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 active();
void inactive(); void inactive();
@@ -37,11 +38,12 @@ private:
ACTIVATED ACTIVATED
}; };
const std::shared_ptr<IEventNotifier> event_notifier; const std::shared_ptr<EventNotifier> event_notifier;
ActivationState activation_state; ActivationState activation_state;
}; };
} }
} }

View File

@@ -13,8 +13,7 @@ namespace flippR_driver
namespace input namespace input
{ {
// todo unsigned char address Event::Event(uint8_t address, int priority, std::string name) :
Event::Event(char address, int priority, std::string name) :
address(address), priority(priority), name(name) address(address), priority(priority), name(name)
{ {
CLOG_IF(VLOG_IS_ON(0), INFO, INPUT_LOGGER) << "Created event: " << name << ", address: " << address; 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 * Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
*/ */
#ifndef SRC_INPUT_EVENTNOTIFIER_H_ #ifndef SRC_INPUT_IEVENTNOTIFIER_H_
#define SRC_INPUT_EVENTNOTIFIER_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/Event.h"
#include "input/EventHandler.h" #include "input/EventHandler.h"
#include <memory>
#define HANDLER_TIMEOUT 2000
namespace flippR_driver namespace flippR_driver
{ {
namespace input namespace input
{ {
class EventNotifier : public IEventNotifier class EventNotifier
{ {
public: public:
explicit EventNotifier(utility::IBlockingQueue<Event>* queue); virtual ~EventNotifier() = default;
~EventNotifier() override;
void register_event_handler(IEventHandler* handler) override; virtual void register_event_handler(EventHandler* handler) = 0;
void unregister_event_handler(IEventHandler* handler) override; virtual void unregister_event_handler(EventHandler* handler) = 0;
void distribute_event(Event &event) override; virtual void distribute_event(Event &event) = 0;
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;
}; };
}
} }
#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 "utility/LoggerFactory.h"
#include "InputDriver.h" #include "input/impl/InputDriver.h"
#include "EventNotifier.h" #include "input/impl/EventNotifier.h"
#include "Detector.h" #include "input/impl/Detector.h"
namespace flippR_driver namespace flippR_driver
{ {
@@ -26,63 +26,64 @@ namespace InputDriverFactory
using namespace nlohmann; using namespace nlohmann;
using namespace flippR_driver::utility; 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(); LoggerFactory::CreateInputLogger();
IBlockingQueue<Event> *event_queue = new BlockingQueue<Event>; 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::vector<std::shared_ptr<DistributingEvent>> events;
std::map<std::string, std::shared_ptr<Event>> name_event_map; std::map<std::string, std::shared_ptr<Event>> name_event_map;
create_events(matrix_config_stream, events, name_event_map, event_notifier); 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<InputPinController> input_gpio_interface(new impl::InputPinController(create_pin_map(input_pin_stream)));
std::unique_ptr<IDetector> detector(new Detector(std::move(input_gpio_interface), events)); 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 namespace
{ {
void create_events(std::istream &matrix_config_stream, std::vector<std::shared_ptr<DistributingEvent>> &events, 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::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; json matrix_config;
matrix_config_stream >> matrix_config; matrix_config_stream >> matrix_config;
int global_bounce_time = matrix_config.at("global_bounce_time").get<uint8_t>(); try
auto &json_events = matrix_config.at("input_matrix");
for(auto &json_event : json_events)
{ {
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); std::shared_ptr<DistributingEvent> event = create_event(json_event, event_notifier, global_bounce_time);
events.push_back(event); events.push_back(event);
name_event_map.emplace(event->name, 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) 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); 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) void set_individual_bounce_time(json &json_event, int &bounce_time)
{ {
auto it_bounce_time = json_event.find("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>(); 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(); CLOG(ERROR, INPUT_LOGGER) << "Input pin config file corrupted! " << e.what();
exit(EXIT_FAILURE);
}
catch(json::out_of_range &e)
{
CLOG(ERROR, INPUT_LOGGER) << "Input json corrupted! " << e.what();
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }

View File

@@ -11,10 +11,10 @@
#include <istream> #include <istream>
#include "json/json.hpp" #include "json/json.hpp"
#include "input/IInputDriver.h" #include "input/InputDriver.h"
#include "DistributingEvent.h" #include "DistributingEvent.h"
#include "InputGPIOInterface.h" #include "input/impl/InputPinController.h"
#include "IEventNotifier.h" #include "input/EventNotifier.h"
namespace flippR_driver namespace flippR_driver
{ {
@@ -22,16 +22,16 @@ namespace input
{ {
namespace InputDriverFactory 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 namespace
{ {
static void create_events(std::istream &matrix_config, static void create_events(std::istream &matrix_config,
std::vector<std::shared_ptr<DistributingEvent>> &events, std::vector<std::shared_ptr<DistributingEvent>> &events,
std::map<std::string, std::shared_ptr<Event>> &name_event_map, 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 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); 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 * Created on: May 31, 2018
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert * Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
@@ -15,10 +15,10 @@ namespace flippR_driver
namespace input namespace input
{ {
class IInputGPIOInterface class InputPinController
{ {
public: public:
virtual ~IInputGPIOInterface() = default; virtual ~InputGPIOInterface() = default;
virtual bool read_data(uint8_t pin) const = 0; virtual bool read_data(uint8_t pin) const = 0;
}; };

View File

@@ -15,9 +15,12 @@ namespace flippR_driver
{ {
namespace input namespace input
{ {
namespace impl
{
Detector::Detector(std::unique_ptr<IInputGPIOInterface> input_gpio_interface, std::vector<std::shared_ptr<DistributingEvent>> events) : 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) :
input_gpio_interface(std::move(input_gpio_interface)), events(std::move(events)), is_running(true)
{ {
this->detect_thread = std::thread(&Detector::detect, this); this->detect_thread = std::thread(&Detector::detect, this);
@@ -41,7 +44,7 @@ void Detector::detect()
void Detector::check_inputs() void Detector::check_inputs()
{ {
for(auto& event : events) for(auto &event : events)
{ {
input_gpio_interface->read_data(event->address) ? event->active() : event->inactive(); 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 * Created on: Jun 14, 2018
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert * Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
*/ */
#include "input/EventHandler.h" #include "EventHandler.h"
#include "utility/config.h" #include "utility/config.h"
namespace flippR_driver namespace flippR_driver
{ {
namespace input namespace input
{ {
namespace impl
{
EventHandler::EventHandler(std::shared_ptr<IInputDriver> input_driver) : EventHandler::EventHandler(std::shared_ptr<InputDriver> input_driver) :
input_driver(std::move(input_driver)) input_driver(std::move(input_driver))
{ {
this->input_driver->register_event_handler(this); 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 // 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"; CLOG(WARNING, INPUT_LOGGER) << "Called EventHandler parent class";
} }
} }
} }
}

View File

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

View File

@@ -15,10 +15,12 @@ namespace flippR_driver
{ {
namespace input namespace input
{ {
namespace impl
{
EventNotifier::EventNotifier(utility::IBlockingQueue<Event>* queue) : EventNotifier::EventNotifier(utility::IBlockingQueue<Event> *queue) :
is_running(true), is_running(true),
event_queue(queue) event_queue(queue)
{ {
this->notify_thread = std::thread(&EventNotifier::notify, this); this->notify_thread = std::thread(&EventNotifier::notify, this);
@@ -37,13 +39,13 @@ EventNotifier::~EventNotifier()
delete this->event_queue; 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); std::lock_guard<std::mutex> event_handler_guard(event_handler_mutex);
this->event_handlers.insert(handler); 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); std::lock_guard<std::mutex> event_handler_guard(event_handler_mutex);
this->event_handlers.erase(handler); this->event_handlers.erase(handler);
@@ -63,19 +65,19 @@ void EventNotifier::notify()
// TODO schoener machen // TODO schoener machen
if(event.name == "END") if(event.name == "END")
{ {
return; return;
} }
// getting a guard and calling all registered handlers // getting a guard and calling all registered handlers
std::lock_guard<std::mutex> event_handler_guard(this->event_handler_mutex); std::lock_guard<std::mutex> event_handler_guard(this->event_handler_mutex);
for(auto handler : this->event_handlers) 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 " 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 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) : std::map<std::string, std::shared_ptr<Event>> events) :
event_notifier(std::move(event_notifier)), detector(std::move(detector)), events(std::move(events)) event_notifier(std::move(event_notifier)), detector(std::move(detector)), events(std::move(events))
{ {
CLOG(INFO, INPUT_LOGGER) << "Created InputDriver"; 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); 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); 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!"; 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 * Created on: May 31, 2018
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert * Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
*/ */
#include "InputGPIOInterface.h" #include "InputPinController.h"
#include <thread> #include <thread>
@@ -17,17 +17,18 @@ namespace flippR_driver
{ {
namespace input namespace input
{ {
namespace impl
{
using namespace nlohmann; using namespace nlohmann;
InputPinController::InputPinController(std::map<std::string, uint8_t> pins)
InputGPIOInterface::InputGPIOInterface(std::map<std::string, uint8_t> pins) : pins(std::move(pins))
: pins(std::move(pins))
{ {
init_pins(); init_pins();
} }
bool InputGPIOInterface::read_data(uint8_t pin) const bool InputPinController::read_data(uint8_t pin) const
{ {
// setting address to read // setting address to read
write_row(pin / INPUT_MATRIX_SIZE); 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")); 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_A"), data & 0b001u);
write_pin(this->pins.at("row_address_B"), data & 0b010u); write_pin(this->pins.at("row_address_B"), data & 0b010u);
write_pin(this->pins.at("row_address_C"), data & 0b100u); 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_A"), data & 0b001u);
write_pin(this->pins.at("col_address_B"), data & 0b010u); write_pin(this->pins.at("col_address_B"), data & 0b010u);
write_pin(this->pins.at("col_address_C"), data & 0b100u); 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_A"));
initialize_output_pin(this->pins.at("col_address_B")); 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 * Created on: May 31, 2018
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert * Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
@@ -8,22 +8,24 @@
#ifndef SRC_UTILITIES_INPUTGPIOINTERFACE_H_ #ifndef SRC_UTILITIES_INPUTGPIOINTERFACE_H_
#define SRC_UTILITIES_INPUTGPIOINTERFACE_H_ #define SRC_UTILITIES_INPUTGPIOINTERFACE_H_
#include "IInputGPIOInterface.h" #include "input/InputPinController.h"
#include <istream> #include <istream>
#include <map> #include <map>
#include "GPIOInterface.h" #include "PinController.h"
namespace flippR_driver namespace flippR_driver
{ {
namespace input namespace input
{ {
namespace impl
{
class InputGPIOInterface : public IInputGPIOInterface, public GPIOInterface class InputPinController : public input::InputPinController, public PinController
{ {
public: 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; bool read_data(uint8_t pin) const override;
private: private:
@@ -36,6 +38,7 @@ private:
}; };
}
} }
} }
#endif #endif

View File

@@ -1,45 +1,24 @@
/* /*
* DisplayController.h * DisplayController.h
* *
* Created on: Aug 7, 2018 * Created on: Aug 2, 2018
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert * Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
*/ */
#ifndef _SRC_OUTPUT_DISPLAYCONTROLLER_H_ #ifndef _SRC_OUTPUT_IDISPLAYCONTROLLER_H_
#define _SRC_OUTPUT_DISPLAYCONTROLLER_H_ #define _SRC_OUTPUT_IDISPLAYCONTROLLER_H_
#include "IDisplayController.h"
#include <vector>
#include <thread>
#include "items/IDisplay.h"
#include "IOutputGPIOInterface.h"
namespace flippR_driver namespace flippR_driver
{ {
namespace output namespace output
{ {
class DisplayController : public IDisplayController class DisplayController
{ {
public: public:
explicit DisplayController(std::vector<std::shared_ptr<items::IDisplay>> displays, std::shared_ptr<IOutputGPIOInterface> output_gpio_interface); virtual ~DisplayController () = default;
~DisplayController() override;
private:
void cycle_displays();
private:
std::vector<std::shared_ptr<items::IDisplay>> displays;
std::thread display_cycle_thread;
std::shared_ptr<IOutputGPIOInterface> output_gpio_interface;
bool is_running;
}; };
} } /* namespace output */
} }
#endif #endif

View File

@@ -0,0 +1,5 @@
//
// Created by rhetenor on 14.12.18.
//
#include "DisplayPinController.h"

View File

@@ -0,0 +1,13 @@
//
// Created by rhetenor on 14.12.18.
//
#ifndef FLIPPR_DRIVER_DISPLAYPINCONTROLLER_H
#define FLIPPR_DRIVER_DISPLAYPINCONTROLLER_H
class DisplayPinController
{
};
#endif //FLIPPR_DRIVER_DISPLAYPINCONTROLLER_H

View File

@@ -0,0 +1,24 @@
//
// Created by rhetenor on 13.12.18.
//
#ifndef FLIPPR_DRIVER_DRIVERBOARDPINCONTROLLER_H
#define FLIPPR_DRIVER_DRIVERBOARDPINCONTROLLER_H
namespace flippR_driver
{
namespace output
{
class DriverBoardPinController
{
public:
virtual ~DriverBoardPinController() = default;
virtual void activate(items::DriverBoardItem *driver_board_item) = 0;
virtual void deactivate(items::DriverBoardItem *driver_board_item) = 0;
};
}
}
#endif //FLIPPR_DRIVER_DRIVERBOARDPINCONTROLLER_H

View File

@@ -1,24 +0,0 @@
/*
* IDisplayController.h
*
* Created on: Aug 2, 2018
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
*/
#ifndef _SRC_OUTPUT_IDISPLAYCONTROLLER_H_
#define _SRC_OUTPUT_IDISPLAYCONTROLLER_H_
namespace flippR_driver
{
namespace output
{
class IDisplayController
{
public:
virtual ~IDisplayController () = default;
};
} /* namespace output */
}
#endif

View File

@@ -4,8 +4,10 @@
#include "OutputDriverFactory.h" #include "OutputDriverFactory.h"
#include "OutputDriver.h" #include "utility/LoggerFactory.h"
#include "OutputGPIOInterface.h"
#include "output/impl/OutputDriver.h"
#include "output/impl/OutputPinController.h"
namespace flippR_driver namespace flippR_driver
{ {
@@ -19,9 +21,11 @@ namespace
using namespace nlohmann; using namespace nlohmann;
std::shared_ptr<IOutputDriver> get_OutputDriver(std::istream &output_pin_config, std::istream &solenoid_config, std::istream &lamp_config, std::istream &sound_config, std::istream &display_config) std::shared_ptr<OutputDriver> get_OutputDriver(std::istream &output_pin_config, std::istream &solenoid_config, std::istream &lamp_config, std::istream &sound_config, std::istream &display_config)
{ {
std::shared_ptr<IOutputGPIOInterface> output_gpio_interface = std::shared_ptr<IOutputGPIOInterface>(create_OutputGPIOInterface(output_pin_config)); utility::LoggerFactory::CreateOutputLogger();
std::shared_ptr<OutputPinController> output_gpio_interface = std::shared_ptr<OutputPinController>(create_OutputGPIOInterface(output_pin_config));
auto solenoids = create_solenoids(solenoid_config, output_gpio_interface); auto solenoids = create_solenoids(solenoid_config, output_gpio_interface);
auto lamps = create_lamps(lamp_config, output_gpio_interface); auto lamps = create_lamps(lamp_config, output_gpio_interface);
@@ -32,7 +36,7 @@ std::shared_ptr<IOutputDriver> get_OutputDriver(std::istream &output_pin_config,
return std::make_shared<OutputDriver>(solenoids, lamps, sounds, displays); return std::make_shared<OutputDriver>(solenoids, lamps, sounds, displays);
} }
IOutputGPIOInterface* create_OutputGPIOInterface(std::istream &output_pin_config) OutputPinController* create_OutputGPIOInterface(std::istream &output_pin_config)
{ {
json output_config; json output_config;
output_pin_config >> output_config; output_pin_config >> output_config;
@@ -46,52 +50,74 @@ std::map<std::string, uint8_t> parse_pins_driver_board(json &driver_board_config
{ {
std::map<std::string, uint8_t> pins_driver_board; std::map<std::string, uint8_t> pins_driver_board;
pins_driver_board["i2c_address"] = driver_board_config.at("i2c_address").get<uint8_t>(); try
pins_driver_board["pin_base"] = driver_board_config.at("pin_base").get<uint8_t>(); {
pins_driver_board["data"] = driver_board_config.at("data").get<uint8_t>(); pins_driver_board["i2c_address"] = driver_board_config.at("i2c_address").get<uint8_t>();
pins_driver_board["CL"] = driver_board_config.at("CL").get<uint8_t>(); pins_driver_board["pin_base"] = driver_board_config.at("pin_base").get<uint8_t>();
pins_driver_board["data"] = driver_board_config.at("data").get<uint8_t>();
pins_driver_board["CL"] = driver_board_config.at("CL").get<uint8_t>();
json pin_select = driver_board_config.at("pin-select"); json pin_select = driver_board_config.at("pin-select");
pins_driver_board["pin-select-A"] = pin_select.at("A").get<uint8_t>(); pins_driver_board["pin-select-A"] = pin_select.at("A").get<uint8_t>();
pins_driver_board["pin-select-B"] = pin_select.at("B").get<uint8_t>(); pins_driver_board["pin-select-B"] = pin_select.at("B").get<uint8_t>();
pins_driver_board["pin-select-C"] = pin_select.at("C").get<uint8_t>(); pins_driver_board["pin-select-C"] = pin_select.at("C").get<uint8_t>();
json latch_select = driver_board_config.at("latch-select");
pins_driver_board["mux1"] = latch_select.at("mux1").get<uint8_t>();
pins_driver_board["mux2"] = latch_select.at("mux2").get<uint8_t>();
pins_driver_board["latch-select-A"] = latch_select.at("A").get<uint8_t>();
pins_driver_board["latch-select-B"] = latch_select.at("B").get<uint8_t>();
pins_driver_board["latch-select-C"] = latch_select.at("C").get<uint8_t>();
json latch_select = driver_board_config.at("latch-select");
pins_driver_board["mux1"] = latch_select.at("mux1").get<uint8_t>();
pins_driver_board["mux2"] = latch_select.at("mux2").get<uint8_t>();
pins_driver_board["latch-select-A"] = latch_select.at("A").get<uint8_t>();
pins_driver_board["latch-select-B"] = latch_select.at("B").get<uint8_t>();
pins_driver_board["latch-select-C"] = latch_select.at("C").get<uint8_t>();
}
catch(json::exception &e)
{
CLOG(ERROR, OUTPUT_LOGGER) << "Output pin config file at driver_board corrupted: " << e.what();
exit(EXIT_FAILURE);
}
return pins_driver_board; return pins_driver_board;
} }
std::map<std::string, uint8_t> parse_pins_sound(json &sound_board_config) std::map<std::string, uint8_t> parse_pins_sound(json &sound_board_config)
{ {
std::map<std::string, uint8_t> pins_sound; std::map<std::string, uint8_t> pins_sound;
try
{
pins_sound["i2c_address"] = sound_board_config.at("i2c_address").get<uint8_t>();
pins_sound["pin_base"] = sound_board_config.at("pin_base").get<uint8_t>();
pins_sound["fire"] = sound_board_config.at("fire").get<uint8_t>();
pins_sound["i2c_address"] = sound_board_config.at("i2c_address").get<uint8_t>(); json sound_address = sound_board_config.at("sound_address_select");
pins_sound["pin_base"] = sound_board_config.at("pin_base").get<uint8_t>(); pins_sound["A"] = sound_address.at("A").get<uint8_t>();
pins_sound["fire"] = sound_board_config.at("fire").get<uint8_t>(); pins_sound["B"] = sound_address.at("B").get<uint8_t>();
pins_sound["C"] = sound_address.at("C").get<uint8_t>();
json sound_address = sound_board_config.at("sound_address"); pins_sound["D"] = sound_address.at("D").get<uint8_t>();
pins_sound["A"] = sound_address.at("A").get<uint8_t>(); pins_sound["E"] = sound_address.at("E").get<uint8_t>();
pins_sound["B"] = sound_address.at("B").get<uint8_t>(); pins_sound["F"] = sound_address.at("F").get<uint8_t>();
pins_sound["C"] = sound_address.at("C").get<uint8_t>(); pins_sound["G"] = sound_address.at("G").get<uint8_t>();
pins_sound["D"] = sound_address.at("D").get<uint8_t>(); }
pins_sound["E"] = sound_address.at("E").get<uint8_t>(); catch(json::exception &e)
pins_sound["F"] = sound_address.at("F").get<uint8_t>(); {
pins_sound["G"] = sound_address.at("G").get<uint8_t>(); CLOG(ERROR, OUTPUT_LOGGER) << "Output pin config file at sound_board corrupted: " << e.what();
exit(EXIT_FAILURE);
}
return pins_sound; return pins_sound;
} }
std::map<std::string, uint8_t> parse_pins_display(json &display_board_config) std::map<std::string, uint8_t> parse_pins_display(json &display_board_config)
{ {
return std::map<std::string, uint8_t>(); std::map<std::string, uint8_t> pins_display;
try
{
pins_display["run"] = display_board_config.at("run");
}
catch(json::exception &e)
{
CLOG(ERROR, OUTPUT_LOGGER) << "Output pin config file at display_board corrupted: " << e.what();
exit(EXIT_FAILURE);
}
} }
std::map<std::string, std::shared_ptr<items::ISolenoid>> create_solenoids(std::istream &solenoid_config, std::shared_ptr<IOutputGPIOInterface> output_gpio_interface) std::map<std::string, std::shared_ptr<items::ISolenoid>> create_solenoids(std::istream &solenoid_config, std::shared_ptr<OutputPinController> output_gpio_interface)
{ {
std::map<std::string, std::shared_ptr<items::ISolenoid>> solenoids; std::map<std::string, std::shared_ptr<items::ISolenoid>> solenoids;
@@ -108,7 +134,7 @@ std::map<std::string, std::shared_ptr<items::ISolenoid>> create_solenoids(std::i
return solenoids; return solenoids;
} }
std::map<std::string, std::shared_ptr<items::ILamp>> create_lamps(std::istream &lamp_config, std::shared_ptr<IOutputGPIOInterface> output_gpio_interface) std::map<std::string, std::shared_ptr<items::ILamp>> create_lamps(std::istream &lamp_config, std::shared_ptr<OutputPinController> output_gpio_interface)
{ {
std::map<std::string, std::shared_ptr<items::ILamp>> lamps; std::map<std::string, std::shared_ptr<items::ILamp>> lamps;
@@ -124,7 +150,7 @@ std::map<std::string, std::shared_ptr<items::ILamp>> create_lamps(std::istream &
return lamps; return lamps;
} }
std::map<std::string, std::shared_ptr<items::ISound>> create_sounds(std::istream &sound_config, std::shared_ptr<IOutputGPIOInterface> output_gpio_interface) std::map<std::string, std::shared_ptr<items::ISound>> create_sounds(std::istream &sound_config, std::shared_ptr<OutputPinController> output_gpio_interface)
{ {
std::map<std::string, std::shared_ptr<items::ISound>> sounds; std::map<std::string, std::shared_ptr<items::ISound>> sounds;
@@ -156,7 +182,7 @@ std::chrono::milliseconds get_deactivation_time(nlohmann::json &json)
} }
} }
std::shared_ptr<items::Solenoid> create_solenoid(nlohmann::json &solenoid_json, std::shared_ptr<IOutputGPIOInterface> output_gpio_interface, std::chrono::milliseconds deactivation_time) std::shared_ptr<items::Solenoid> create_solenoid(nlohmann::json &solenoid_json, std::shared_ptr<OutputPinController> output_gpio_interface, std::chrono::milliseconds deactivation_time)
{ {
try try
{ {
@@ -177,7 +203,7 @@ std::shared_ptr<items::Solenoid> create_solenoid(nlohmann::json &solenoid_json,
} }
} }
std::shared_ptr<items::Lamp> create_lamp(nlohmann::json &lamp_json, std::shared_ptr<IOutputGPIOInterface> output_gpio_interface) std::shared_ptr<items::Lamp> create_lamp(nlohmann::json &lamp_json, std::shared_ptr<OutputPinController> output_gpio_interface)
{ {
try try
{ {
@@ -192,7 +218,7 @@ std::shared_ptr<items::Lamp> create_lamp(nlohmann::json &lamp_json, std::shared_
} }
} }
std::shared_ptr<items::Sound> create_sound(nlohmann::json &sound_json, std::shared_ptr<IOutputGPIOInterface> &output_gpio_interface, std::chrono::milliseconds deactivation_time) std::shared_ptr<items::Sound> create_sound(nlohmann::json &sound_json, std::shared_ptr<OutputPinController> &output_gpio_interface, std::chrono::milliseconds deactivation_time)
{ {
try try
{ {

View File

@@ -5,11 +5,11 @@
#ifndef flippR_driver_OUTPUTDRIVERFACTORY_H #ifndef flippR_driver_OUTPUTDRIVERFACTORY_H
#define flippR_driver_OUTPUTDRIVERFACTORY_H #define flippR_driver_OUTPUTDRIVERFACTORY_H
#include "output/IOutputDriver.h" #include "output/OutputDriver.h"
#include "output/items/Solenoid.h" #include "output/items/Solenoid.h"
#include "output/items/Lamp.h" #include "output/items/Lamp.h"
#include "output/items/Sound.h" #include "output/items/Sound.h"
#include "IOutputGPIOInterface.h" #include "OutputPinController.h"
#include "json/json.hpp" #include "json/json.hpp"
#include <memory> #include <memory>
@@ -20,24 +20,24 @@ namespace output
{ {
namespace OutputDriverFactory namespace OutputDriverFactory
{ {
std::shared_ptr<IOutputDriver> get_OutputDriver(std::istream &output_pin_config, std::istream &solenoid_config, std::istream &lamp_config, std::istream &sound_config, std::istream &display_config); std::shared_ptr<OutputDriver> get_OutputDriver(std::istream &output_pin_config, std::istream &solenoid_config, std::istream &lamp_config, std::istream &sound_config, std::istream &display_config);
namespace namespace
{ {
std::map<std::string, std::shared_ptr<items::ISolenoid>> create_solenoids(std::istream &solenoid_config, std::shared_ptr<IOutputGPIOInterface> output_gpio_interface); std::map<std::string, std::shared_ptr<items::ISolenoid>> create_solenoids(std::istream &solenoid_config, std::shared_ptr<OutputPinController> output_gpio_interface);
std::shared_ptr<items::Solenoid> create_solenoid(nlohmann::json &solenoid_json, std::shared_ptr<IOutputGPIOInterface> output_gpio_interface, std::chrono::milliseconds deactivation_time); std::shared_ptr<items::Solenoid> create_solenoid(nlohmann::json &solenoid_json, std::shared_ptr<OutputPinController> output_gpio_interface, std::chrono::milliseconds deactivation_time);
std::map<std::string, std::shared_ptr<items::ILamp>> create_lamps(std::istream &lamp_config, std::shared_ptr<IOutputGPIOInterface> output_gpio_interface); std::map<std::string, std::shared_ptr<items::ILamp>> create_lamps(std::istream &lamp_config, std::shared_ptr<OutputPinController> output_gpio_interface);
std::shared_ptr<items::Lamp> create_lamp(nlohmann::json &lamp_json, std::shared_ptr<IOutputGPIOInterface> output_gpio_interface); std::shared_ptr<items::Lamp> create_lamp(nlohmann::json &lamp_json, std::shared_ptr<OutputPinController> output_gpio_interface);
std::map<std::string, std::shared_ptr<items::ISound>> create_sounds(std::istream &sound_config, std::shared_ptr<IOutputGPIOInterface> output_gpio_interface); std::map<std::string, std::shared_ptr<items::ISound>> create_sounds(std::istream &sound_config, std::shared_ptr<OutputPinController> output_gpio_interface);
std::shared_ptr<items::Sound> create_sound(nlohmann::json &sound_json, std::shared_ptr<IOutputGPIOInterface> output_gpio_interface, std::chrono::milliseconds deactivation_time); std::shared_ptr<items::Sound> create_sound(nlohmann::json &sound_json, std::shared_ptr<OutputPinController> output_gpio_interface, std::chrono::milliseconds deactivation_time);
std::chrono::milliseconds get_deactivation_time(nlohmann::json &json); std::chrono::milliseconds get_deactivation_time(nlohmann::json &json);
std::map<char, std::shared_ptr<items::IDisplay>> create_displays(std::istream &display_config, std::shared_ptr<IOutputGPIOInterface> output_gpio_interface); std::map<char, std::shared_ptr<items::IDisplay>> create_displays(std::istream &display_config, std::shared_ptr<OutputPinController> output_gpio_interface);
IOutputGPIOInterface* create_OutputGPIOInterface(std::istream &output_pin_config); OutputPinController* create_OutputGPIOInterface(std::istream &output_pin_config);
std::map<std::string, uint8_t> parse_pins_driver_board(nlohmann::json &driver_board_config); std::map<std::string, uint8_t> parse_pins_driver_board(nlohmann::json &driver_board_config);
std::map<std::string, uint8_t> parse_pins_sound(nlohmann::json &sound_board_config); std::map<std::string, uint8_t> parse_pins_sound(nlohmann::json &sound_board_config);
std::map<std::string, uint8_t> parse_pins_display(nlohmann::json &display_board_config); std::map<std::string, uint8_t> parse_pins_display(nlohmann::json &display_board_config);

View File

@@ -5,7 +5,7 @@
#ifndef flippR_driver_IOUTPUTGPIOINTERFACE_H #ifndef flippR_driver_IOUTPUTGPIOINTERFACE_H
#define flippR_driver_IOUTPUTGPIOINTERFACE_H #define flippR_driver_IOUTPUTGPIOINTERFACE_H
#include "IOutputGPIOInterface.h" #include "OutputPinController.h"
#include "output/items/DriverBoardItem.h" #include "output/items/DriverBoardItem.h"
#include "output/items/Sound.h" #include "output/items/Sound.h"
@@ -18,16 +18,11 @@ namespace flippR_driver
namespace output namespace output
{ {
class IOutputGPIOInterface class OutputPinController
{ {
public: public:
virtual ~IOutputGPIOInterface() = default; virtual ~OutputPinController() = default;
virtual void activate(items::DriverBoardItem *driver_board_item) = 0;
virtual void activate(items::Item *sound) = 0;
virtual void deactivate(items::DriverBoardItem *driver_board_item) = 0;
virtual void deactivate(items::Item *sound) = 0;
virtual void write_display(items::IDisplay &display) = 0; virtual void write_display(items::IDisplay &display) = 0;
//Display gpio interface! //Display gpio interface!

View File

@@ -0,0 +1,25 @@
//
// Created by rhetenor on 14.12.18.
//
#ifndef FLIPPR_DRIVER_SOUNDPINCONTROLLER_H
#define FLIPPR_DRIVER_SOUNDPINCONTROLLER_H
#include "OutputPinController.h"
namespace flippR_driver
{
namespace output
{
class SoundBoardPinController : public OutputPinController
{
public:
virtual void activate(const items::Sound &sound) = 0;
virtual void deactivate(const items::Sound &sound) = 0;
};
}
}
#endif //FLIPPR_DRIVER_SOUNDPINCONTROLLER_H

View File

@@ -13,9 +13,11 @@ namespace flippR_driver
{ {
namespace output namespace output
{ {
namespace impl
{
DisplayController::DisplayController(std::vector<std::shared_ptr<items::IDisplay>> displays, std::shared_ptr<IOutputGPIOInterface> output_gpio_interface) DisplayController::DisplayController(std::vector<std::shared_ptr<items::IDisplay>> displays, std::shared_ptr<OutputPinController> output_gpio_interface)
: displays(std::move(displays)), output_gpio_interface(std::move(output_gpio_interface)), is_running(true) : displays(std::move(displays)), output_gpio_interface(std::move(output_gpio_interface)), is_running(true)
{ {
this->display_cycle_thread = std::thread(&DisplayController::cycle_displays, this); this->display_cycle_thread = std::thread(&DisplayController::cycle_displays, this);
@@ -42,3 +44,4 @@ void DisplayController::cycle_displays()
} }
} }
}

View File

@@ -0,0 +1,47 @@
/*
* DisplayController.h
*
* Created on: Aug 7, 2018
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
*/
#ifndef _SRC_OUTPUT_DISPLAYCONTROLLER_H_
#define _SRC_OUTPUT_DISPLAYCONTROLLER_H_
#include "output/DisplayController.h"
#include <vector>
#include <thread>
#include "output/items/IDisplay.h"
#include "output/OutputPinController.h"
namespace flippR_driver
{
namespace output
{
namespace impl
{
class DisplayController : public output::DisplayController
{
public:
explicit DisplayController(std::vector<std::shared_ptr<items::IDisplay>> displays, std::shared_ptr<OutputPinController> output_gpio_interface);
~DisplayController() override;
private:
void cycle_displays();
private:
std::vector<std::shared_ptr<items::IDisplay>> displays;
std::thread display_cycle_thread;
std::shared_ptr<OutputPinController> output_gpio_interface;
bool is_running;
};
}
}
#endif

View File

@@ -0,0 +1,85 @@
//
// Created by rhetenor on 14.12.18.
//
#include "DriverBoardPinController.h"
namespace flippR_driver
{
namespace output
{
namespace impl
{
void DriverBoardPinController::activate(items::DriverBoardItem *driver_board_item)
{
std::lock_guard<std::mutex> guard(output_item_mutex);
write_driver_board_address(driver_board_item->get_address());
write_data(true);
}
void DriverBoardPinController::deactivate(items::DriverBoardItem *driver_board_item)
{
std::lock_guard<std::mutex> guard(output_item_mutex);
write_driver_board_address(driver_board_item->get_address());
write_data(false);
}
void DriverBoardPinController::write_driver_board_address(uint8_t address)
{
int latch = address / 8;
int pin = address % 8;
select_mux(latch);
select_latch(latch);
select_pin(pin);
}
void DriverBoardPinController::select_mux(uint8_t latch)
{
bool mux1 = latch / 8;
write_pin(pins_driver_board.at("mux1"), mux1);
write_pin(pins_driver_board.at("mux2"), !mux1);
}
void DriverBoardPinController::select_latch(uint8_t latch)
{
// todo not nice
if(latch > 8)
latch -= 8;
write_pin(pins_driver_board.at("latch-select-A"), latch & 0b001u);
write_pin(pins_driver_board.at("latch-select-B"), latch & 0b010u);
write_pin(pins_driver_board.at("latch-select-C"), latch & 0b100u);
}
void DriverBoardPinController::write_data(bool data)
{
write_pin(pins_driver_board.at("data"), data);
}
void DriverBoardPinController::select_pin(uint8_t pin)
{
write_pin(pins_driver_board.at("pin-select-A"), pin & 0b001u);
write_pin(pins_driver_board.at("pin-select-B"), pin & 0b010u);
write_pin(pins_driver_board.at("pin-select-C"), pin & 0b100u);
}
void DriverBoardPinController::write_pin(uint8_t pin, bool value)
{
PinController::write_pin(pins_driver_board.at("pin_base") + pin, value);
}
}
}
}

View File

@@ -0,0 +1,49 @@
//
// Created by rhetenor on 14.12.18.
//
#ifndef FLIPPR_DRIVER_OUTPUT_IMPL_DRIVERBOARDPINCONTROLLER_H
#define FLIPPR_DRIVER_OUTPUT_IMPL_DRIVERBOARDPINCONTROLLER_H
#include "PinController.h"
#include "output/DriverBoardPinController.h"
#include <map>
#include <memory>
namespace flippR_driver
{
namespace output
{
namespace impl
{
class DriverBoardPinController : public PinController, public output::DriverBoardPinController
{
public:
DriverBoardPinController(std::map<std::string, uint8_t> pins_driver_board, std::shared_ptr<std::mutex> output_item_mutex);
~DriverBoardPinController() override = default;
virtual void activate(items::DriverBoardItem *driver_board_item) = 0;
virtual void deactivate(items::DriverBoardItem *driver_board_item) = 0;
private:
void write_driver_board_address(uint8_t address);
void select_mux(uint8_t latch);
void select_latch(uint8_t latch);
void select_pin(uint8_t pin);
void write_data(bool data);
void write_pin(uint8_t pin, bool value);
private:
std::shared_ptr<std::mutex> output_item_mutex;
const std::map<std::string, uint8_t> pins_driver_board;
};
}
}
}
#endif //FLIPPR_DRIVER_DRIVERBOARDPINCONTROLLER_H

View File

@@ -14,6 +14,8 @@ namespace flippR_driver
{ {
namespace output namespace output
{ {
namespace impl
{
using namespace items; using namespace items;
@@ -21,7 +23,6 @@ OutputDriver::OutputDriver(std::map<std::string, std::shared_ptr<ISolenoid>> sol
: solenoids(std::move(solenoids)), lamps(std::move(lamps)), sounds(std::move(sounds)), displays(std::move(displays)) : solenoids(std::move(solenoids)), lamps(std::move(lamps)), sounds(std::move(sounds)), displays(std::move(displays))
{} {}
std::vector<std::shared_ptr<ISound>> OutputDriver::get_sounds() std::vector<std::shared_ptr<ISound>> OutputDriver::get_sounds()
{ {
std::vector<std::shared_ptr<ISound>> sounds; std::vector<std::shared_ptr<ISound>> sounds;
@@ -60,7 +61,7 @@ std::vector<std::shared_ptr<ISolenoid>> OutputDriver::get_solenoids()
boost::optional<std::shared_ptr<items::ILamp>> OutputDriver::get_lamp(std::string name) boost::optional<std::shared_ptr<items::ILamp>> OutputDriver::get_lamp(std::string name)
{ {
return this->lamps.find(name)->second; return this->lamps.find(name)->second;
} }
boost::optional<std::shared_ptr<items::ISolenoid>> OutputDriver::get_solenoid(std::string name) boost::optional<std::shared_ptr<items::ISolenoid>> OutputDriver::get_solenoid(std::string name)
@@ -78,6 +79,6 @@ boost::optional<std::shared_ptr<items::IDisplay>> OutputDriver::get_display(char
return this->displays.find(number)->second; return this->displays.find(number)->second;
} }
}
} /* namespace output */ } /* namespace output */
} }

View File

@@ -8,7 +8,7 @@
#ifndef _SRC_OUTPUT_OUTPUTDRIVER_H_ #ifndef _SRC_OUTPUT_OUTPUTDRIVER_H_
#define _SRC_OUTPUT_OUTPUTDRIVER_H_ #define _SRC_OUTPUT_OUTPUTDRIVER_H_
#include "output/IOutputDriver.h" #include "output/OutputDriver.h"
#include <map> #include <map>
@@ -16,11 +16,13 @@ namespace flippR_driver
{ {
namespace output namespace output
{ {
namespace impl
{
class OutputDriver : public IOutputDriver class OutputDriver : public output::OutputDriver
{ {
public: public:
OutputDriver(std::map<std::string, std::shared_ptr<items::ISolenoid>> solenoids, std::map<std::string, std::shared_ptr<items::ILamp>> lamps, std::map<std::string, std::shared_ptr<items::ISound>> sounds, std::map<char, std::shared_ptr<items::IDisplay>> displays); OutputDriver(std::map<std::string, std::shared_ptr<items::ISolenoid>> solenoids, std::map<std::string, std::shared_ptr<items::ILamp>> lamps, std::map<std::string, std::shared_ptr<items::ISound>> sounds, std::map<char, std::shared_ptr<items::IDisplay>> displays);
~OutputDriver() override = default; ~OutputDriver() override = default;
// todo what is flipper_relay ? // todo what is flipper_relay ?
@@ -38,10 +40,11 @@ private:
const std::map<std::string, std::shared_ptr<items::ILamp>> lamps; const std::map<std::string, std::shared_ptr<items::ILamp>> lamps;
const std::map<std::string, std::shared_ptr<items::ISolenoid>> solenoids; const std::map<std::string, std::shared_ptr<items::ISolenoid>> solenoids;
const std::map<std::string, std::shared_ptr<items::ISound>> sounds; const std::map<std::string, std::shared_ptr<items::ISound>> sounds;
const std::map<char, std::shared_ptr<items::IDisplay>> displays; const std::map<char, std::shared_ptr<items::IDisplay>> displays;
}; };
}
} /* namespace output */ } /* namespace output */
} }
#endif #endif

View File

@@ -5,7 +5,7 @@
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert * Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
*/ */
#include "OutputGPIOInterface.h" #include "OutputPinController.h"
#include "utility/config.h" #include "utility/config.h"
@@ -13,6 +13,9 @@ namespace flippR_driver
{ {
namespace output namespace output
{ {
namespace impl
{
using namespace output::items; using namespace output::items;
OutputGPIOInterface::OutputGPIOInterface(std::map<std::string, uint8_t> pins_driver_board, std::map<std::string, uint8_t> pins_sound, std::map<std::string, uint8_t> pins_display) OutputGPIOInterface::OutputGPIOInterface(std::map<std::string, uint8_t> pins_driver_board, std::map<std::string, uint8_t> pins_sound, std::map<std::string, uint8_t> pins_display)
@@ -35,7 +38,7 @@ void OutputGPIOInterface::initialize_all_pins(uint8_t pin_base)
{ {
for(int i = 0; i < 16; i++) for(int i = 0; i < 16; i++)
{ {
GPIOInterface::initialize_output_pin(pin_base + i); PinController::initialize_output_pin(pin_base + i);
} }
} }
@@ -46,101 +49,7 @@ void OutputGPIOInterface::initialize_i2c_addresses()
mcp23017Setup(pins_display.at("pin_base"), pins_display.at("i2c_address")); mcp23017Setup(pins_display.at("pin_base"), pins_display.at("i2c_address"));
} }
void OutputGPIOInterface::activate(items::Item *sound)
{
std::lock_guard<std::mutex> guard(output_item_mutex);
write_sound_address(sound->get_address());
fire_sound(true);
}
void OutputGPIOInterface::activate(items::DriverBoardItem *driver_board_item)
{
std::lock_guard<std::mutex> guard(output_item_mutex);
write_driver_board_address(driver_board_item->get_address());
write_data(true);
}
void OutputGPIOInterface::deactivate(items::DriverBoardItem *driver_board_item)
{
std::lock_guard<std::mutex> guard(output_item_mutex);
write_driver_board_address(driver_board_item->get_address());
write_data(false);
}
void OutputGPIOInterface::deactivate(items::Item *sound)
{
std::lock_guard<std::mutex> guard(output_item_mutex);
write_sound_address(sound->get_address());
fire_sound(false);
}
void OutputGPIOInterface::write_driver_board_address(uint8_t address)
{
int latch = address / 8;
int pin = address % 8;
select_mux(latch);
select_latch(latch);
select_pin(pin);
}
void OutputGPIOInterface::select_mux(uint8_t latch)
{
bool mux1 = latch / 8;
write_pin(pins_driver_board.at("mux1"), mux1);
write_pin(pins_driver_board.at("mux2"), !mux1);
}
void OutputGPIOInterface::select_latch(uint8_t latch)
{
// todo not nice
if(latch > 8)
latch -= 8;
write_pin(pins_driver_board.at("latch-select-A"), latch & 0b001u);
write_pin(pins_driver_board.at("latch-select-B"), latch & 0b010u);
write_pin(pins_driver_board.at("latch-select-C"), latch & 0b100u);
}
void OutputGPIOInterface::write_data(bool data)
{
write_pin(pins_driver_board.at("data"), data);
}
void OutputGPIOInterface::select_pin(uint8_t pin)
{
write_pin(pins_driver_board.at("pin-select-A"), pin & 0b001u);
write_pin(pins_driver_board.at("pin-select-B"), pin & 0b010u);
write_pin(pins_driver_board.at("pin-select-C"), pin & 0b100u);
}
void OutputGPIOInterface::write_sound_address(uint8_t address)
{
write_pin(pins_sound.at("A"), address & 0b0000001u);
write_pin(pins_sound.at("B"), address & 0b0000010u);
write_pin(pins_sound.at("C"), address & 0b0000100u);
write_pin(pins_sound.at("D"), address & 0b0001000u);
write_pin(pins_sound.at("E"), address & 0b0010000u);
write_pin(pins_sound.at("F"), address & 0b0100000u);
write_pin(pins_sound.at("G"), address & 0b1000000u);
}
void OutputGPIOInterface::fire_sound(bool fire)
{
GPIOInterface::write_pin(pins_sound.at("fire"), fire);
}
void OutputGPIOInterface::write_display(IDisplay &display) void OutputGPIOInterface::write_display(IDisplay &display)
{ {
@@ -161,7 +70,7 @@ void OutputGPIOInterface::write_display_digit(const uint8_t display_address, con
run_display(display_address); run_display(display_address);
std::this_thread::sleep_for(std::chrono::milliseconds(DISPLAY_SLEEP_TIME_MILLISECONDS)); std::this_thread::sleep_for(std::chrono::milliseconds(DISPLAY_SLEEP_TIME_MILLI));
} }
void OutputGPIOInterface::select_display_segment(const uint8_t &segment) void OutputGPIOInterface::select_display_segment(const uint8_t &segment)
@@ -196,5 +105,7 @@ void OutputGPIOInterface::deactivate_displays()
write_pin(pins_display.at("run"), 0); write_pin(pins_display.at("run"), 0);
} }
} }
} }

View File

@@ -8,8 +8,8 @@
#ifndef SRC_UTILITIES_OUTPUTGPIOINTERFACE_H_ #ifndef SRC_UTILITIES_OUTPUTGPIOINTERFACE_H_
#define SRC_UTILITIES_OUTPUTGPIOINTERFACE_H_ #define SRC_UTILITIES_OUTPUTGPIOINTERFACE_H_
#include "IOutputGPIOInterface.h" #include "output/OutputPinController.h"
#include "GPIOInterface.h" #include "PinController.h"
#include <mcp23017.h> #include <mcp23017.h>
#include <mutex> #include <mutex>
@@ -18,19 +18,19 @@ namespace flippR_driver
{ {
namespace output namespace output
{ {
namespace impl
{
class OutputGPIOInterface : public GPIOInterface, public IOutputGPIOInterface class OutputGPIOInterface : public PinController, public output::OutputPinController
{ {
public: public:
OutputGPIOInterface(std::map<std::string, uint8_t> pins_driver_board, std::map<std::string, uint8_t> pins_sound, std::map<std::string, uint8_t> pins_display); OutputGPIOInterface(, std::map<std::string, uint8_t> pins_sound, std::map<std::string, uint8_t> pins_display);
~OutputGPIOInterface() override = default; ~OutputGPIOInterface() override = default;
void activate(items::DriverBoardItem *driver_board_item) override;
void activate(items::Item *sound) override; void activate(items::Item *sound) override;
void deactivate(items::DriverBoardItem *driver_board_item) override;
void deactivate(items::Item *sound) override; void deactivate(items::Item *sound) override;
void activate_displays(); void activate_displays();
@@ -48,23 +48,12 @@ private:
void initialize_pins(); void initialize_pins();
void initialize_all_pins(uint8_t pin_base); void initialize_all_pins(uint8_t pin_base);
void write_driver_board_address(uint8_t address);
void select_mux(uint8_t latch);
void select_latch(uint8_t latch);
void select_pin(uint8_t pin);
void write_data(bool data);
void write_sound_address(uint8_t address);
void fire_sound(bool fire);
private: private:
std::mutex output_item_mutex;
const std::map<std::string, uint8_t> pins_driver_board;
const std::map<std::string, uint8_t> pins_sound;
const std::map<std::string, uint8_t> pins_display; const std::map<std::string, uint8_t> pins_display;
}; };
}
} }
} }

View File

@@ -0,0 +1,56 @@
//
// Created by rhetenor on 14.12.18.
//
#include "SoundBoardPinController.h"
namespace flippR_driver
{
namespace output
{
namespace impl
{
void SoundBoardPinController::activate(items::Sound &sound)
{
std::lock_guard<std::mutex> guard(output_item_mutex);
write_sound_address(sound->get_address());
fire_sound(true);
}
void SoundBoardPinController::deactivate(items::Sound &sound)
{
std::lock_guard<std::mutex> guard(output_item_mutex);
write_sound_address(sound->get_address());
fire_sound(false);
}
void SoundBoardPinController::write_sound_address(uint8_t address)
{
write_pin(pins_sound.at("A"), address & 0b0000001u);
write_pin(pins_sound.at("B"), address & 0b0000010u);
write_pin(pins_sound.at("C"), address & 0b0000100u);
write_pin(pins_sound.at("D"), address & 0b0001000u);
write_pin(pins_sound.at("E"), address & 0b0010000u);
write_pin(pins_sound.at("F"), address & 0b0100000u);
write_pin(pins_sound.at("G"), address & 0b1000000u);
}
void SoundBoardPinController::fire_sound(bool fire)
{
PinController::write_pin(pins_sound.at("fire"), fire);
}
void SoundBoardPinController::write_pin(uint8_t pin, bool value)
{
PinController::write_pin(pins_sound.at("pin_base") + pin, value);
}
}
}
}

View File

@@ -0,0 +1,45 @@
//
// Created by rhetenor on 14.12.18.
//
#ifndef FLIPPR_DRIVER_SOUNDBOARDPINCONTROLLER_H
#define FLIPPR_DRIVER_SOUNDBOARDPINCONTROLLER_H
#include <map>
#include "output/SoundBoardPinController.h"
#include "PinController.h"
namespace flippR_driver
{
namespace output
{
namespace impl
{
class SoundBoardPinController : public PinController, public output::SoundBoardPinController
{
public:
SoundBoardPinController();
~SoundBoardPinController() override = default;
void activate(const items::Sound &sound) override;
void deactivate(const items::Sound &sound) override;
private:
void write_sound_address(uint8_t address);
void fire_sound(bool fire);
void write_pin(uint8_t pin, bool value);
private:
std::shared_ptr<std::mutex> output_item_mutex;
const std::map<std::string, uint8_t> pins_sound;
};
}
}
}
#endif //FLIPPR_DRIVER_SOUNDBOARDPINCONTROLLER_H

View File

@@ -19,10 +19,10 @@ namespace items
class DriverBoardItem : public Item class DriverBoardItem : public Item
{ {
public: public:
DriverBoardItem(std::shared_ptr<IOutputGPIOInterface> output_gpio_interface, uint8_t address, std::string name) : DriverBoardItem(std::shared_ptr<OutputPinController> output_gpio_interface, uint8_t address, std::string name) :
Item(std::move(output_gpio_interface), address, std::move(name)) {} Item(std::move(output_gpio_interface), address, std::move(name)) {}
~DriverBoardItem() override = default;
~DriverBoardItem() override = default;
}; };
} }

View File

@@ -12,7 +12,7 @@ namespace output
namespace items namespace items
{ {
Item::Item(std::shared_ptr<IOutputGPIOInterface> output_gpio_interface, uint8_t address, std::string name) : Item::Item(std::shared_ptr<OutputPinController> output_gpio_interface, uint8_t address, std::string name) :
address(address), address(address),
name(std::move(name)), name(std::move(name)),
gpio_interface(std::move(output_gpio_interface)) gpio_interface(std::move(output_gpio_interface))

View File

@@ -18,7 +18,7 @@ namespace flippR_driver
namespace output namespace output
{ {
class IOutputGPIOInterface; class OutputPinController;
namespace items namespace items
{ {
@@ -26,7 +26,7 @@ namespace items
class Item : public IItem class Item : public IItem
{ {
public: public:
Item(std::shared_ptr<IOutputGPIOInterface> output_gpio_interface, uint8_t address, std::string name); Item(std::shared_ptr<OutputPinController> output_gpio_interface, uint8_t address, std::string name);
~Item() override = default; ~Item() override = default;
uint8_t get_address() override; uint8_t get_address() override;
@@ -36,7 +36,7 @@ protected:
const uint8_t address; const uint8_t address;
const std::string name; const std::string name;
const std::shared_ptr<IOutputGPIOInterface> gpio_interface; const std::shared_ptr<OutputPinController> gpio_interface;
}; };

View File

@@ -7,7 +7,7 @@
#include "Lamp.h" #include "Lamp.h"
#include "output/IOutputGPIOInterface.h" #include "output/OutputPinController.h"
namespace flippR_driver namespace flippR_driver
{ {
namespace output namespace output
@@ -15,7 +15,7 @@ namespace output
namespace items namespace items
{ {
Lamp::Lamp(std::shared_ptr<IOutputGPIOInterface> output_gpio_interface, uint8_t address, std::string name) : Lamp::Lamp(std::shared_ptr<OutputPinController> output_gpio_interface, uint8_t address, std::string name) :
DriverBoardItem(std::move(output_gpio_interface), address, std::move(name)), activated(false) DriverBoardItem(std::move(output_gpio_interface), address, std::move(name)), activated(false)
{} {}

View File

@@ -21,7 +21,7 @@ namespace items
class Lamp : public DriverBoardItem, public ILamp class Lamp : public DriverBoardItem, public ILamp
{ {
public: public:
Lamp(std::shared_ptr<IOutputGPIOInterface> output_gpio_interface, uint8_t address, std::string name); Lamp(std::shared_ptr<OutputPinController> output_gpio_interface, uint8_t address, std::string name);
~Lamp() override = default; ~Lamp() override = default;
void activate() override; void activate() override;

View File

@@ -7,7 +7,7 @@
#include "Solenoid.h" #include "Solenoid.h"
#include "output/IOutputGPIOInterface.h" #include "output/OutputPinController.h"
namespace flippR_driver namespace flippR_driver
{ {
@@ -16,7 +16,7 @@ namespace output
namespace items namespace items
{ {
Solenoid::Solenoid(std::shared_ptr<IOutputGPIOInterface> output_gpio_interface, uint8_t address, std::string name, std::chrono::milliseconds deactivation_time): Solenoid::Solenoid(std::shared_ptr<OutputPinController> output_gpio_interface, uint8_t address, std::string name, std::chrono::milliseconds deactivation_time):
DriverBoardItem(std::move(output_gpio_interface), address, std::move(name)), deactivation_time(deactivation_time) DriverBoardItem(std::move(output_gpio_interface), address, std::move(name)), deactivation_time(deactivation_time)
{} {}

View File

@@ -24,7 +24,7 @@ namespace items
class Solenoid : public DriverBoardItem, public ISolenoid class Solenoid : public DriverBoardItem, public ISolenoid
{ {
public: public:
Solenoid(std::shared_ptr<IOutputGPIOInterface> output_gpio_interface, u_int8_t address, std::string name, std::chrono::milliseconds deactivation_time); Solenoid(std::shared_ptr<OutputPinController> output_gpio_interface, u_int8_t address, std::string name, std::chrono::milliseconds deactivation_time);
~Solenoid() override = default; ~Solenoid() override = default;
void trigger() override; void trigger() override;

View File

@@ -7,7 +7,7 @@
#include "Sound.h" #include "Sound.h"
#include "output/IOutputGPIOInterface.h" #include "output/OutputPinController.h"
namespace flippR_driver namespace flippR_driver
{ {
@@ -16,7 +16,7 @@ namespace output
namespace items namespace items
{ {
Sound::Sound(std::shared_ptr<IOutputGPIOInterface> output_gpio_interface, uint8_t address, std::string name, std::chrono::milliseconds deactivation_time, u_int id) : Sound::Sound(std::shared_ptr<OutputPinController> output_gpio_interface, uint8_t address, std::string name, std::chrono::milliseconds deactivation_time, u_int id) :
Item(std::move(output_gpio_interface), address, std::move(name)), deactivation_time(deactivation_time), id(id) Item(std::move(output_gpio_interface), address, std::move(name)), deactivation_time(deactivation_time), id(id)
{} {}

View File

@@ -29,7 +29,7 @@ public:
u_int id; u_int id;
public: public:
Sound(std::shared_ptr<IOutputGPIOInterface> output_gpio_interface, uint8_t address, std::string name, std::chrono::milliseconds deactivation_time, u_int id); Sound(std::shared_ptr<OutputPinController> output_gpio_interface, uint8_t address, std::string name, std::chrono::milliseconds deactivation_time, u_int id);
~Sound() override = default; ~Sound() override = default;
void play() override; void play() override;

View File

@@ -7,14 +7,14 @@
#include "SocketHandler.h" #include "SocketHandler.h"
#include "input/IEventHandler.h" #include "input/EventHandler.h"
#include <string> #include <string>
namespace flippR_driver namespace flippR_driver
{ {
namespace utility namespace utility
{ {
class InputSocketHandler : public SocketHandler, public IEventHandler class InputSocketHandler : public SocketHandler, public EventHandler
{ {
public: public:
explicit InputSocketHandler(boost::asio::io_service &service, std::string socket_file = "/var/run/user/" + std::to_string(getuid()) explicit InputSocketHandler(boost::asio::io_service &service, std::string socket_file = "/var/run/user/" + std::to_string(getuid())

View File

@@ -14,7 +14,8 @@
#define INPUT_MATRIX_SIZE 8 #define INPUT_MATRIX_SIZE 8
#define INPUT_SLEEP_DURATION_NANO 800 #define INPUT_SLEEP_DURATION_NANO 800
#define INPUT_HANDLER_TIMEOUT_MILLI 2000
#define PULLDOWN false #define PULLDOWN false
#define DISPLAY_SLEEP_TIME_MILLISECONDS 1 #define DISPLAY_SLEEP_TIME_MILLI 1

View File

@@ -3373,7 +3373,7 @@ namespace Catch {
virtual void skipTest( TestCaseInfo const& testInfo ) = 0; virtual void skipTest( TestCaseInfo const& testInfo ) = 0;
// Default empty implementation provided // Default empty impl provided
virtual void fatalErrorEncountered( StringRef name ); virtual void fatalErrorEncountered( StringRef name );
virtual bool isMulti() const; virtual bool isMulti() const;