refactored everything
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
cmake_minimum_required(VERSION 3.6.2)
|
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)
|
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/${OUTPUT_PATH}/cli)
|
||||||
add_executable(${PROJECT_NAME} main.cpp PrintHandler.cpp)
|
add_executable(${PROJECT_NAME} main.cpp PrintHandler.cpp)
|
||||||
|
|||||||
@@ -5,14 +5,14 @@
|
|||||||
#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::IInputDriver> driver) :
|
||||||
FlippR_Driver::Input::EventHandler(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";
|
std::cout << "Event " << event.name << " (" << std::to_string(event.address) << ") occured!\n";
|
||||||
}
|
}
|
||||||
@@ -2,20 +2,20 @@
|
|||||||
// Created by rhetenor on 13.09.18.
|
// Created by rhetenor on 13.09.18.
|
||||||
//
|
//
|
||||||
|
|
||||||
#ifndef FLIPPR_DRIVER_PRINTHANDLER_H
|
#ifndef flippR_driver_PRINTHANDLER_H
|
||||||
#define FLIPPR_DRIVER_PRINTHANDLER_H
|
#define flippR_driver_PRINTHANDLER_H
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "EventHandler.h"
|
#include "EventHandler.h"
|
||||||
#include "IInputDriver.h"
|
#include "IInputDriver.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::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"
|
#include "PrintHandler.h"
|
||||||
|
|
||||||
using namespace FlippR_Driver;
|
using namespace flippR_driver;
|
||||||
|
|
||||||
void siginthandler(int param)
|
void siginthandler(int param)
|
||||||
{
|
{
|
||||||
@@ -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::IInputDriver> driver = flippR_driver::get_InputDriver(input_config, matrix_config);
|
||||||
|
|
||||||
PrintHandler* print_handler = new PrintHandler(driver);
|
PrintHandler* print_handler = new PrintHandler(driver);
|
||||||
|
|
||||||
|
|||||||
@@ -2,17 +2,17 @@
|
|||||||
// Created by rhetenor on 13.09.18.
|
// Created by rhetenor on 13.09.18.
|
||||||
//
|
//
|
||||||
|
|
||||||
#ifndef FLIPPR_DRIVER_DRIVERFACTORY_H
|
#ifndef flippR_driver_DRIVERFACTORY_H
|
||||||
#define FLIPPR_DRIVER_DRIVERFACTORY_H
|
#define flippR_driver_DRIVERFACTORY_H
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "IInputDriver.h"
|
#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 <string>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
|
||||||
namespace FlippR_Driver {
|
namespace flippR_driver {
|
||||||
namespace Input {
|
namespace input {
|
||||||
|
|
||||||
class Event {
|
class Event {
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -17,9 +17,9 @@
|
|||||||
#include "IEventHandler.h"
|
#include "IEventHandler.h"
|
||||||
#include "Event.h"
|
#include "Event.h"
|
||||||
|
|
||||||
namespace FlippR_Driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace Input
|
namespace input
|
||||||
{
|
{
|
||||||
class EventHandler;
|
class EventHandler;
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class IEventHandler
|
|||||||
public:
|
public:
|
||||||
virtual ~IEventHandler(){};
|
virtual ~IEventHandler(){};
|
||||||
|
|
||||||
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_ */
|
||||||
|
|||||||
@@ -11,9 +11,9 @@
|
|||||||
#include "IEventHandler.h"
|
#include "IEventHandler.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace FlippR_Driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace Input
|
namespace input
|
||||||
{
|
{
|
||||||
class IInputDriver {
|
class IInputDriver {
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -5,10 +5,10 @@
|
|||||||
#include "DriverFactory.h"
|
#include "DriverFactory.h"
|
||||||
#include "input/InputDriverFactory.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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,9 +12,9 @@
|
|||||||
|
|
||||||
#include "utility/config.h"
|
#include "utility/config.h"
|
||||||
|
|
||||||
namespace FlippR_Driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace Input
|
namespace input
|
||||||
{
|
{
|
||||||
|
|
||||||
Detector::Detector(std::unique_ptr<utility::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) :
|
||||||
|
|||||||
@@ -25,9 +25,9 @@
|
|||||||
#include "DistributingEvent.h"
|
#include "DistributingEvent.h"
|
||||||
#include "IEventNotifier.h"
|
#include "IEventNotifier.h"
|
||||||
|
|
||||||
namespace FlippR_Driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace Input
|
namespace input
|
||||||
{
|
{
|
||||||
|
|
||||||
class Detector : public IDetector
|
class Detector : public IDetector
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#include "DistributingEvent.h"
|
#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):
|
std::chrono::milliseconds bounce_time, std::shared_ptr<IEventNotifier> event_notifier):
|
||||||
Event(address, priority, name),
|
Event(address, priority, name),
|
||||||
bounce_time(bounce_time),
|
bounce_time(bounce_time),
|
||||||
@@ -12,12 +12,12 @@ FlippR_Driver::Input::DistributingEvent::DistributingEvent(char address, int pri
|
|||||||
activation_state(NOT_ACTIVATED)
|
activation_state(NOT_ACTIVATED)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void FlippR_Driver::Input::DistributingEvent::distribute()
|
void flippR_driver::input::DistributingEvent::distribute()
|
||||||
{
|
{
|
||||||
event_notifier->distribute_event(*this);
|
event_notifier->distribute_event(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FlippR_Driver::Input::DistributingEvent::active()
|
void flippR_driver::input::DistributingEvent::active()
|
||||||
{
|
{
|
||||||
if(!is_bouncing())
|
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::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 +43,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 flippR_driver::input::DistributingEvent::inactive()
|
||||||
{
|
{
|
||||||
if(activation_state == ACTIVATED)
|
if(activation_state == ACTIVATED)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,15 +2,15 @@
|
|||||||
// Created by rhetenor on 21.09.18.
|
// Created by rhetenor on 21.09.18.
|
||||||
//
|
//
|
||||||
|
|
||||||
#ifndef FLIPPR_DRIVER_DISTRIBUTINGEVENT_H
|
#ifndef flippR_driver_DISTRIBUTINGEVENT_H
|
||||||
#define FLIPPR_DRIVER_DISTRIBUTINGEVENT_H
|
#define flippR_driver_DISTRIBUTINGEVENT_H
|
||||||
|
|
||||||
#include "Event.h"
|
#include "Event.h"
|
||||||
#include "IEventNotifier.h"
|
#include "IEventNotifier.h"
|
||||||
|
|
||||||
namespace FlippR_Driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace Input
|
namespace input
|
||||||
{
|
{
|
||||||
class DistributingEvent : public Event
|
class DistributingEvent : public Event
|
||||||
{
|
{
|
||||||
@@ -45,4 +45,4 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //FLIPPR_DRIVER_DISTRIBUTINGEVENT_H
|
#endif //flippR_driver_DISTRIBUTINGEVENT_H
|
||||||
|
|||||||
@@ -10,8 +10,8 @@
|
|||||||
|
|
||||||
#include "Event.h"
|
#include "Event.h"
|
||||||
|
|
||||||
namespace FlippR_Driver {
|
namespace flippR_driver {
|
||||||
namespace Input {
|
namespace input {
|
||||||
|
|
||||||
class ErrorEvent : public Event
|
class ErrorEvent : public Event
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,16 +8,16 @@
|
|||||||
|
|
||||||
#include "utility/config.h"
|
#include "utility/config.h"
|
||||||
|
|
||||||
namespace FlippR_Driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace Input
|
namespace input
|
||||||
{
|
{
|
||||||
|
|
||||||
// todo unsigned char address
|
// todo unsigned char address
|
||||||
Event::Event(char 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(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)
|
bool operator==(const Event& left, const Event& right)
|
||||||
|
|||||||
@@ -7,9 +7,9 @@
|
|||||||
#include "EventHandler.h"
|
#include "EventHandler.h"
|
||||||
#include "utility/config.h"
|
#include "utility/config.h"
|
||||||
|
|
||||||
namespace FlippR_Driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace Input
|
namespace input
|
||||||
{
|
{
|
||||||
|
|
||||||
EventHandler::EventHandler(std::shared_ptr<IInputDriver> input_driver) :
|
EventHandler::EventHandler(std::shared_ptr<IInputDriver> input_driver) :
|
||||||
|
|||||||
@@ -11,9 +11,9 @@
|
|||||||
|
|
||||||
#include "EventNotifier.h"
|
#include "EventNotifier.h"
|
||||||
|
|
||||||
namespace FlippR_Driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace Input
|
namespace input
|
||||||
{
|
{
|
||||||
|
|
||||||
EventNotifier::EventNotifier(utility::IBlockingQueue<Event>* queue) :
|
EventNotifier::EventNotifier(utility::IBlockingQueue<Event>* queue) :
|
||||||
|
|||||||
@@ -21,9 +21,9 @@
|
|||||||
|
|
||||||
#define HANDLER_TIMEOUT 2000
|
#define HANDLER_TIMEOUT 2000
|
||||||
|
|
||||||
namespace FlippR_Driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace Input
|
namespace input
|
||||||
{
|
{
|
||||||
|
|
||||||
class EventNotifier : public IEventNotifier
|
class EventNotifier : public IEventNotifier
|
||||||
|
|||||||
@@ -9,9 +9,9 @@
|
|||||||
#define SRC_INPUT_IDETECTOR_H_
|
#define SRC_INPUT_IDETECTOR_H_
|
||||||
|
|
||||||
|
|
||||||
namespace FlippR_Driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace Input
|
namespace input
|
||||||
{
|
{
|
||||||
|
|
||||||
class IDetector
|
class IDetector
|
||||||
|
|||||||
@@ -12,9 +12,9 @@
|
|||||||
#include "IEventHandler.h"
|
#include "IEventHandler.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace FlippR_Driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace Input
|
namespace input
|
||||||
{
|
{
|
||||||
|
|
||||||
class IEventNotifier
|
class IEventNotifier
|
||||||
|
|||||||
@@ -10,9 +10,9 @@
|
|||||||
|
|
||||||
#include <input/ErrorEvent.hpp>
|
#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,
|
InputDriver::InputDriver(std::shared_ptr<IEventNotifier> event_notifier, std::unique_ptr<IDetector> detector,
|
||||||
|
|||||||
@@ -13,9 +13,9 @@
|
|||||||
#include "IInputDriver.h"
|
#include "IInputDriver.h"
|
||||||
#include "IDetector.h"
|
#include "IDetector.h"
|
||||||
|
|
||||||
namespace FlippR_Driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace Input
|
namespace input
|
||||||
{
|
{
|
||||||
|
|
||||||
class InputDriver : public IInputDriver
|
class InputDriver : public IInputDriver
|
||||||
|
|||||||
@@ -16,13 +16,13 @@
|
|||||||
#include "EventNotifier.h"
|
#include "EventNotifier.h"
|
||||||
|
|
||||||
using namespace nlohmann;
|
using namespace nlohmann;
|
||||||
using namespace FlippR_Driver::utility;
|
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();
|
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>();
|
int global_bounce_time = matrix_config.at("global_bounce_time").get<json::number_integer_t>();
|
||||||
auto& event_array = matrix_config.at("input_matrix");
|
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");
|
std::string name = json_event.at("name");
|
||||||
char address = json_event.at("address").get<json::number_integer_t>();
|
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);
|
events.push_back(event_ptr);
|
||||||
name_event_map.emplace(name, 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();
|
CLOG(ERROR, INPUT_LOGGER) << "Matrix config-file corrupted: " << e.what();
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
|||||||
@@ -18,9 +18,9 @@
|
|||||||
#include "json/json.hpp"
|
#include "json/json.hpp"
|
||||||
#include "IEventNotifier.h"
|
#include "IEventNotifier.h"
|
||||||
|
|
||||||
namespace FlippR_Driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace Input
|
namespace input
|
||||||
{
|
{
|
||||||
class InputDriverFactory
|
class InputDriverFactory
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -12,12 +12,12 @@
|
|||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
namespace FlippR_Driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace output
|
namespace output
|
||||||
{
|
{
|
||||||
template <int DigitCount>
|
template <int DigitCount>
|
||||||
class Display : public IDisplay
|
class Display : public IDisplay<DigitCount>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Display(int address, int id);
|
Display(int address, int id);
|
||||||
@@ -38,7 +38,13 @@ private:
|
|||||||
std::string fit_string(std::string& score_string);
|
std::string fit_string(std::string& score_string);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
using SevenDigitDisplay = Display<7>;
|
||||||
|
using EightDigitDisply = Display<8>;
|
||||||
|
|
||||||
} /* namespace output */
|
} /* namespace output */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include "Display.hpp"
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -2,14 +2,13 @@
|
|||||||
// Created by rhetenor on 10.10.18.
|
// Created by rhetenor on 10.10.18.
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "Display.h"
|
|
||||||
#include "utility/config.h"
|
#include "utility/config.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
|
||||||
namespace FlippR_Driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace output
|
namespace output
|
||||||
{
|
{
|
||||||
@@ -45,10 +44,12 @@ std::string Display<DigitCount>::fit_string(std::string& score_string)
|
|||||||
if (score_length > DigitCount)
|
if (score_length > DigitCount)
|
||||||
{
|
{
|
||||||
CLOG(DEBUG, OUTPUT_LOGGER) << "Score too long for display";
|
CLOG(DEBUG, OUTPUT_LOGGER) << "Score too long for display";
|
||||||
return score_string.substr(score_length-DigitCount, score_length);
|
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, ' ');
|
score_string.insert(0, DigitCount-score_length, '\0');
|
||||||
return score_string;
|
return score_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
#include "utility/config.h"
|
#include "utility/config.h"
|
||||||
|
|
||||||
namespace FlippR_Driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace output
|
namespace output
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
#include "IDisplay.h"
|
#include "IDisplay.h"
|
||||||
#include "utility/IOutputGPIOInterface.h"
|
#include "utility/IOutputGPIOInterface.h"
|
||||||
|
|
||||||
namespace FlippR_Driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace output
|
namespace output
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
#define _SRC_OUTPUT_ICABINETITEM_H_
|
#define _SRC_OUTPUT_ICABINETITEM_H_
|
||||||
|
|
||||||
|
|
||||||
namespace FlippR_Driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace output
|
namespace output
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,18 +8,26 @@
|
|||||||
#ifndef _SRC_OUTPUT_IDISPLAY_H_
|
#ifndef _SRC_OUTPUT_IDISPLAY_H_
|
||||||
#define _SRC_OUTPUT_IDISPLAY_H_
|
#define _SRC_OUTPUT_IDISPLAY_H_
|
||||||
|
|
||||||
namespace FlippR_Driver
|
#include <array>
|
||||||
|
|
||||||
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace output
|
namespace output
|
||||||
{
|
{
|
||||||
|
|
||||||
class IDisplay
|
class IDisplay
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
IDisplay();
|
IDisplay();
|
||||||
virtual ~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 int getID() = 0;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string fit_string(std::string& score_string);
|
||||||
};
|
};
|
||||||
|
|
||||||
} /* namespace output */
|
} /* namespace output */
|
||||||
|
|||||||
@@ -7,18 +7,19 @@
|
|||||||
|
|
||||||
#ifndef _SRC_OUTPUT_IDISPLAYCONTROLLER_H_
|
#ifndef _SRC_OUTPUT_IDISPLAYCONTROLLER_H_
|
||||||
#define _SRC_OUTPUT_IDISPLAYCONTROLLER_H_
|
#define _SRC_OUTPUT_IDISPLAYCONTROLLER_H_
|
||||||
namespace FlippR_Driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace output
|
namespace output
|
||||||
{
|
{
|
||||||
|
|
||||||
class IDisplayController
|
class IDisplayController
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
IDisplayController();
|
IDisplayController ();
|
||||||
virtual ~IDisplayController();
|
virtual ~IDisplayController ();
|
||||||
};
|
};
|
||||||
|
|
||||||
} /* namespace output */
|
} /* namespace output */
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
#ifndef _SRC_OUTPUT_ILAMP_H_
|
#ifndef _SRC_OUTPUT_ILAMP_H_
|
||||||
#define _SRC_OUTPUT_ILAMP_H_
|
#define _SRC_OUTPUT_ILAMP_H_
|
||||||
|
|
||||||
namespace FlippR_Driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace output
|
namespace output
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
#ifndef _SRC_OUTPUT_IOUTPUTDRIVER_H_
|
#ifndef _SRC_OUTPUT_IOUTPUTDRIVER_H_
|
||||||
#define _SRC_OUTPUT_IOUTPUTDRIVER_H_
|
#define _SRC_OUTPUT_IOUTPUTDRIVER_H_
|
||||||
|
|
||||||
namespace FlippR_Driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace output
|
namespace output
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
#ifndef _SRC_OUTPUT_ISOLENOID_H_
|
#ifndef _SRC_OUTPUT_ISOLENOID_H_
|
||||||
#define _SRC_OUTPUT_ISOLENOID_H_
|
#define _SRC_OUTPUT_ISOLENOID_H_
|
||||||
|
|
||||||
namespace FlippR_Driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace output
|
namespace output
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
#ifndef _SRC_OUTPUT_ISOUND_H_
|
#ifndef _SRC_OUTPUT_ISOUND_H_
|
||||||
#define _SRC_OUTPUT_ISOUND_H_
|
#define _SRC_OUTPUT_ISOUND_H_
|
||||||
|
|
||||||
namespace FlippR_Driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace output
|
namespace output
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,13 +7,13 @@
|
|||||||
|
|
||||||
#include "Lamp.h"
|
#include "Lamp.h"
|
||||||
|
|
||||||
namespace FlippR_Driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace output
|
namespace output
|
||||||
{
|
{
|
||||||
|
|
||||||
Lamp::Lamp(std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface, int address, std::string name) :
|
Lamp::Lamp(std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface, int address, std::string name) :
|
||||||
CabinetItem(output_gpio_interface, address, name)
|
OutputItem(output_gpio_interface, address, name)
|
||||||
{
|
{
|
||||||
// TODO Auto-generated constructor stub
|
// TODO Auto-generated constructor stub
|
||||||
|
|
||||||
|
|||||||
@@ -8,14 +8,14 @@
|
|||||||
#ifndef _SRC_OUTPUT_LAMP_H_
|
#ifndef _SRC_OUTPUT_LAMP_H_
|
||||||
#define _SRC_OUTPUT_LAMP_H_
|
#define _SRC_OUTPUT_LAMP_H_
|
||||||
|
|
||||||
#include "CabinetItem.h"
|
#include "OutputItem.h"
|
||||||
|
|
||||||
namespace FlippR_Driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace output
|
namespace output
|
||||||
{
|
{
|
||||||
|
|
||||||
class Lamp : public CabinetItem
|
class Lamp : public OutputItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Lamp(std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface, int address, std::string name);
|
Lamp(std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface, int address, std::string name);
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
#include <boost/range/adaptor/map.hpp>
|
#include <boost/range/adaptor/map.hpp>
|
||||||
#include <boost/range/algorithm/copy.hpp>
|
#include <boost/range/algorithm/copy.hpp>
|
||||||
|
|
||||||
namespace FlippR_Driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace output
|
namespace output
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
#include "IDisplay.h"
|
#include "IDisplay.h"
|
||||||
#include "ISound.h"
|
#include "ISound.h"
|
||||||
|
|
||||||
namespace FlippR_Driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace output
|
namespace output
|
||||||
{
|
{
|
||||||
@@ -25,24 +25,24 @@ namespace output
|
|||||||
class OutputDriver : public IOutputDriver
|
class OutputDriver : public IOutputDriver
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
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);
|
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);
|
||||||
|
|
||||||
virtual ~OutputDriver() = default;
|
virtual ~OutputDriver() = default;
|
||||||
|
|
||||||
std::vector<std::shared_ptr<ICabinetItem>> get_cabinet_items();
|
std::vector<std::shared_ptr<ICabinetItem>> get_cabinet_items();
|
||||||
std::vector<std::shared_ptr<ISound>> get_sounds();
|
std::vector<std::shared_ptr<ISound>> get_sounds();
|
||||||
std::vector<std::shared_ptr<IDisplay>> get_displays();
|
std::vector<std::shared_ptr<IDisplay>> get_displays();
|
||||||
|
|
||||||
std::shared_ptr<ICabinetItem> get_cabinet_item(std::string name);
|
std::shared_ptr<ICabinetItem> get_cabinet_item(std::string name);
|
||||||
std::shared_ptr<ISound> get_sound(std::string name);
|
std::shared_ptr<ISound> get_sound(std::string name);
|
||||||
std::shared_ptr<IDisplay> get_display(char number);
|
std::shared_ptr<IDisplay> get_display(char number);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<std::string, std::shared_ptr<ICabinetItem>> cabinet_items;
|
std::map<std::string, std::shared_ptr<ICabinetItem>> cabinet_items;
|
||||||
std::map<char, std::shared_ptr<IDisplay>> displays;
|
std::map<char, std::shared_ptr<IDisplay>> displays;
|
||||||
std::map<std::string, std::shared_ptr<ISound>> sounds;
|
std::map<std::string, std::shared_ptr<ISound>> sounds;
|
||||||
};
|
};
|
||||||
|
|
||||||
} /* namespace output */
|
} /* namespace output */
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#include "OutputDriverFactory.h"
|
#include "OutputDriverFactory.h"
|
||||||
|
|
||||||
namespace FlippR_Driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace output
|
namespace output
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,14 +2,14 @@
|
|||||||
// Created by rhetenor on 04.10.18.
|
// Created by rhetenor on 04.10.18.
|
||||||
//
|
//
|
||||||
|
|
||||||
#ifndef FLIPPR_DRIVER_OUTPUTDRIVERFACTORY_H
|
#ifndef flippR_driver_OUTPUTDRIVERFACTORY_H
|
||||||
#define FLIPPR_DRIVER_OUTPUTDRIVERFACTORY_H
|
#define flippR_driver_OUTPUTDRIVERFACTORY_H
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "OutputDriver.h"
|
#include "OutputDriver.h"
|
||||||
|
|
||||||
namespace FlippR_Driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace output
|
namespace output
|
||||||
{
|
{
|
||||||
@@ -21,4 +21,4 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //FLIPPR_DRIVER_OUTPUTDRIVERFACTORY_H
|
#endif //flippR_driver_OUTPUTDRIVERFACTORY_H
|
||||||
|
|||||||
@@ -10,21 +10,22 @@
|
|||||||
|
|
||||||
#include "ICabinetItem.h"
|
#include "ICabinetItem.h"
|
||||||
|
|
||||||
|
#include "ActivationStrategy.h"
|
||||||
#include "utility/IOutputGPIOInterface.h"
|
#include "utility/IOutputGPIOInterface.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace FlippR_Driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace output
|
namespace output
|
||||||
{
|
{
|
||||||
|
|
||||||
class CabinetItem : public ICabinetItem
|
class OutputItem : public ICabinetItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CabinetItem(std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface, int address, std::string name);
|
OutputItem(std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface, int address, std::string name);
|
||||||
virtual ~CabinetItem();
|
virtual ~OutputItem();
|
||||||
|
|
||||||
virtual bool isActivated();
|
virtual bool isActivated();
|
||||||
virtual bool activate();
|
virtual bool activate();
|
||||||
@@ -35,6 +36,10 @@ protected:
|
|||||||
std::string name;
|
std::string name;
|
||||||
|
|
||||||
bool activated;
|
bool activated;
|
||||||
|
|
||||||
|
strategy::ActivationStrategy* strategy;
|
||||||
|
|
||||||
|
std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface;
|
||||||
};
|
};
|
||||||
|
|
||||||
} /* namespace output */
|
} /* namespace output */
|
||||||
@@ -7,12 +7,12 @@
|
|||||||
|
|
||||||
#include "Solenoid.h"
|
#include "Solenoid.h"
|
||||||
|
|
||||||
namespace FlippR_Driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace output {
|
namespace output {
|
||||||
|
|
||||||
Solenoid::Solenoid(std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface, int address, std::string name) :
|
Solenoid::Solenoid(std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface, int address, std::string name) :
|
||||||
CabinetItem(output_gpio_interface, address, name)
|
OutputItem(output_gpio_interface, address, name)
|
||||||
{
|
{
|
||||||
// TODO Auto-generated constructor stub
|
// TODO Auto-generated constructor stub
|
||||||
|
|
||||||
|
|||||||
@@ -8,14 +8,14 @@
|
|||||||
#ifndef _SRC_OUTPUT_SOLENOID_H_
|
#ifndef _SRC_OUTPUT_SOLENOID_H_
|
||||||
#define _SRC_OUTPUT_SOLENOID_H_
|
#define _SRC_OUTPUT_SOLENOID_H_
|
||||||
|
|
||||||
#include "CabinetItem.h"
|
#include "OutputItem.h"
|
||||||
|
|
||||||
namespace FlippR_Driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace output
|
namespace output
|
||||||
{
|
{
|
||||||
|
|
||||||
class Solenoid : public CabinetItem
|
class Solenoid : public OutputItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Solenoid(std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface, int address, std::string name);
|
Solenoid(std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface, int address, std::string name);
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
#include "Sound.h"
|
#include "Sound.h"
|
||||||
|
|
||||||
namespace FlippR_Driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace output
|
namespace output
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
#include "utility/IOutputGPIOInterface.h"
|
#include "utility/IOutputGPIOInterface.h"
|
||||||
|
|
||||||
namespace FlippR_Driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace output
|
namespace output
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
using namespace boost;
|
using namespace boost;
|
||||||
|
|
||||||
namespace FlippR_Driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace utility
|
namespace utility
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
#include "wiringPi/wiringPi.h"
|
#include "wiringPi/wiringPi.h"
|
||||||
#include "json/json.hpp"
|
#include "json/json.hpp"
|
||||||
|
|
||||||
namespace FlippR_Driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace utility
|
namespace utility
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
namespace FlippR_Driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace utility
|
namespace utility
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
#ifndef SRC_UTILITIES_IBLOCKINGQUEUE_H_
|
#ifndef SRC_UTILITIES_IBLOCKINGQUEUE_H_
|
||||||
#define SRC_UTILITIES_IBLOCKINGQUEUE_H_
|
#define SRC_UTILITIES_IBLOCKINGQUEUE_H_
|
||||||
|
|
||||||
namespace FlippR_Driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace utility
|
namespace utility
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
#ifndef SRC_UTILITIES_IINPUTGPIOINTERFACE_H_
|
#ifndef SRC_UTILITIES_IINPUTGPIOINTERFACE_H_
|
||||||
#define SRC_UTILITIES_IINPUTGPIOINTERFACE_H_
|
#define SRC_UTILITIES_IINPUTGPIOINTERFACE_H_
|
||||||
|
|
||||||
namespace FlippR_Driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace utility
|
namespace utility
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,18 +2,26 @@
|
|||||||
// Created by rhetenor on 10.10.18.
|
// Created by rhetenor on 10.10.18.
|
||||||
//
|
//
|
||||||
|
|
||||||
#ifndef FLIPPR_DRIVER_IOUTPUTGPIOINTERFACE_H
|
#ifndef flippR_driver_IOUTPUTGPIOINTERFACE_H
|
||||||
#define 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
|
namespace utility
|
||||||
{
|
{
|
||||||
|
|
||||||
class IOutputGPIOInterface
|
class IOutputGPIOInterface
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
void activate(int address, std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface);
|
||||||
|
void deactivate(int address,std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif //FLIPPR_DRIVER_IOUTPUTGPIOINTERFACE_H
|
#endif //flippR_driver_IOUTPUTGPIOINTERFACE_H
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
#include "easylogging/easylogging++.h"
|
#include "easylogging/easylogging++.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
namespace FlippR_Driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace utility
|
namespace utility
|
||||||
{
|
{
|
||||||
@@ -46,7 +46,7 @@ void InputGPIOInterface::write_col(char data)
|
|||||||
write_pin(this->col_address_C, data & 0b100);
|
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);
|
init_members(input_config_stream);
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
#include "IInputGPIOInterface.h"
|
#include "IInputGPIOInterface.h"
|
||||||
#include "GPIOInterface.h"
|
#include "GPIOInterface.h"
|
||||||
|
|
||||||
namespace FlippR_Driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace utility
|
namespace utility
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
INITIALIZE_EASYLOGGINGPP
|
INITIALIZE_EASYLOGGINGPP
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace FlippR_Driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace utility
|
namespace utility
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
namespace FlippR_Driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace utility
|
namespace utility
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
#include "GPIOInterface.h"
|
#include "GPIOInterface.h"
|
||||||
#include <mcp23017.h>
|
#include <mcp23017.h>
|
||||||
|
|
||||||
namespace FlippR_Driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace utility
|
namespace utility
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -12,15 +12,9 @@
|
|||||||
|
|
||||||
#define LOGGER_FILE "driver.log"
|
#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_MATRIX_SIZE 8
|
||||||
#define INPUT_SLEEP_DURATION_NANO 800
|
#define INPUT_SLEEP_DURATION_NANO 800
|
||||||
|
|
||||||
#define PULLDOWN false
|
#define PULLDOWN false
|
||||||
|
|
||||||
#define HIGHEST_INPUT_EVENT_PRIORITY 0
|
#define VALID_DISPLAY_CHARACTERS [1,2,3,4,5,6,7,8,9,0,\0]
|
||||||
|
|||||||
@@ -23,8 +23,8 @@
|
|||||||
|
|
||||||
|
|
||||||
using namespace fakeit;
|
using namespace fakeit;
|
||||||
using namespace FlippR_Driver;
|
using namespace flippR_driver;
|
||||||
using namespace Input;
|
using namespace input;
|
||||||
using namespace utility;
|
using namespace utility;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
|
|
||||||
using namespace fakeit;
|
using namespace fakeit;
|
||||||
using namespace FlippR_Driver::utility;
|
using namespace flippR_driver::utility;
|
||||||
|
|
||||||
SCENARIO("An EventHandler gets created", "[construction}")
|
SCENARIO("An EventHandler gets created", "[construction}")
|
||||||
{
|
{
|
||||||
@@ -26,15 +26,15 @@ SCENARIO("An EventHandler gets created", "[construction}")
|
|||||||
{
|
{
|
||||||
LoggerFactory::CreateInputTestLogger();
|
LoggerFactory::CreateInputTestLogger();
|
||||||
|
|
||||||
Mock<FlippR_Driver::Input::IInputDriver> input_driver_mock;
|
Mock<flippR_driver::input::IInputDriver> input_driver_mock;
|
||||||
Fake(Dtor(input_driver_mock));
|
Fake(Dtor(input_driver_mock));
|
||||||
When(Method(input_driver_mock, register_event_handler)).AlwaysReturn();
|
When(Method(input_driver_mock, register_event_handler)).AlwaysReturn();
|
||||||
When(Method(input_driver_mock, unregister_event_handler)).AlwaysReturn();
|
When(Method(input_driver_mock, unregister_event_handler)).AlwaysReturn();
|
||||||
|
|
||||||
WHEN("the event handler gets created")
|
WHEN("the event handler gets created")
|
||||||
{
|
{
|
||||||
std::shared_ptr<FlippR_Driver::Input::IInputDriver> driver_ptr(&input_driver_mock.get());
|
std::shared_ptr<flippR_driver::input::IInputDriver> driver_ptr(&input_driver_mock.get());
|
||||||
FlippR_Driver::Input::EventHandler handler(driver_ptr);
|
flippR_driver::input::EventHandler handler(driver_ptr);
|
||||||
|
|
||||||
THEN("It should register itself at the input_driver")
|
THEN("It should register itself at the input_driver")
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -20,8 +20,8 @@
|
|||||||
|
|
||||||
#include "input/EventNotifier.h"
|
#include "input/EventNotifier.h"
|
||||||
|
|
||||||
using namespace FlippR_Driver;
|
using namespace flippR_driver;
|
||||||
using namespace Input;
|
using namespace input;
|
||||||
using namespace fakeit;
|
using namespace fakeit;
|
||||||
using namespace utility;
|
using namespace utility;
|
||||||
|
|
||||||
|
|||||||
@@ -19,8 +19,8 @@
|
|||||||
|
|
||||||
|
|
||||||
using namespace fakeit;
|
using namespace fakeit;
|
||||||
using namespace FlippR_Driver;
|
using namespace flippR_driver;
|
||||||
using namespace Input;
|
using namespace input;
|
||||||
using namespace utility;
|
using namespace utility;
|
||||||
|
|
||||||
SCENARIO("An InputDriver gets created", "[construction}")
|
SCENARIO("An InputDriver gets created", "[construction}")
|
||||||
@@ -58,14 +58,14 @@ SCENARIO("An EventHandler [un]registers at the driver", "[un-register]")
|
|||||||
{
|
{
|
||||||
LoggerFactory::CreateInputTestLogger();
|
LoggerFactory::CreateInputTestLogger();
|
||||||
|
|
||||||
Mock<FlippR_Driver::Input::IDetector> detector_mock;
|
Mock<flippR_driver::input::IDetector> detector_mock;
|
||||||
Fake(Dtor(detector_mock));
|
Fake(Dtor(detector_mock));
|
||||||
|
|
||||||
Mock<IEventHandler> event_handler_mock;
|
Mock<IEventHandler> event_handler_mock;
|
||||||
Fake(Method(event_handler_mock, handle));
|
Fake(Method(event_handler_mock, handle));
|
||||||
Fake(Dtor(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(Method(event_notifier_mock, register_event_handler));
|
Fake(Method(event_notifier_mock, register_event_handler));
|
||||||
Fake(Method(event_notifier_mock, unregister_event_handler));
|
Fake(Method(event_notifier_mock, unregister_event_handler));
|
||||||
Fake(Dtor(event_notifier_mock));
|
Fake(Dtor(event_notifier_mock));
|
||||||
@@ -105,13 +105,13 @@ SCENARIO("An Input Driver is created normally", "")
|
|||||||
{
|
{
|
||||||
LoggerFactory::CreateInputTestLogger();
|
LoggerFactory::CreateInputTestLogger();
|
||||||
|
|
||||||
Mock<FlippR_Driver::Input::IDetector> detector_mock;
|
Mock<flippR_driver::input::IDetector> detector_mock;
|
||||||
Fake(Dtor(detector_mock));
|
Fake(Dtor(detector_mock));
|
||||||
|
|
||||||
Mock<IEventHandler> event_handler_mock;
|
Mock<IEventHandler> event_handler_mock;
|
||||||
Fake(Dtor(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));
|
Fake(Dtor(event_notifier_mock));
|
||||||
|
|
||||||
std::shared_ptr<IEventNotifier> event_notifier_ptr(&event_notifier_mock.get());
|
std::shared_ptr<IEventNotifier> event_notifier_ptr(&event_notifier_mock.get());
|
||||||
|
|||||||
@@ -17,16 +17,16 @@
|
|||||||
// testing purposes
|
// testing purposes
|
||||||
#define private public
|
#define private public
|
||||||
|
|
||||||
#include "output/Display.h"
|
#include "Display.h"
|
||||||
|
|
||||||
using namespace FlippR_Driver::output;
|
using namespace flippR_driver::output;
|
||||||
using namespace fakeit;
|
using namespace fakeit;
|
||||||
|
|
||||||
SCENARIO("Creating a Display object", "")
|
SCENARIO("Creating a Display object", "")
|
||||||
{
|
{
|
||||||
GIVEN("Just a Display with 7 digits")
|
GIVEN("Just a Display with 7 digits")
|
||||||
{
|
{
|
||||||
Display<7> display(5,5);
|
SevenDigitDisplay display(5,5);
|
||||||
WHEN("A content is set for the display")
|
WHEN("A content is set for the display")
|
||||||
{
|
{
|
||||||
std::string content_string = "1234567";
|
std::string content_string = "1234567";
|
||||||
@@ -43,7 +43,7 @@ SCENARIO("Creating a Display object", "")
|
|||||||
display.write_score(12345);
|
display.write_score(12345);
|
||||||
THEN("The content should look like: \" 12345\" ")
|
THEN("The content should look like: \" 12345\" ")
|
||||||
{
|
{
|
||||||
std::string content_string = " 12345";
|
std::string content_string = "\0\012345";
|
||||||
std::array<char,7> content;
|
std::array<char,7> content;
|
||||||
std::copy(content_string.begin(), content_string.end(), content.data());
|
std::copy(content_string.begin(), content_string.end(), content.data());
|
||||||
|
|
||||||
@@ -51,14 +51,16 @@ SCENARIO("Creating a Display object", "")
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
WHEN("A score (12345678), which is longer than the digit is written")
|
WHEN("A score (12345678), which is longer than the digit is written")
|
||||||
display.write_score(12345678);
|
|
||||||
THEN("The content should look like: \"2345678\" ")
|
|
||||||
{
|
{
|
||||||
std::string content_string = "2345678";
|
display.write_score(12345678);
|
||||||
std::array<char,7> content;
|
THEN("The content should look like: \"9999999\"-> highest number ")
|
||||||
std::copy(content_string.begin(), content_string.end(), content.data());
|
{
|
||||||
|
std::string content_string = "9999999";
|
||||||
|
std::array<char,7> content;
|
||||||
|
std::copy(content_string.begin(), content_string.end(), content.data());
|
||||||
|
|
||||||
REQUIRE(display.content == content);
|
REQUIRE(display.content == content);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
#include "output/DisplayController.h"
|
#include "output/DisplayController.h"
|
||||||
|
|
||||||
using namespace FlippR_Driver::output;
|
using namespace flippR_driver::output;
|
||||||
using namespace fakeit;
|
using namespace fakeit;
|
||||||
|
|
||||||
SCENARIO("")
|
SCENARIO("")
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
#include "output/Lamp.h"
|
#include "output/Lamp.h"
|
||||||
|
|
||||||
using namespace FlippR_Driver::output;
|
using namespace flippR_driver::output;
|
||||||
using namespace fakeit;
|
using namespace fakeit;
|
||||||
|
|
||||||
SCENARIO("")
|
SCENARIO("")
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
#include "output/OutputDriver.h"
|
#include "output/OutputDriver.h"
|
||||||
|
|
||||||
using namespace FlippR_Driver::output;
|
using namespace flippR_driver::output;
|
||||||
using namespace fakeit;
|
using namespace fakeit;
|
||||||
|
|
||||||
SCENARIO("")
|
SCENARIO("")
|
||||||
|
|||||||
@@ -17,9 +17,9 @@
|
|||||||
// testing purposes
|
// testing purposes
|
||||||
#define private public
|
#define private public
|
||||||
|
|
||||||
#include "output/CabinetItem.h"
|
#include "../../src/output/OutputItem.h"
|
||||||
|
|
||||||
using namespace FlippR_Driver::output;
|
using namespace flippR_driver::output;
|
||||||
using namespace fakeit;
|
using namespace fakeit;
|
||||||
|
|
||||||
SCENARIO("")
|
SCENARIO("")
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
#include "output/Solenoid.h"
|
#include "output/Solenoid.h"
|
||||||
|
|
||||||
using namespace FlippR_Driver::output;
|
using namespace flippR_driver::output;
|
||||||
using namespace fakeit;
|
using namespace fakeit;
|
||||||
|
|
||||||
SCENARIO("")
|
SCENARIO("")
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
#include "output/Sound.h"
|
#include "output/Sound.h"
|
||||||
|
|
||||||
using namespace FlippR_Driver::output;
|
using namespace flippR_driver::output;
|
||||||
using namespace fakeit;
|
using namespace fakeit;
|
||||||
|
|
||||||
SCENARIO("")
|
SCENARIO("")
|
||||||
|
|||||||
Reference in New Issue
Block a user