meeeeerging
This commit is contained in:
1
FlippR-Driver/.gitignore
vendored
1
FlippR-Driver/.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
.csettings/*
|
||||
build
|
||||
CMakeFiles
|
||||
CMakeCache.txt
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
cmake_minimum_required(VERSION 3.6.2)
|
||||
project(FlippR_Driver_CLI)
|
||||
project(flippR_driver_CLI)
|
||||
|
||||
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/${OUTPUT_PATH}/cli)
|
||||
add_executable(${PROJECT_NAME} main.cpp PrintHandler.cpp)
|
||||
|
||||
@@ -5,14 +5,14 @@
|
||||
#include "PrintHandler.h"
|
||||
#include <iostream>
|
||||
|
||||
PrintHandler::PrintHandler(std::shared_ptr<FlippR_Driver::Input::IInputDriver> driver) :
|
||||
FlippR_Driver::Input::EventHandler(driver)
|
||||
PrintHandler::PrintHandler(std::shared_ptr<flippR_driver::input::IInputDriver> driver) :
|
||||
flippR_driver::input::EventHandler(driver)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void PrintHandler::handle(FlippR_Driver::Input::Event &event)
|
||||
void PrintHandler::handle(flippR_driver::input::Event &event)
|
||||
{
|
||||
std::cout << "Event " << event.name << " (" << std::to_string(event.address) << ") occured!\n";
|
||||
}
|
||||
@@ -2,20 +2,20 @@
|
||||
// Created by rhetenor on 13.09.18.
|
||||
//
|
||||
|
||||
#ifndef FLIPPR_DRIVER_PRINTHANDLER_H
|
||||
#define FLIPPR_DRIVER_PRINTHANDLER_H
|
||||
#ifndef flippR_driver_PRINTHANDLER_H
|
||||
#define flippR_driver_PRINTHANDLER_H
|
||||
|
||||
#include <memory>
|
||||
#include "EventHandler.h"
|
||||
#include "IInputDriver.h"
|
||||
|
||||
class PrintHandler : public FlippR_Driver::Input::EventHandler
|
||||
class PrintHandler : public flippR_driver::input::EventHandler
|
||||
{
|
||||
public:
|
||||
PrintHandler(std::shared_ptr<FlippR_Driver::Input::IInputDriver> driver);
|
||||
PrintHandler(std::shared_ptr<flippR_driver::input::IInputDriver> driver);
|
||||
|
||||
virtual void handle(FlippR_Driver::Input::Event& event) override;
|
||||
virtual void handle(flippR_driver::input::Event& event) override;
|
||||
};
|
||||
|
||||
|
||||
#endif //FLIPPR_DRIVER_PRINTHANDLER_H
|
||||
#endif //flippR_driver_PRINTHANDLER_H
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
#include "PrintHandler.h"
|
||||
|
||||
using namespace FlippR_Driver;
|
||||
using namespace flippR_driver;
|
||||
|
||||
void siginthandler(int param)
|
||||
{
|
||||
@@ -45,7 +45,7 @@ int main (int argc, char *argv[])
|
||||
exit(2);
|
||||
}
|
||||
|
||||
std::shared_ptr<Input::IInputDriver> driver = FlippR_Driver::get_InputDriver(input_config, matrix_config);
|
||||
std::shared_ptr<input::IInputDriver> driver = flippR_driver::get_InputDriver(input_config, matrix_config);
|
||||
|
||||
PrintHandler* print_handler = new PrintHandler(driver);
|
||||
|
||||
|
||||
1
FlippR-Driver/contrib/ideen.txt
Normal file
1
FlippR-Driver/contrib/ideen.txt
Normal file
@@ -0,0 +1 @@
|
||||
input events entprellen über flanken statt zeit
|
||||
@@ -2,17 +2,17 @@
|
||||
// Created by rhetenor on 13.09.18.
|
||||
//
|
||||
|
||||
#ifndef FLIPPR_DRIVER_DRIVERFACTORY_H
|
||||
#define FLIPPR_DRIVER_DRIVERFACTORY_H
|
||||
#ifndef flippR_driver_DRIVERFACTORY_H
|
||||
#define flippR_driver_DRIVERFACTORY_H
|
||||
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
|
||||
#include "IInputDriver.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::IInputDriver> get_InputDriver(std::istream& input_config_stream, std::istream& matrix_config_stream);
|
||||
}
|
||||
|
||||
#endif //FLIPPR_DRIVER_DRIVERFACTORY_H
|
||||
#endif //flippR_driver_DRIVERFACTORY_H
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
|
||||
namespace FlippR_Driver {
|
||||
namespace Input {
|
||||
namespace flippR_driver {
|
||||
namespace input {
|
||||
|
||||
class Event {
|
||||
public:
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
#include "IEventHandler.h"
|
||||
#include "Event.h"
|
||||
|
||||
namespace FlippR_Driver
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace Input
|
||||
namespace input
|
||||
{
|
||||
class EventHandler;
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ class IEventHandler
|
||||
public:
|
||||
virtual ~IEventHandler(){};
|
||||
|
||||
virtual void handle(FlippR_Driver::Input::Event& event) = 0;
|
||||
virtual void handle(flippR_driver::input::Event& event) = 0;
|
||||
};
|
||||
|
||||
#endif /* SRC_IEVENTHANDLER_H_ */
|
||||
|
||||
@@ -11,9 +11,9 @@
|
||||
#include "IEventHandler.h"
|
||||
#include <memory>
|
||||
|
||||
namespace FlippR_Driver
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace Input
|
||||
namespace input
|
||||
{
|
||||
class IInputDriver {
|
||||
public:
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
#include "DriverFactory.h"
|
||||
#include "input/InputDriverFactory.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::IInputDriver> get_InputDriver(std::istream& input_config_stream, std::istream& matrix_config_stream)
|
||||
{
|
||||
return FlippR_Driver::Input::InputDriverFactory::get_InputDriver(input_config_stream, matrix_config_stream);
|
||||
return flippR_driver::input::InputDriverFactory::get_InputDriver(input_config_stream, matrix_config_stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,14 +10,14 @@
|
||||
#include <iostream>
|
||||
#include <math.h>
|
||||
|
||||
#include "utilities/config.h"
|
||||
#include "utility/config.h"
|
||||
|
||||
namespace FlippR_Driver
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace Input
|
||||
namespace input
|
||||
{
|
||||
|
||||
Detector::Detector(std::unique_ptr<IInputGPIOInterface> input_gpio_interface, std::vector<std::shared_ptr<DistributingEvent>> events) :
|
||||
Detector::Detector(std::unique_ptr<utility::IInputGPIOInterface> input_gpio_interface, std::vector<std::shared_ptr<DistributingEvent>> events) :
|
||||
input_gpio_interface(std::move(input_gpio_interface)), events(events), is_running(true)
|
||||
{
|
||||
this->detect_thread = std::thread(&Detector::detect, this);
|
||||
@@ -49,4 +49,4 @@ void Detector::check_inputs()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,22 +19,22 @@
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include "utilities/IInputGPIOInterface.h"
|
||||
#include "utility/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
|
||||
{
|
||||
|
||||
public:
|
||||
Detector(std::unique_ptr<IInputGPIOInterface> input_gpio_interface, std::vector<std::shared_ptr<DistributingEvent>> events);
|
||||
Detector(std::unique_ptr<utility::IInputGPIOInterface> input_gpio_interface, std::vector<std::shared_ptr<DistributingEvent>> events);
|
||||
~Detector();
|
||||
|
||||
private:
|
||||
@@ -42,7 +42,7 @@ private:
|
||||
void check_inputs();
|
||||
|
||||
private:
|
||||
std::unique_ptr<IInputGPIOInterface> input_gpio_interface;
|
||||
std::unique_ptr<utility::IInputGPIOInterface> input_gpio_interface;
|
||||
|
||||
std::vector<std::shared_ptr<DistributingEvent>> events;
|
||||
|
||||
@@ -52,4 +52,4 @@ private:
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#include "DistributingEvent.h"
|
||||
|
||||
FlippR_Driver::Input::DistributingEvent::DistributingEvent(char address, int priority, std::string name,
|
||||
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, name),
|
||||
bounce_time(bounce_time),
|
||||
@@ -12,12 +12,12 @@ FlippR_Driver::Input::DistributingEvent::DistributingEvent(char address, int pri
|
||||
activation_state(NOT_ACTIVATED)
|
||||
{}
|
||||
|
||||
void FlippR_Driver::Input::DistributingEvent::distribute()
|
||||
void flippR_driver::input::DistributingEvent::distribute()
|
||||
{
|
||||
event_notifier->distribute_event(*this);
|
||||
}
|
||||
|
||||
void FlippR_Driver::Input::DistributingEvent::active()
|
||||
void flippR_driver::input::DistributingEvent::active()
|
||||
{
|
||||
if(!is_bouncing())
|
||||
{
|
||||
@@ -35,7 +35,7 @@ void FlippR_Driver::Input::DistributingEvent::active()
|
||||
}
|
||||
}
|
||||
|
||||
bool FlippR_Driver::Input::DistributingEvent::is_bouncing()
|
||||
bool flippR_driver::input::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 +43,7 @@ bool FlippR_Driver::Input::DistributingEvent::is_bouncing()
|
||||
return elapsed_time < bounce_time;
|
||||
}
|
||||
|
||||
void FlippR_Driver::Input::DistributingEvent::inactive()
|
||||
void flippR_driver::input::DistributingEvent::inactive()
|
||||
{
|
||||
if(activation_state == ACTIVATED)
|
||||
{
|
||||
|
||||
@@ -2,15 +2,15 @@
|
||||
// Created by rhetenor on 21.09.18.
|
||||
//
|
||||
|
||||
#ifndef FLIPPR_DRIVER_DISTRIBUTINGEVENT_H
|
||||
#define FLIPPR_DRIVER_DISTRIBUTINGEVENT_H
|
||||
#ifndef flippR_driver_DISTRIBUTINGEVENT_H
|
||||
#define flippR_driver_DISTRIBUTINGEVENT_H
|
||||
|
||||
#include "Event.h"
|
||||
#include "IEventNotifier.h"
|
||||
|
||||
namespace FlippR_Driver
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace Input
|
||||
namespace input
|
||||
{
|
||||
class DistributingEvent : public Event
|
||||
{
|
||||
@@ -45,4 +45,4 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
#endif //FLIPPR_DRIVER_DISTRIBUTINGEVENT_H
|
||||
#endif //flippR_driver_DISTRIBUTINGEVENT_H
|
||||
|
||||
@@ -10,15 +10,16 @@
|
||||
|
||||
#include "Event.h"
|
||||
|
||||
namespace FlippR_Driver {
|
||||
namespace Input {
|
||||
namespace flippR_driver {
|
||||
namespace input {
|
||||
|
||||
class ErrorEvent : public Event {
|
||||
public:
|
||||
ErrorEvent() :
|
||||
Event(0, 0, "ERROR") {}
|
||||
};
|
||||
}
|
||||
class ErrorEvent : public Event
|
||||
{
|
||||
public:
|
||||
ErrorEvent() : Event(0, 0, "ERROR") {}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -6,18 +6,18 @@
|
||||
*/
|
||||
#include "Event.h"
|
||||
|
||||
#include "utilities/config.h"
|
||||
#include "utility/config.h"
|
||||
|
||||
namespace FlippR_Driver
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace Input
|
||||
namespace input
|
||||
{
|
||||
|
||||
// todo unsigned char address
|
||||
Event::Event(char address, int priority, std::string name) :
|
||||
address(address), priority(priority), name(name)
|
||||
{
|
||||
CLOG_IF(VLOG_IS_ON(HIGHEST_LOG_VERBOSITY), INFO, INPUT_LOGGER) << "Created event: " << name << ", address: " << address;
|
||||
CLOG_IF(VLOG_IS_ON(0), INFO, INPUT_LOGGER) << "Created event: " << name << ", address: " << address;
|
||||
}
|
||||
|
||||
bool operator==(const Event& left, const Event& right)
|
||||
@@ -26,4 +26,4 @@ bool operator==(const Event& left, const Event& right)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,32 +5,32 @@
|
||||
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert, Rafael Vinci, Dr. Franca Rupprecht
|
||||
*/
|
||||
#include "EventHandler.h"
|
||||
#include "utilities/config.h"
|
||||
#include "utility/config.h"
|
||||
|
||||
namespace FlippR_Driver
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace Input
|
||||
namespace input
|
||||
{
|
||||
|
||||
EventHandler::EventHandler(std::shared_ptr<IInputDriver> input_driver) :
|
||||
input_driver(input_driver)
|
||||
{
|
||||
this->input_driver->register_event_handler(this);
|
||||
EventHandler::EventHandler(std::shared_ptr<IInputDriver> input_driver) :
|
||||
input_driver(input_driver)
|
||||
{
|
||||
this->input_driver->register_event_handler(this);
|
||||
|
||||
CLOG(INFO, INPUT_LOGGER) << "Created EventHandler";
|
||||
}
|
||||
CLOG(INFO, INPUT_LOGGER) << "Created EventHandler";
|
||||
}
|
||||
|
||||
EventHandler::~EventHandler()
|
||||
{
|
||||
this->input_driver->unregister_event_handler(this);
|
||||
this->input_driver = NULL;
|
||||
}
|
||||
EventHandler::~EventHandler()
|
||||
{
|
||||
this->input_driver->unregister_event_handler(this);
|
||||
this->input_driver = NULL;
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
CLOG(WARNING, INPUT_LOGGER) << "Called EventHandler parent class";
|
||||
}
|
||||
// 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)
|
||||
{
|
||||
CLOG(WARNING, INPUT_LOGGER) << "Called EventHandler parent class";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,16 +7,16 @@
|
||||
|
||||
#include <boost/thread.hpp>
|
||||
|
||||
#include "utilities/config.h"
|
||||
#include "utility/config.h"
|
||||
|
||||
#include "EventNotifier.h"
|
||||
|
||||
namespace FlippR_Driver
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace Input
|
||||
namespace input
|
||||
{
|
||||
|
||||
EventNotifier::EventNotifier(IBlockingQueue<Event>* queue) :
|
||||
EventNotifier::EventNotifier(utility::IBlockingQueue<Event>* queue) :
|
||||
is_running(true),
|
||||
event_queue(queue)
|
||||
{
|
||||
@@ -82,4 +82,4 @@ void EventNotifier::notify()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,23 +14,23 @@
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
|
||||
#include "utilities/BlockingQueue.hpp"
|
||||
#include "utilities/IBlockingQueue.h"
|
||||
#include "utility/BlockingQueue.hpp"
|
||||
#include "utility/IBlockingQueue.h"
|
||||
#include "Event.h"
|
||||
#include "EventHandler.h"
|
||||
|
||||
#define HANDLER_TIMEOUT 2000
|
||||
|
||||
namespace FlippR_Driver
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace Input
|
||||
namespace input
|
||||
{
|
||||
|
||||
class EventNotifier : public IEventNotifier
|
||||
{
|
||||
|
||||
public:
|
||||
EventNotifier(IBlockingQueue<Event>* queue);
|
||||
EventNotifier(utility::IBlockingQueue<Event>* queue);
|
||||
~EventNotifier();
|
||||
|
||||
void register_event_handler(IEventHandler* handler);
|
||||
@@ -42,7 +42,7 @@ private:
|
||||
void notify();
|
||||
|
||||
private:
|
||||
IBlockingQueue<Event>* event_queue;
|
||||
utility::IBlockingQueue<Event>* event_queue;
|
||||
std::set<IEventHandler*> event_handlers;
|
||||
|
||||
bool is_running;
|
||||
@@ -54,4 +54,4 @@ private:
|
||||
|
||||
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
#define SRC_INPUT_IDETECTOR_H_
|
||||
|
||||
|
||||
namespace FlippR_Driver
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace Input
|
||||
namespace input
|
||||
{
|
||||
|
||||
class IDetector
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
#include "IEventHandler.h"
|
||||
#include <memory>
|
||||
|
||||
namespace FlippR_Driver
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace Input
|
||||
namespace input
|
||||
{
|
||||
|
||||
class IEventNotifier
|
||||
|
||||
@@ -6,13 +6,13 @@
|
||||
*/
|
||||
#include "InputDriver.h"
|
||||
|
||||
#include "utilities/config.h"
|
||||
#include "utility/config.h"
|
||||
|
||||
#include <input/ErrorEvent.hpp>
|
||||
|
||||
namespace FlippR_Driver
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace Input
|
||||
namespace input
|
||||
{
|
||||
|
||||
InputDriver::InputDriver(std::shared_ptr<IEventNotifier> event_notifier, std::unique_ptr<IDetector> detector,
|
||||
@@ -42,9 +42,8 @@ std::shared_ptr<Event> InputDriver::get_event(std::string name)
|
||||
catch(std::out_of_range &e)
|
||||
{
|
||||
CLOG_N_TIMES(1, WARNING, OUTPUT_LOGGER) << "Did not found event " << name << " please check config file!";
|
||||
|
||||
return event;
|
||||
}
|
||||
return event;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,9 +13,9 @@
|
||||
#include "IInputDriver.h"
|
||||
#include "IDetector.h"
|
||||
|
||||
namespace FlippR_Driver
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace Input
|
||||
namespace input
|
||||
{
|
||||
|
||||
class InputDriver : public IInputDriver
|
||||
|
||||
@@ -8,21 +8,21 @@
|
||||
|
||||
#include "InputDriverFactory.h"
|
||||
|
||||
#include "utilities/config.h"
|
||||
#include "utility/config.h"
|
||||
|
||||
#include "utilities/LoggerFactory.h"
|
||||
#include "utility/LoggerFactory.h"
|
||||
|
||||
#include "InputDriver.h"
|
||||
#include "EventNotifier.h"
|
||||
|
||||
using namespace nlohmann;
|
||||
using namespace flippR_driver::utility;
|
||||
|
||||
|
||||
namespace FlippR_Driver
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace Input
|
||||
namespace input
|
||||
{
|
||||
std::shared_ptr<IInputDriver> InputDriverFactory::get_InputDriver(std::istream &input_config_stream, std::istream &matrix_config_stream)
|
||||
std::shared_ptr<IInputDriver> InputDriverFactory::get_InputDriver(std::istream &input_config_stream, std::istream &matrix_config_stream)
|
||||
{
|
||||
LoggerFactory::CreateInputLogger();
|
||||
|
||||
@@ -52,9 +52,9 @@ void InputDriverFactory::create_input_events(json matrix_config, std::vector<std
|
||||
{
|
||||
int global_bounce_time = matrix_config.at("global_bounce_time").get<json::number_integer_t>();
|
||||
auto& event_array = matrix_config.at("input_matrix");
|
||||
for (auto &json_event : event_array)
|
||||
for (auto &json_event : event_array)
|
||||
{
|
||||
try
|
||||
try
|
||||
{
|
||||
std::string name = json_event.at("name");
|
||||
char address = json_event.at("address").get<json::number_integer_t>();
|
||||
@@ -73,7 +73,7 @@ void InputDriverFactory::create_input_events(json matrix_config, std::vector<std
|
||||
events.push_back(event_ptr);
|
||||
name_event_map.emplace(name, event_ptr);
|
||||
}
|
||||
catch (json::exception &e)
|
||||
catch (json::exception &e)
|
||||
{
|
||||
CLOG(ERROR, INPUT_LOGGER) << "Matrix config-file corrupted: " << e.what();
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
@@ -14,13 +14,13 @@
|
||||
#include "Detector.h"
|
||||
#include "IInputDriver.h"
|
||||
|
||||
#include "utilities/InputGPIOInterface.h"
|
||||
#include "utility/InputGPIOInterface.h"
|
||||
#include "json/json.hpp"
|
||||
#include "IEventNotifier.h"
|
||||
|
||||
namespace FlippR_Driver
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace Input
|
||||
namespace input
|
||||
{
|
||||
class InputDriverFactory
|
||||
{
|
||||
@@ -36,4 +36,4 @@ private:
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
//
|
||||
// Created by rhetenor on 19.10.18.
|
||||
//
|
||||
|
||||
#ifndef FLIPPR_DRIVER_CABINETITEM_H
|
||||
#define FLIPPR_DRIVER_CABINETITEM_H
|
||||
|
||||
class CabinetItem : IOutputItem
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
#endif //FLIPPR_DRIVER_CABINETITEM_H
|
||||
@@ -1,12 +0,0 @@
|
||||
//
|
||||
// Created by rhetenor on 10.10.18.
|
||||
//
|
||||
|
||||
namespace FlippR_Driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -12,15 +12,15 @@
|
||||
|
||||
#include <array>
|
||||
|
||||
namespace FlippR_Driver
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
template <int DigitCount>
|
||||
class Display : public IDisplay
|
||||
class Display : public IDisplay<DigitCount>
|
||||
{
|
||||
public:
|
||||
Display();
|
||||
Display(int address, int id);
|
||||
virtual ~Display() = default;
|
||||
|
||||
virtual int getID();
|
||||
@@ -34,8 +34,17 @@ public:
|
||||
private:
|
||||
int address;
|
||||
int id;
|
||||
|
||||
std::string fit_string(std::string& score_string);
|
||||
};
|
||||
|
||||
using SevenDigitDisplay = Display<7>;
|
||||
using EightDigitDisply = Display<8>;
|
||||
|
||||
} /* namespace output */
|
||||
}
|
||||
#endif
|
||||
|
||||
#include "Display.hpp"
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
63
FlippR-Driver/src/output/Display.hpp
Normal file
63
FlippR-Driver/src/output/Display.hpp
Normal file
@@ -0,0 +1,63 @@
|
||||
//
|
||||
// Created by rhetenor on 10.10.18.
|
||||
//
|
||||
|
||||
#include "utility/config.h"
|
||||
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
|
||||
template<int DigitCount>
|
||||
Display<DigitCount>::Display(int address, int id) :
|
||||
address(address),
|
||||
id(id)
|
||||
{
|
||||
}
|
||||
|
||||
template<int DigitCount>
|
||||
int Display<DigitCount>::getID()
|
||||
{
|
||||
return this->id;
|
||||
}
|
||||
|
||||
template<int DigitCount>
|
||||
void Display<DigitCount>::write_score(int score)
|
||||
{
|
||||
auto score_string = std::to_string(score);
|
||||
|
||||
auto score_c_string = this->fit_string(score_string).c_str();
|
||||
|
||||
std::copy(std::begin(score_c_string), std::end(score_c_string), std::begin(this->content));
|
||||
}
|
||||
|
||||
template<int DigitCount>
|
||||
std::string Display<DigitCount>::fit_string(std::string& score_string)
|
||||
{
|
||||
auto score_length = score_string.length();
|
||||
|
||||
if (score_length > DigitCount)
|
||||
{
|
||||
CLOG(DEBUG, OUTPUT_LOGGER) << "Score too long for display";
|
||||
std::string full_display;
|
||||
// TODO mach mal schöner hier wird 9999 angezeigt wenn die zahl zu groß is
|
||||
return full_display.insert(0, DigitCount, '9');
|
||||
}
|
||||
|
||||
score_string.insert(0, DigitCount-score_length, '\0');
|
||||
return score_string;
|
||||
}
|
||||
|
||||
template<int DigitCount>
|
||||
void Display<DigitCount>::write_content( std::array<char, DigitCount> content)
|
||||
{
|
||||
this->content = content;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -6,15 +6,16 @@
|
||||
*/
|
||||
|
||||
#include "DisplayController.h"
|
||||
#include "utility/IOutputGPIOInterface.h"
|
||||
|
||||
#include "utility/config.h"
|
||||
|
||||
namespace FlippR_Driver
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
|
||||
DisplayController::DisplayController(std::vector<std::shared_ptr<IDisplay>> displays, std::shared_ptr<IOutputGPIOInterface> output_gpio_interface)
|
||||
DisplayController::DisplayController(std::vector<std::shared_ptr<IDisplay>> displays, std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface)
|
||||
: displays(displays), output_gpio_interface(output_gpio_interface), is_running(true)
|
||||
{
|
||||
this->display_cycle_thread = std::thread(&DisplayController::cycle_displays, this);
|
||||
@@ -33,9 +34,9 @@ void DisplayController::cycle_displays()
|
||||
{
|
||||
while(is_running)
|
||||
{
|
||||
for(auto& display : displays)
|
||||
for(auto& display : this->displays)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,9 +14,9 @@
|
||||
#include <thread>
|
||||
|
||||
#include "IDisplay.h"
|
||||
#include "utilities/IOutputGPIOInterface.h"
|
||||
#include "utility/IOutputGPIOInterface.h"
|
||||
|
||||
namespace FlippR_Driver
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
@@ -24,7 +24,7 @@ namespace output
|
||||
class DisplayController : public IDisplayController
|
||||
{
|
||||
public:
|
||||
DisplayController(std::vector<std::shared_ptr<IDisplay>> displays, std::shared_ptr<IOutputGPIOInterface> output_gpio_interface);
|
||||
explicit DisplayController(std::vector<std::shared_ptr<IDisplay>> displays, std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface);
|
||||
~DisplayController();
|
||||
|
||||
private:
|
||||
@@ -35,11 +35,11 @@ private:
|
||||
|
||||
std::thread display_cycle_thread;
|
||||
|
||||
std::shared_ptr<IOutputGPIOInterface> output_gpio_interface;
|
||||
std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface;
|
||||
|
||||
bool is_running;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -8,22 +8,28 @@
|
||||
#ifndef _SRC_OUTPUT_IDISPLAY_H_
|
||||
#define _SRC_OUTPUT_IDISPLAY_H_
|
||||
|
||||
namespace FlippR_Driver
|
||||
#include <array>
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
|
||||
class IDisplay
|
||||
{
|
||||
|
||||
public:
|
||||
IDisplay();
|
||||
virtual ~IDisplay();
|
||||
|
||||
virtual void write_score(int score) = 0;
|
||||
virtual void write_content(std::array<char, DigitCount> content) = 0;
|
||||
|
||||
virtual int getID() = 0;
|
||||
|
||||
virtual void write() = 0;
|
||||
private:
|
||||
std::string fit_string(std::string& score_string);
|
||||
};
|
||||
|
||||
} /* namespace output */
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -7,18 +7,19 @@
|
||||
|
||||
#ifndef _SRC_OUTPUT_IDISPLAYCONTROLLER_H_
|
||||
#define _SRC_OUTPUT_IDISPLAYCONTROLLER_H_
|
||||
namespace FlippR_Driver
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
|
||||
class IDisplayController
|
||||
{
|
||||
|
||||
public:
|
||||
IDisplayController();
|
||||
virtual ~IDisplayController();
|
||||
IDisplayController ();
|
||||
virtual ~IDisplayController ();
|
||||
};
|
||||
|
||||
} /* namespace output */
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -8,14 +8,12 @@
|
||||
#ifndef _SRC_OUTPUT_ILAMP_H_
|
||||
#define _SRC_OUTPUT_ILAMP_H_
|
||||
|
||||
#include "IOutputItem.h"
|
||||
|
||||
namespace FlippR_Driver
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
|
||||
class ILamp : public IOutputItem
|
||||
class ILamp
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#ifndef _SRC_OUTPUT_IOUTPUTDRIVER_H_
|
||||
#define _SRC_OUTPUT_IOUTPUTDRIVER_H_
|
||||
|
||||
namespace FlippR_Driver
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* IOutputItem.h
|
||||
* ICabinetItem.h
|
||||
*
|
||||
* Created on: Aug 7, 2018
|
||||
* Author: rhetenor
|
||||
@@ -9,17 +9,17 @@
|
||||
#define _SRC_OUTPUT_ICABINETITEM_H_
|
||||
|
||||
|
||||
namespace FlippR_Driver
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
|
||||
class IOutputItem
|
||||
class ICabinetItem
|
||||
{
|
||||
virtual ~IOutputItem();
|
||||
virtual bool isActivated() = 0;
|
||||
virtual bool activate() = 0;
|
||||
virtual bool deactivate() = 0;
|
||||
virtual ~ICabinetItem();
|
||||
virtual bool isActivated() = 0;
|
||||
virtual bool activate() = 0;
|
||||
virtual bool deactivate() = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -8,14 +8,12 @@
|
||||
#ifndef _SRC_OUTPUT_ISOLENOID_H_
|
||||
#define _SRC_OUTPUT_ISOLENOID_H_
|
||||
|
||||
#include "IOutputItem.h"
|
||||
|
||||
namespace FlippR_Driver
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
|
||||
class ISolenoid : public IOutputItem
|
||||
class ISolenoid
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
@@ -8,13 +8,12 @@
|
||||
#ifndef _SRC_OUTPUT_ISOUND_H_
|
||||
#define _SRC_OUTPUT_ISOUND_H_
|
||||
|
||||
#include "IOutputItem.h"
|
||||
namespace FlippR_Driver
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
|
||||
class ISound : public IOutputItem
|
||||
class ISound
|
||||
{
|
||||
public:
|
||||
ISound();
|
||||
|
||||
@@ -7,12 +7,13 @@
|
||||
|
||||
#include "Lamp.h"
|
||||
|
||||
namespace FlippR_Driver
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
|
||||
Lamp::Lamp()
|
||||
Lamp::Lamp(std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface, int address, std::string name) :
|
||||
OutputItem(output_gpio_interface, address, name)
|
||||
{
|
||||
// TODO Auto-generated constructor stub
|
||||
|
||||
@@ -23,5 +24,15 @@ Lamp::~Lamp()
|
||||
// TODO Auto-generated destructor stub
|
||||
}
|
||||
|
||||
void Lamp::activate()
|
||||
{
|
||||
// activate
|
||||
}
|
||||
|
||||
void Lamp::deactivate()
|
||||
{
|
||||
// deactivate
|
||||
}
|
||||
|
||||
} /* namespace output */
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
#include "OutputItem.h"
|
||||
|
||||
namespace FlippR_Driver
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
@@ -18,10 +18,17 @@ namespace output
|
||||
class Lamp : public OutputItem
|
||||
{
|
||||
public:
|
||||
Lamp();
|
||||
virtual ~Lamp();
|
||||
Lamp(std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface, int address, std::string name);
|
||||
virtual ~Lamp();
|
||||
|
||||
void activate();
|
||||
void deactivate();
|
||||
bool is_activated();
|
||||
|
||||
private:
|
||||
bool activated;
|
||||
};
|
||||
|
||||
} /* namespace output */
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include <boost/range/adaptor/map.hpp>
|
||||
#include <boost/range/algorithm/copy.hpp>
|
||||
|
||||
namespace FlippR_Driver
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#include "IDisplay.h"
|
||||
#include "ISound.h"
|
||||
|
||||
namespace FlippR_Driver
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
@@ -25,10 +25,15 @@ namespace output
|
||||
class OutputDriver : public IOutputDriver
|
||||
{
|
||||
public:
|
||||
<<<<<<< HEAD
|
||||
OutputDriver(std::map<std::string, std::shared_ptr<IOutputItem>> cabinet_items, std::map<char, std::shared_ptr<IDisplay>> displays, std::map<std::string, std::shared_ptr<ISound>> sounds);
|
||||
=======
|
||||
OutputDriver(std::map<std::string, std::shared_ptr<ICabinetItem>> cabinet_items, std::map<char, std::shared_ptr<IDisplay>> displays, std::map<std::string, std::shared_ptr<ISound>> sounds);
|
||||
>>>>>>> be582e9f7f0d29518665a131afce24ca0a43386e
|
||||
|
||||
virtual ~OutputDriver() = default;
|
||||
virtual ~OutputDriver() = default;
|
||||
|
||||
<<<<<<< HEAD
|
||||
std::vector<std::shared_ptr<IOutputItem>> get_cabinet_items();
|
||||
std::vector<std::shared_ptr<ISound>> get_sounds();
|
||||
std::vector<std::shared_ptr<IDisplay>> get_displays();
|
||||
@@ -41,8 +46,22 @@ private:
|
||||
std::map<std::string, std::shared_ptr<IOutputItem>> cabinet_items;
|
||||
std::map<char, std::shared_ptr<IDisplay>> displays;
|
||||
std::map<std::string, std::shared_ptr<ISound>> sounds;
|
||||
=======
|
||||
std::vector<std::shared_ptr<ICabinetItem>> get_cabinet_items();
|
||||
std::vector<std::shared_ptr<ISound>> get_sounds();
|
||||
std::vector<std::shared_ptr<IDisplay>> get_displays();
|
||||
|
||||
std::shared_ptr<ICabinetItem> get_cabinet_item(std::string name);
|
||||
std::shared_ptr<ISound> get_sound(std::string name);
|
||||
std::shared_ptr<IDisplay> get_display(char number);
|
||||
|
||||
private:
|
||||
std::map<std::string, std::shared_ptr<ICabinetItem>> cabinet_items;
|
||||
std::map<char, std::shared_ptr<IDisplay>> displays;
|
||||
std::map<std::string, std::shared_ptr<ISound>> sounds;
|
||||
>>>>>>> be582e9f7f0d29518665a131afce24ca0a43386e
|
||||
};
|
||||
|
||||
} /* namespace output */
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#include "OutputDriverFactory.h"
|
||||
|
||||
namespace FlippR_Driver
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
// Created by rhetenor on 04.10.18.
|
||||
//
|
||||
|
||||
#ifndef FLIPPR_DRIVER_OUTPUTDRIVERFACTORY_H
|
||||
#define FLIPPR_DRIVER_OUTPUTDRIVERFACTORY_H
|
||||
#ifndef flippR_driver_OUTPUTDRIVERFACTORY_H
|
||||
#define flippR_driver_OUTPUTDRIVERFACTORY_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "OutputDriver.h"
|
||||
|
||||
namespace FlippR_Driver
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
@@ -21,4 +21,4 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
#endif //FLIPPR_DRIVER_OUTPUTDRIVERFACTORY_H
|
||||
#endif //flippR_driver_OUTPUTDRIVERFACTORY_H
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* OutputItem.h
|
||||
* CabinetItem.h
|
||||
*
|
||||
* Created on: Aug 2, 2018
|
||||
* Author: rhetenor
|
||||
@@ -8,38 +8,34 @@
|
||||
#ifndef _SRC_OUTPUT_CABINETITEM_H_
|
||||
#define _SRC_OUTPUT_CABINETITEM_H_
|
||||
|
||||
#include "IOutputItem.h"
|
||||
#include "ICabinetItem.h"
|
||||
|
||||
#include "ActivationStrategy.h"
|
||||
#include "utility/IOutputGPIOInterface.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace FlippR_Driver
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
|
||||
using namespace utility;
|
||||
|
||||
class OutputItem : public IOutputItem
|
||||
class OutputItem : public ICabinetItem
|
||||
{
|
||||
public:
|
||||
OutputItem(std::shared_ptr<IOutputGPIOInterface> output_gpio_interface, int address, std::string name);
|
||||
OutputItem(std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface, int address, std::string name);
|
||||
virtual ~OutputItem();
|
||||
|
||||
bool isActivated();
|
||||
|
||||
public:
|
||||
int address;
|
||||
int priority;
|
||||
protected:
|
||||
int address, i2c_address, data_pin_address;
|
||||
std::string name;
|
||||
|
||||
protected:
|
||||
bool activated;
|
||||
std::shared_ptr<IOutputGPIOInterface> output_gpio_interface;
|
||||
strategy::ActivationStrategy* strategy;
|
||||
|
||||
std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface;
|
||||
};
|
||||
|
||||
} /* namespace output */
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -7,18 +7,28 @@
|
||||
|
||||
#include "Solenoid.h"
|
||||
|
||||
namespace FlippR_Driver
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output {
|
||||
|
||||
Solenoid::Solenoid() {
|
||||
Solenoid::Solenoid(std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface, int address, std::string name) :
|
||||
OutputItem(output_gpio_interface, address, name)
|
||||
{
|
||||
// TODO Auto-generated constructor stub
|
||||
|
||||
}
|
||||
|
||||
Solenoid::~Solenoid() {
|
||||
Solenoid::~Solenoid()
|
||||
{
|
||||
// TODO Auto-generated destructor stub
|
||||
}
|
||||
|
||||
void Solenoid::trigger()
|
||||
{
|
||||
// activate
|
||||
// wait
|
||||
// deactivate
|
||||
}
|
||||
|
||||
} /* namespace output */
|
||||
}
|
||||
|
||||
@@ -8,20 +8,23 @@
|
||||
#ifndef _SRC_OUTPUT_SOLENOID_H_
|
||||
#define _SRC_OUTPUT_SOLENOID_H_
|
||||
|
||||
#include "ISolenoid.h.h"
|
||||
#include "OutputItem.h"
|
||||
|
||||
namespace FlippR_Driver
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
|
||||
class Solenoid : public ISolenoid
|
||||
class Solenoid : public OutputItem
|
||||
{
|
||||
public:
|
||||
Solenoid();
|
||||
virtual ~Solenoid();
|
||||
Solenoid(std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface, int address, std::string name);
|
||||
virtual ~Solenoid();
|
||||
|
||||
//muss task sein
|
||||
void trigger();
|
||||
};
|
||||
|
||||
} /* namespace output */
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -7,19 +7,21 @@
|
||||
|
||||
#include "Sound.h"
|
||||
|
||||
namespace FlippR_Driver
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
|
||||
Sound::Sound(std::shared_ptr<IOutputGPIOInterface> output_gpio_interface, int address, std::string name)
|
||||
: output_gpio_interface(output_gpio_interface), address(address), name(name)
|
||||
Sound::Sound(std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface, int address, std::string name) :
|
||||
output_gpio_interface(output_gpio_interface), address(address), name(name)
|
||||
{}
|
||||
|
||||
void Sound::play()
|
||||
{
|
||||
this->output_gpio_interface->activate(this);
|
||||
// this->output_gpio_interface->activate(this);
|
||||
// wait
|
||||
// deactivate()
|
||||
}
|
||||
|
||||
} /* namespace output */
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,9 +13,9 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "utilities/IOutputGPIOInterface.h"
|
||||
#include "utility/IOutputGPIOInterface.h"
|
||||
|
||||
namespace FlippR_Driver
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
@@ -23,13 +23,13 @@ namespace output
|
||||
class Sound : ISound
|
||||
{
|
||||
public:
|
||||
Sound(std::shared_ptr<IOutputGPIOInterface> output_gpio_interface, int address, std::string name);
|
||||
Sound(std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface, int address, std::string name);
|
||||
virtual ~Sound() = default;
|
||||
|
||||
virtual void play();
|
||||
|
||||
private:
|
||||
std::shared_ptr<IOutputGPIOInterface> output_gpio_interface;
|
||||
std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface;
|
||||
|
||||
int address;
|
||||
std::string name;
|
||||
@@ -37,4 +37,4 @@ private:
|
||||
|
||||
} /* namespace output */
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
using namespace boost;
|
||||
|
||||
namespace FlippR_Driver
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace utility
|
||||
{
|
||||
|
||||
20
FlippR-Driver/src/utility/DisplayGPIOInterface.cpp
Normal file
20
FlippR-Driver/src/utility/DisplayGPIOInterface.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* DisplayGPIOInterface.cpp
|
||||
*
|
||||
* Created on: Nov 9, 2018
|
||||
* Author: johannes
|
||||
*/
|
||||
|
||||
#include "DisplayGPIOInterface.h"
|
||||
|
||||
DisplayGPIOInterface::DisplayGPIOInterface()
|
||||
{
|
||||
// TODO Auto-generated constructor stub
|
||||
|
||||
}
|
||||
|
||||
DisplayGPIOInterface::~DisplayGPIOInterface()
|
||||
{
|
||||
// TODO Auto-generated destructor stub
|
||||
}
|
||||
|
||||
19
FlippR-Driver/src/utility/DisplayGPIOInterface.h
Normal file
19
FlippR-Driver/src/utility/DisplayGPIOInterface.h
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* DisplayGPIOInterface.h
|
||||
*
|
||||
* Created on: Nov 9, 2018
|
||||
* Author: johannes
|
||||
*/
|
||||
|
||||
#ifndef SRC_UTILITY_DISPLAYGPIOINTERFACE_H_
|
||||
#define SRC_UTILITY_DISPLAYGPIOINTERFACE_H_
|
||||
|
||||
class DisplayGPIOInterface
|
||||
{
|
||||
public:
|
||||
DisplayGPIOInterface();
|
||||
virtual
|
||||
~DisplayGPIOInterface();
|
||||
};
|
||||
|
||||
#endif /* SRC_UTILITY_DISPLAYGPIOINTERFACE_H_ */
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "wiringPi/wiringPi.h"
|
||||
#include "json/json.hpp"
|
||||
|
||||
namespace FlippR_Driver
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace utility
|
||||
{
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
#include <mutex>
|
||||
#include <fstream>
|
||||
namespace FlippR_Driver
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace utility
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#ifndef SRC_UTILITIES_IBLOCKINGQUEUE_H_
|
||||
#define SRC_UTILITIES_IBLOCKINGQUEUE_H_
|
||||
|
||||
namespace FlippR_Driver
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace utility
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#ifndef SRC_UTILITIES_IINPUTGPIOINTERFACE_H_
|
||||
#define SRC_UTILITIES_IINPUTGPIOINTERFACE_H_
|
||||
|
||||
namespace FlippR_Driver
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace utility
|
||||
{
|
||||
|
||||
@@ -2,19 +2,30 @@
|
||||
// Created by rhetenor on 10.10.18.
|
||||
//
|
||||
|
||||
#ifndef FLIPPR_DRIVER_IOUTPUTGPIOINTERFACE_H
|
||||
#define FLIPPR_DRIVER_IOUTPUTGPIOINTERFACE_H
|
||||
#ifndef flippR_driver_IOUTPUTGPIOINTERFACE_H
|
||||
#define flippR_driver_IOUTPUTGPIOINTERFACE_H
|
||||
|
||||
namespace FlippR_Driver
|
||||
#include "OutputItem.h"
|
||||
#include "IOutputGPIOInterface.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace utility
|
||||
{
|
||||
|
||||
class IOutputGPIOInterface
|
||||
{
|
||||
public:
|
||||
//muss alles geschützt sein
|
||||
void set_address(int i2c_address, int address);
|
||||
void activate_pin(int i2c_address, int pin);
|
||||
void deactivate_pin(int i2c_address, int pin);
|
||||
|
||||
//Display gpio interface!
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
#endif //FLIPPR_DRIVER_IOUTPUTGPIOINTERFACE_H
|
||||
#endif //flippR_driver_IOUTPUTGPIOINTERFACE_H
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include "easylogging/easylogging++.h"
|
||||
#include "config.h"
|
||||
#include <string>
|
||||
namespace FlippR_Driver
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace utility
|
||||
{
|
||||
@@ -46,7 +46,7 @@ void InputGPIOInterface::write_col(char data)
|
||||
write_pin(this->col_address_C, data & 0b100);
|
||||
}
|
||||
|
||||
InputGPIOInterface::InputGPIOInterface(std::istream &input_config_stream)
|
||||
InputGPIOInterface::inputGPIOInterface(std::istream &input_config_stream)
|
||||
{
|
||||
init_members(input_config_stream);
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "IInputGPIOInterface.h"
|
||||
#include "GPIOInterface.h"
|
||||
|
||||
namespace FlippR_Driver
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace utility
|
||||
{
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
INITIALIZE_EASYLOGGINGPP
|
||||
#endif
|
||||
|
||||
namespace FlippR_Driver
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace utility
|
||||
{
|
||||
|
||||
@@ -10,20 +10,20 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
namespace FlippR_Driver
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace utility
|
||||
{
|
||||
|
||||
namespace LoggerFactory
|
||||
{
|
||||
void CreateInputTestLogger(el::Level level = el::Level::Global);
|
||||
void CreateInputTestLogger(el::Level level = el::Level::Global);
|
||||
|
||||
void CreateInputLogger(el::Level level = el::Level::Info);
|
||||
void CreateInputLogger(el::Level level = el::Level::Info);
|
||||
|
||||
void CreateOutputLogger(el::Level level = el::Level::Info);
|
||||
void CreateOutputLogger(el::Level level = el::Level::Info);
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
#include <mcp23017.h>
|
||||
|
||||
namespace FlippR_Driver
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace utility
|
||||
{
|
||||
|
||||
@@ -12,13 +12,9 @@
|
||||
|
||||
#define LOGGER_FILE "driver.log"
|
||||
|
||||
#define DRIVER_CONF_FILE "/var/log/flippr_driver.conf"
|
||||
|
||||
#define HIGHEST_LOG_VERBOSITY 10
|
||||
|
||||
#define INPUT_MATRIX_SIZE 8
|
||||
#define INPUT_SLEEP_DURATION_NANO 800
|
||||
|
||||
#define PULLDOWN false
|
||||
|
||||
#define HIGHEST_INPUT_EVENT_PRIORITY 0
|
||||
#define VALID_DISPLAY_CHARACTERS [1,2,3,4,5,6,7,8,9,0,\0]
|
||||
|
||||
@@ -18,13 +18,14 @@
|
||||
#include "input/IEventNotifier.h"
|
||||
#include "input/DistributingEvent.h"
|
||||
#include "input/Detector.h"
|
||||
#include "utilities/LoggerFactory.h"
|
||||
#include "utilities/InputGPIOInterface.h"
|
||||
#include "utility/LoggerFactory.h"
|
||||
#include "utility/InputGPIOInterface.h"
|
||||
|
||||
|
||||
using namespace fakeit;
|
||||
using namespace FlippR_Driver;
|
||||
using namespace Input;
|
||||
using namespace flippR_driver;
|
||||
using namespace input;
|
||||
using namespace utility;
|
||||
|
||||
|
||||
SCENARIO("Creating a Detector object", "")
|
||||
@@ -42,11 +43,11 @@ SCENARIO("Creating a Detector object", "")
|
||||
Fake(Dtor(event_notifier_mock));
|
||||
When(Method(event_notifier_mock, distribute_event)).AlwaysReturn();
|
||||
|
||||
std::map<char, std::shared_ptr<DistributingEvent>> events;
|
||||
std::vector<std::shared_ptr<DistributingEvent>> events;
|
||||
|
||||
WHEN("Detector is created")
|
||||
{
|
||||
Detector detector(std::unique_ptr<IInputGPIOInterface>(&gpio_interface_mock.get()), events, std::shared_ptr<IEventNotifier>(&event_notifier_mock.get()));
|
||||
Detector detector(std::unique_ptr<IInputGPIOInterface>(&gpio_interface_mock.get()), events);
|
||||
THEN("a thread should be created")
|
||||
{
|
||||
REQUIRE(typeid(detector.detect_thread).hash_code() == typeid(std::thread).hash_code());
|
||||
@@ -75,16 +76,16 @@ SCENARIO("There are events at the input", "")
|
||||
DistributingEvent event2(2, '2', "event 2", std::chrono::milliseconds(0), event_notifier);
|
||||
DistributingEvent event3(3, '3', "event 3", std::chrono::milliseconds(0), event_notifier);
|
||||
|
||||
std::map<char, std::shared_ptr<DistributingEvent>> events;
|
||||
std::vector<std::shared_ptr<DistributingEvent>> events;
|
||||
|
||||
auto event2ptr = std::make_shared<DistributingEvent>(event2);
|
||||
events.insert(std::make_pair(1, std::make_shared<DistributingEvent>(event1)));
|
||||
events.insert(std::make_pair(2, event2ptr));
|
||||
events.insert(std::make_pair(3, std::make_shared<DistributingEvent>(event3)));
|
||||
events.push_back(std::make_shared<DistributingEvent>(event1));
|
||||
events.push_back(event2ptr);
|
||||
events.push_back(std::make_shared<DistributingEvent>(event3));
|
||||
|
||||
WHEN("an event can be found at gpio interface")
|
||||
{
|
||||
Detector detector(std::unique_ptr<IInputGPIOInterface>(&gpio_interface_mock.get()), events, std::shared_ptr<IEventNotifier>(&event_notifier_mock.get()));
|
||||
Detector detector(std::unique_ptr<IInputGPIOInterface>(&gpio_interface_mock.get()), events);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||
THEN("the event should be distributed")
|
||||
{
|
||||
@@ -116,15 +117,15 @@ SCENARIO("There are events at the input but no suitable event in map", "")
|
||||
DistributingEvent event2(2, '2', "event 2", std::chrono::milliseconds(0), event_notifier);
|
||||
DistributingEvent event3(3, '3', "event 3", std::chrono::milliseconds(0), event_notifier);
|
||||
|
||||
std::map<char, std::shared_ptr<DistributingEvent>> events;
|
||||
std::vector<std::shared_ptr<DistributingEvent>> events;
|
||||
|
||||
events.insert(std::make_pair(1, std::make_shared<DistributingEvent>(event1)));
|
||||
events.insert(std::make_pair(2, std::make_shared<DistributingEvent>(event2)));
|
||||
events.insert(std::make_pair(3, std::make_shared<DistributingEvent>(event3)));
|
||||
events.push_back(std::make_shared<DistributingEvent>(event1));
|
||||
events.push_back(std::make_shared<DistributingEvent>(event2));
|
||||
events.push_back(std::make_shared<DistributingEvent>(event3));
|
||||
|
||||
WHEN("an event can be found at gpio interface")
|
||||
{
|
||||
Detector detector(std::unique_ptr<IInputGPIOInterface>(&gpio_interface_mock.get()), events, std::shared_ptr<IEventNotifier>(&event_notifier_mock.get()));
|
||||
Detector detector(std::unique_ptr<IInputGPIOInterface>(&gpio_interface_mock.get()), events);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
THEN("the event should be distributed")
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include "catch.hpp"
|
||||
#include "fakeit.hpp"
|
||||
|
||||
#include "utilities/LoggerFactory.h"
|
||||
#include "utility/LoggerFactory.h"
|
||||
#include "EventHandler.h"
|
||||
#include "IInputDriver.h"
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
|
||||
using namespace fakeit;
|
||||
using namespace flippR_driver::utility;
|
||||
|
||||
SCENARIO("An EventHandler gets created", "[construction}")
|
||||
{
|
||||
@@ -25,15 +26,15 @@ SCENARIO("An EventHandler gets created", "[construction}")
|
||||
{
|
||||
LoggerFactory::CreateInputTestLogger();
|
||||
|
||||
Mock<FlippR_Driver::Input::IInputDriver> input_driver_mock;
|
||||
Mock<flippR_driver::input::IInputDriver> input_driver_mock;
|
||||
Fake(Dtor(input_driver_mock));
|
||||
When(Method(input_driver_mock, register_event_handler)).AlwaysReturn();
|
||||
When(Method(input_driver_mock, unregister_event_handler)).AlwaysReturn();
|
||||
|
||||
WHEN("the event handler gets created")
|
||||
{
|
||||
std::shared_ptr<FlippR_Driver::Input::IInputDriver> driver_ptr(&input_driver_mock.get());
|
||||
FlippR_Driver::Input::EventHandler handler(driver_ptr);
|
||||
std::shared_ptr<flippR_driver::input::IInputDriver> driver_ptr(&input_driver_mock.get());
|
||||
flippR_driver::input::EventHandler handler(driver_ptr);
|
||||
|
||||
THEN("It should register itself at the input_driver")
|
||||
{
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
#include "fakeit.hpp"
|
||||
|
||||
|
||||
#include "utilities/LoggerFactory.h"
|
||||
#include "utility/LoggerFactory.h"
|
||||
#include "IEventHandler.h"
|
||||
#include "utilities/IBlockingQueue.h"
|
||||
#include "utility/IBlockingQueue.h"
|
||||
|
||||
|
||||
// testing purposes
|
||||
@@ -20,9 +20,10 @@
|
||||
|
||||
#include "input/EventNotifier.h"
|
||||
|
||||
using namespace FlippR_Driver;
|
||||
using namespace Input;
|
||||
using namespace flippR_driver;
|
||||
using namespace input;
|
||||
using namespace fakeit;
|
||||
using namespace utility;
|
||||
|
||||
SCENARIO("An EventNotifier gets created", "[construction]")
|
||||
{
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "fakeit.hpp"
|
||||
#include "utilities/LoggerFactory.h"
|
||||
#include "utility/LoggerFactory.h"
|
||||
|
||||
// testing purposes
|
||||
#define private public
|
||||
@@ -19,8 +19,9 @@
|
||||
|
||||
|
||||
using namespace fakeit;
|
||||
using namespace FlippR_Driver;
|
||||
using namespace Input;
|
||||
using namespace flippR_driver;
|
||||
using namespace input;
|
||||
using namespace utility;
|
||||
|
||||
SCENARIO("An InputDriver gets created", "[construction}")
|
||||
{
|
||||
@@ -57,14 +58,14 @@ SCENARIO("An EventHandler [un]registers at the driver", "[un-register]")
|
||||
{
|
||||
LoggerFactory::CreateInputTestLogger();
|
||||
|
||||
Mock<FlippR_Driver::Input::IDetector> detector_mock;
|
||||
Mock<flippR_driver::input::IDetector> detector_mock;
|
||||
Fake(Dtor(detector_mock));
|
||||
|
||||
Mock<IEventHandler> event_handler_mock;
|
||||
Fake(Method(event_handler_mock, handle));
|
||||
Fake(Dtor(event_handler_mock));
|
||||
|
||||
Mock<FlippR_Driver::Input::IEventNotifier> event_notifier_mock;
|
||||
Mock<flippR_driver::input::IEventNotifier> event_notifier_mock;
|
||||
Fake(Method(event_notifier_mock, register_event_handler));
|
||||
Fake(Method(event_notifier_mock, unregister_event_handler));
|
||||
Fake(Dtor(event_notifier_mock));
|
||||
@@ -104,13 +105,13 @@ SCENARIO("An Input Driver is created normally", "")
|
||||
{
|
||||
LoggerFactory::CreateInputTestLogger();
|
||||
|
||||
Mock<FlippR_Driver::Input::IDetector> detector_mock;
|
||||
Mock<flippR_driver::input::IDetector> detector_mock;
|
||||
Fake(Dtor(detector_mock));
|
||||
|
||||
Mock<IEventHandler> event_handler_mock;
|
||||
Fake(Dtor(event_handler_mock));
|
||||
|
||||
Mock<FlippR_Driver::Input::IEventNotifier> event_notifier_mock;
|
||||
Mock<flippR_driver::input::IEventNotifier> event_notifier_mock;
|
||||
Fake(Dtor(event_notifier_mock));
|
||||
|
||||
std::shared_ptr<IEventNotifier> event_notifier_ptr(&event_notifier_mock.get());
|
||||
|
||||
@@ -11,19 +11,57 @@
|
||||
#include "catch.hpp"
|
||||
#include "fakeit.hpp"
|
||||
|
||||
#include "utilities/LoggerFactory.h"
|
||||
#include "utility/LoggerFactory.h"
|
||||
|
||||
|
||||
// testing purposes
|
||||
#define private public
|
||||
|
||||
#include "output/Display.h"
|
||||
#include "Display.h"
|
||||
|
||||
using namespace output;
|
||||
using namespace flippR_driver::output;
|
||||
using namespace fakeit;
|
||||
|
||||
SCENARIO("")
|
||||
SCENARIO("Creating a Display object", "")
|
||||
{
|
||||
GIVEN("Just a Display with 7 digits")
|
||||
{
|
||||
SevenDigitDisplay display(5,5);
|
||||
WHEN("A content is set for the display")
|
||||
{
|
||||
std::string content_string = "1234567";
|
||||
std::array<char,7> content;
|
||||
std::copy(content_string.begin(), content_string.end(), content.data());
|
||||
display.write_content(content);
|
||||
THEN("This content should be set for the display")
|
||||
{
|
||||
REQUIRE(content == display.content);
|
||||
}
|
||||
}
|
||||
WHEN("A score (12345) within the size of the display is written")
|
||||
{
|
||||
display.write_score(12345);
|
||||
THEN("The content should look like: \" 12345\" ")
|
||||
{
|
||||
std::string content_string = "\0\012345";
|
||||
std::array<char,7> content;
|
||||
std::copy(content_string.begin(), content_string.end(), content.data());
|
||||
|
||||
REQUIRE(display.content == content);
|
||||
}
|
||||
}
|
||||
WHEN("A score (12345678), which is longer than the digit is written")
|
||||
{
|
||||
display.write_score(12345678);
|
||||
THEN("The content should look like: \"9999999\"-> highest number ")
|
||||
{
|
||||
std::string content_string = "9999999";
|
||||
std::array<char,7> content;
|
||||
std::copy(content_string.begin(), content_string.end(), content.data());
|
||||
|
||||
REQUIRE(display.content == content);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include "catch.hpp"
|
||||
#include "fakeit.hpp"
|
||||
|
||||
#include "utilities/LoggerFactory.h"
|
||||
#include "utility/LoggerFactory.h"
|
||||
|
||||
|
||||
// testing purposes
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
#include "output/DisplayController.h"
|
||||
|
||||
using namespace output;
|
||||
using namespace flippR_driver::output;
|
||||
using namespace fakeit;
|
||||
|
||||
SCENARIO("")
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include "catch.hpp"
|
||||
#include "fakeit.hpp"
|
||||
|
||||
#include "utilities/LoggerFactory.h"
|
||||
#include "utility/LoggerFactory.h"
|
||||
|
||||
|
||||
// testing purposes
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
#include "output/Lamp.h"
|
||||
|
||||
using namespace output;
|
||||
using namespace flippR_driver::output;
|
||||
using namespace fakeit;
|
||||
|
||||
SCENARIO("")
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include "catch.hpp"
|
||||
#include "fakeit.hpp"
|
||||
|
||||
#include "utilities/LoggerFactory.h"
|
||||
#include "utility/LoggerFactory.h"
|
||||
|
||||
|
||||
// testing purposes
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
#include "output/OutputDriver.h"
|
||||
|
||||
using namespace output;
|
||||
using namespace flippR_driver::output;
|
||||
using namespace fakeit;
|
||||
|
||||
SCENARIO("")
|
||||
|
||||
@@ -11,15 +11,15 @@
|
||||
#include "catch.hpp"
|
||||
#include "fakeit.hpp"
|
||||
|
||||
#include "utilities/LoggerFactory.h"
|
||||
#include "utility/LoggerFactory.h"
|
||||
|
||||
|
||||
// testing purposes
|
||||
#define private public
|
||||
|
||||
#include "output/OutputItem.h"
|
||||
#include "../../src/output/OutputItem.h"
|
||||
|
||||
using namespace output;
|
||||
using namespace flippR_driver::output;
|
||||
using namespace fakeit;
|
||||
|
||||
SCENARIO("")
|
||||
@@ -10,7 +10,7 @@
|
||||
#include "catch.hpp"
|
||||
#include "fakeit.hpp"
|
||||
|
||||
#include "utilities/LoggerFactory.h"
|
||||
#include "utility/LoggerFactory.h"
|
||||
|
||||
|
||||
// testing purposes
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
#include "output/Solenoid.h"
|
||||
|
||||
using namespace output;
|
||||
using namespace flippR_driver::output;
|
||||
using namespace fakeit;
|
||||
|
||||
SCENARIO("")
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include "catch.hpp"
|
||||
#include "fakeit.hpp"
|
||||
|
||||
#include "utilities/LoggerFactory.h"
|
||||
#include "utility/LoggerFactory.h"
|
||||
|
||||
|
||||
// testing purposes
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
#include "output/Sound.h"
|
||||
|
||||
using namespace output;
|
||||
using namespace flippR_driver::output;
|
||||
using namespace fakeit;
|
||||
|
||||
SCENARIO("")
|
||||
|
||||
Reference in New Issue
Block a user