Did big refactoring and further adapted OutputDriverFactory as well as uptuput dricer to new board layouts.
This commit is contained in:
@@ -14,12 +14,11 @@ namespace flippR_driver
|
||||
return input::InputDriverFactory::get_InputDriver(input_config_stream, matrix_config_stream);
|
||||
}
|
||||
|
||||
std::shared_ptr<output::OutputDriver> get_OutputDriver(std::istream& output_pin_config,
|
||||
std::istream& lamp_config,
|
||||
std::shared_ptr<output::OutputDriver> get_OutputDriver(std::istream& lamp_config,
|
||||
std::istream& solenoid_config,
|
||||
std::istream& sound_config,
|
||||
std::istream& display_config)
|
||||
{
|
||||
return output::OutputDriverFactory::get_OutputDriver(output_pin_config, lamp_config, solenoid_config, sound_config, display_config);
|
||||
return output::OutputDriverFactory::get_OutputDriver(lamp_config, solenoid_config, sound_config, display_config);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,4 +50,12 @@ void PinController::initialize_port_expander(const uint8_t i2c_address, const ui
|
||||
}
|
||||
|
||||
|
||||
void PinController::initialize_pins_output(const uint8_t pin_base, std::map<std::string, uint8_t>::iterator begin, std::map<std::string, uint8_t>::iterator end)
|
||||
{
|
||||
for(;begin != end; begin++)
|
||||
{
|
||||
initialize_output_pin(pin_base + begin->second);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include <mutex>
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
@@ -32,6 +33,8 @@ protected:
|
||||
|
||||
static bool read_pin(uint8_t address);
|
||||
|
||||
static void initialize_pins_output(const uint8_t pin_base, std::map<std::string, uint8_t>::iterator begin, std::map<std::string, uint8_t>::iterator end);
|
||||
|
||||
public:
|
||||
static std::once_flag GPIO_LIB_INITIALIZED;
|
||||
};
|
||||
|
||||
@@ -6,22 +6,32 @@
|
||||
#define FLIPPR_DRIVER_DISPLAYPINCONTROLLER_H
|
||||
|
||||
#include "output/items/OutputDisplay.h"
|
||||
#include "OutputPinController.h"
|
||||
#include "PinController.h"
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
|
||||
class DisplayBoardPinController : public OutputPinController
|
||||
class DisplayBoardPinController : public PinController
|
||||
{
|
||||
public:
|
||||
virtual ~DisplayBoardPinController() = default;
|
||||
explicit DisplayBoardPinController(std::map<std::string, uint8_t> pins_display);
|
||||
~DisplayBoardPinController() override = default;
|
||||
|
||||
virtual void activate_displays() const = 0;
|
||||
virtual void deactivate_displays() const = 0;
|
||||
void activate_displays() const;
|
||||
void deactivate_displays() const;
|
||||
|
||||
virtual void write_display(const items::OutputDisplay &display) const = 0;
|
||||
void write_display(const items::OutputDisplay &display) const;
|
||||
|
||||
private:
|
||||
void write_display_digit(uint8_t display_address, uint8_t content, uint8_t position) const;
|
||||
void select_display_segment(uint8_t digit) const;
|
||||
void select_display_digit(uint8_t content) const;
|
||||
void run_display(uint8_t address) const;
|
||||
|
||||
private:
|
||||
const std::map<std::string, uint8_t> pins_display_board;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,12 @@
|
||||
#ifndef _SRC_OUTPUT_IDISPLAYCONTROLLER_H_
|
||||
#define _SRC_OUTPUT_IDISPLAYCONTROLLER_H_
|
||||
|
||||
#include <vector>
|
||||
#include <thread>
|
||||
|
||||
#include "output/items/OutputDisplay.h"
|
||||
#include "output/DisplayBoardPinController.h"
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
@@ -15,12 +21,23 @@ namespace output
|
||||
|
||||
class DisplayController
|
||||
{
|
||||
|
||||
public:
|
||||
virtual ~DisplayController () = default;
|
||||
explicit DisplayController(std::vector<std::shared_ptr<items::OutputDisplay>> displays, std::unique_ptr<DisplayBoardPinController> pin_controller);
|
||||
~DisplayController();
|
||||
|
||||
virtual void activate_displays() const = 0;
|
||||
virtual void deactivate_displays() const = 0;
|
||||
void activate_displays() const;
|
||||
void deactivate_displays() const;
|
||||
|
||||
private:
|
||||
void cycle_displays() const;
|
||||
|
||||
private:
|
||||
const std::vector<std::shared_ptr<items::OutputDisplay>> displays;
|
||||
|
||||
const std::shared_ptr<DisplayBoardPinController> pin_controller;
|
||||
|
||||
std::thread display_cycle_thread;
|
||||
bool is_running;
|
||||
};
|
||||
|
||||
} /* namespace output */
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#ifndef FLIPPR_DRIVER_DRIVERBOARDPINCONTROLLER_H
|
||||
#define FLIPPR_DRIVER_DRIVERBOARDPINCONTROLLER_H
|
||||
|
||||
#include "OutputPinController.h"
|
||||
#include "PinController.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace items
|
||||
class DriverBoardItem;
|
||||
}
|
||||
|
||||
class DriverBoardPinController : public OutputPinController
|
||||
class DriverBoardPinController : public PinController
|
||||
{
|
||||
public:
|
||||
virtual ~DriverBoardPinController() = default;
|
||||
|
||||
@@ -2,22 +2,17 @@
|
||||
// Created by rhetenor on 04.10.18.
|
||||
//
|
||||
|
||||
|
||||
|
||||
#include "OutputDriverFactory.h"
|
||||
|
||||
#include "utility/LoggerFactory.h"
|
||||
|
||||
#include "output/detail/OutputDriver.h"
|
||||
#include "output/detail/DisplayController.h"
|
||||
|
||||
#include "output/detail/DisplayBoardPinController.h"
|
||||
#include "output/detail/SoundBoardPinController.h"
|
||||
|
||||
#include "output/DisplayController.h"
|
||||
#include "output/SoundBoardPinController.h"
|
||||
#include "output/items/detail/EightDigitDisplay.h"
|
||||
|
||||
#include "output/DisplayBoardPinController.h"
|
||||
#include "output/items/detail/SevenDigitDisplay.h"
|
||||
#include "output/items/Flipper.h"
|
||||
#include "output/items/detail/Flipper.h"
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
@@ -28,8 +23,7 @@ namespace OutputDriverFactory
|
||||
|
||||
using namespace nlohmann;
|
||||
|
||||
std::shared_ptr<OutputDriver> get_OutputDriver(std::istream& output_pin_config,
|
||||
std::istream& solenoid_config,
|
||||
std::shared_ptr<OutputDriver> get_OutputDriver(std::istream& solenoid_config,
|
||||
std::istream& lamp_config,
|
||||
std::istream& sound_config,
|
||||
std::istream& display_config)
|
||||
@@ -38,29 +32,21 @@ std::shared_ptr<OutputDriver> get_OutputDriver(std::istream& output_pin_config,
|
||||
|
||||
std::shared_ptr<std::mutex> output_pin_mutex;
|
||||
|
||||
json output_config;
|
||||
output_pin_config >> output_config;
|
||||
|
||||
|
||||
std::shared_ptr<DriverBoardPinController> driver_board_pin_controller(new DriverBoardPinController(output_pin_mutex));
|
||||
auto solenoids = create_solenoids(solenoid_config, driver_board_pin_controller);
|
||||
//TODO create flippers
|
||||
auto flippers = create_flippers(solenoid_config, driver_board_pin_controller);
|
||||
auto lamps = create_lamps(lamp_config, driver_board_pin_controller);
|
||||
|
||||
uint8_t sound_fire_address = get_sound_fire_address(sound_config);
|
||||
std::shared_ptr<SoundBoardPinController> sound_board_pin_controller(new detail::SoundBoardPinController(output_pin_mutex, sound_fire_address));
|
||||
std::shared_ptr<SoundBoardPinController> sound_board_pin_controller(new SoundBoardPinController(output_pin_mutex, sound_fire_address));
|
||||
auto sounds = create_sounds(sound_config, sound_board_pin_controller);
|
||||
|
||||
// json display_board_config = output_config.at("display_board");
|
||||
// std::unique_ptr<DisplayBoardPinController> display_board_pin_controller(new detail::DisplayBoardPinController(parse_pins_display_board(display_board_config)));
|
||||
// auto displays = create_displays(display_config);
|
||||
//
|
||||
// std::unique_ptr<DisplayController> display_controller(new detail::DisplayController(displays, std::move(display_board_pin_controller)));
|
||||
//
|
||||
// auto display_map = map_displays(displays);
|
||||
//
|
||||
// return std::make_shared<detail::OutputDriver>(std::move(display_controller), solenoids, lamps, sounds, display_map);
|
||||
// return std::make_shared<detail::OutputDriver>(NULL, NULL, NULL, NULL, NULL);
|
||||
std::unique_ptr<DisplayBoardPinController> display_board_pin_controller(new DisplayBoardPinController(parse_pins_display_board(display_config)));
|
||||
auto displays = create_displays(display_config);
|
||||
std::unique_ptr<DisplayController> display_controller(new DisplayController(displays, std::move(display_board_pin_controller)));
|
||||
auto display_map = map_displays(displays);
|
||||
|
||||
return std::make_shared<OutputDriver>(std::move(display_controller), solenoids, lamps, sounds, flippers, display_map);
|
||||
}
|
||||
|
||||
std::map<std::string, std::shared_ptr<items::Solenoid>> create_solenoids(std::istream & solenoid_config, std::shared_ptr<DriverBoardPinController> &pin_controller)
|
||||
@@ -210,7 +196,86 @@ uint8_t get_sound_fire_address(std::istream &sound_config)
|
||||
return pin_base + address;
|
||||
}
|
||||
|
||||
void initialize_port_extenders(nlohmann::json &port_extenders, PinController * pin_controller, const std::string & file_name)
|
||||
std::map<std::string, uint8_t> parse_pins_display_board(std::istream &display_config)
|
||||
{
|
||||
std::string config_file = "display_config.json";
|
||||
|
||||
json display_config_json;
|
||||
display_config >> display_config_json;
|
||||
|
||||
json display_board_config = get_element("display_board", display_config_json, config_file);
|
||||
|
||||
std::map<std::string, uint8_t> pins_display;
|
||||
|
||||
pins_display["run"] = get_value<uint8_t>("run", display_board_config, config_file);
|
||||
|
||||
json display_select = display_board_config.at("display_select");
|
||||
for(int i = 1; i < 6; i++)
|
||||
{
|
||||
pins_display["display_select" + std::to_string(i)] = get_value<uint8_t>(std::to_string(i), display_select, config_file);
|
||||
}
|
||||
|
||||
json segment_select = display_board_config.at("segment_select");
|
||||
pins_display["segment_select_A"] = get_value<uint8_t>("A", segment_select, config_file);
|
||||
pins_display["segment_select_B"] = get_value<uint8_t>("B", segment_select, config_file);
|
||||
pins_display["segment_select_C"] = get_value<uint8_t>("C", segment_select, config_file);
|
||||
|
||||
json digit_select = display_board_config.at("digit_select");
|
||||
pins_display["digit_select_A"] = get_value<uint8_t>("A", digit_select, config_file);
|
||||
pins_display["digit_select_B"] = get_value<uint8_t>("B", digit_select, config_file);
|
||||
pins_display["digit_select_C"] = get_value<uint8_t>("C", digit_select, config_file);
|
||||
pins_display["digit_select_D"] = get_value<uint8_t>("D", digit_select, config_file);;
|
||||
|
||||
return pins_display;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<items::OutputDisplay>> create_displays(std::istream &display_config)
|
||||
{
|
||||
|
||||
json display_config_json;
|
||||
display_config >> display_config_json;
|
||||
|
||||
json displays_json = get_element("displays", display_config_json, "display_config.json");
|
||||
|
||||
std::vector<std::shared_ptr<items::OutputDisplay>> displays;
|
||||
for(json &display_json : displays_json)
|
||||
{
|
||||
auto display = create_display(display_json);
|
||||
displays.push_back(display);
|
||||
}
|
||||
|
||||
return displays;
|
||||
}
|
||||
|
||||
std::shared_ptr<items::OutputDisplay> create_display(json & display_json)
|
||||
{
|
||||
std::string config_file = "display_config.json";
|
||||
auto id = get_value<uint8_t>("id", display_json, config_file);
|
||||
auto address = get_value<uint8_t>("address", display_json, config_file);
|
||||
auto digits = get_value<uint8_t>("digits", display_json, config_file);
|
||||
if(digits == 8)
|
||||
return std::make_shared<items::detail::EightDigitDisplay>(address, id);
|
||||
|
||||
else if(digits == 7)
|
||||
return std::make_shared<items::detail::SevenDigitDisplay>(address, id);
|
||||
|
||||
else
|
||||
throw new std::logic_error("Display digits can either be 7 or 8");
|
||||
}
|
||||
|
||||
std::map<uint8_t, std::shared_ptr<items::Display>> map_displays(const std::vector<std::shared_ptr<items::OutputDisplay>> &displays)
|
||||
{
|
||||
std::map<uint8_t, std::shared_ptr<items::Display>> display_map;
|
||||
|
||||
for(auto &display : displays)
|
||||
{
|
||||
display_map.emplace(display->get_address(), display);
|
||||
}
|
||||
|
||||
return display_map;
|
||||
}
|
||||
|
||||
void initialize_port_extenders(json &port_extenders, PinController * pin_controller, const std::string & file_name)
|
||||
{
|
||||
|
||||
for (auto & extender_json : port_extenders)
|
||||
|
||||
@@ -23,8 +23,7 @@ namespace output
|
||||
{
|
||||
namespace OutputDriverFactory
|
||||
{
|
||||
std::shared_ptr<OutputDriver> get_OutputDriver(std::istream& output_pin_config,
|
||||
std::istream& solenoid_config,
|
||||
std::shared_ptr<OutputDriver> get_OutputDriver(std::istream& solenoid_config,
|
||||
std::istream& lamp_config,
|
||||
std::istream& sound_config,
|
||||
std::istream& display_config);
|
||||
@@ -42,6 +41,11 @@ std::map<std::string, std::shared_ptr<items::Sound>> create_sounds(std::istream
|
||||
std::shared_ptr<items::detail::Sound> create_sound(nlohmann::json &sound_json, nlohmann::json &port_extenders, std::shared_ptr<SoundBoardPinController> &pin_controller, std::chrono::milliseconds &deactivation_time);
|
||||
uint8_t get_sound_fire_address(std::istream &sound_config);
|
||||
|
||||
std::map<std::string, uint8_t> parse_pins_display_board(std::istream & display_config);
|
||||
std::vector<std::shared_ptr<items::OutputDisplay>> create_displays(std::istream &display_config);
|
||||
std::shared_ptr<items::OutputDisplay> create_display(nlohmann::json &display_json);
|
||||
std::map<uint8_t, std::shared_ptr<items::Display>> map_displays(const std::vector<std::shared_ptr<items::OutputDisplay>> &displays);
|
||||
|
||||
void initialize_port_extenders(nlohmann::json &port_extenders, PinController * pin_controller, const std::string & file_name);
|
||||
|
||||
uint8_t get_pin_base(nlohmann::json & object, nlohmann::json & port_extenders, const std::string & config_file_name);
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
/*
|
||||
* OutputGPIOInterface.h
|
||||
*
|
||||
* Created on: May 31, 2018
|
||||
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
|
||||
*/
|
||||
|
||||
#include "OutputPinController.h"
|
||||
|
||||
#include "utility/config.h"
|
||||
#include "wiringPi/mcp23017.h"
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
|
||||
void OutputPinController::initialize_i2c_address(const uint8_t i2c_address, const uint8_t pin_base)
|
||||
{
|
||||
mcp23017Setup(pin_base, i2c_address);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* OutputGPIOInterface.h
|
||||
*
|
||||
* Created on: May 31, 2018
|
||||
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
|
||||
*/
|
||||
|
||||
#ifndef SRC_UTILITIES_OUTPUTGPIOINTERFACE_H_
|
||||
#define SRC_UTILITIES_OUTPUTGPIOINTERFACE_H_
|
||||
|
||||
#include "PinController.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
|
||||
namespace items
|
||||
{
|
||||
class DriverBoardItem;
|
||||
}
|
||||
class OutputPinController : public PinController
|
||||
{
|
||||
|
||||
public:
|
||||
virtual ~OutputPinController() = default;
|
||||
|
||||
protected:
|
||||
static void initialize_i2c_address(const uint8_t i2c_address, const uint8_t pin_base);
|
||||
static void initialize_pins_output(const uint8_t pin_base, std::map<std::string, uint8_t>::iterator begin, std::map<std::string, uint8_t>::iterator end);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -6,20 +6,32 @@
|
||||
#define FLIPPR_DRIVER_OUTPUT_SOUNDBOARDPINCONTROLLER_H
|
||||
|
||||
#include "output/items/detail/Sound.h"
|
||||
#include "OutputPinController.h"
|
||||
#include "PinController.h"
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
|
||||
class SoundBoardPinController : public OutputPinController
|
||||
class SoundBoardPinController : public PinController
|
||||
{
|
||||
public:
|
||||
virtual ~SoundBoardPinController() = default;
|
||||
SoundBoardPinController(std::shared_ptr<std::mutex> output_item_mutex, const uint8_t & fire_address);
|
||||
~SoundBoardPinController() override = default;
|
||||
|
||||
virtual void activate(const items::detail::Sound &sound) = 0;
|
||||
virtual void deactivate(const items::detail::Sound &sound) = 0;
|
||||
void activate(const items::detail::Sound &sound);
|
||||
void deactivate(const items::detail::Sound &sound);
|
||||
|
||||
private:
|
||||
void write_sound_address(const uint8_t & address) const;
|
||||
void fire_sound() const;
|
||||
|
||||
void write_pin(const uint8_t & pin, const bool & value) const;
|
||||
|
||||
private:
|
||||
std::shared_ptr<std::mutex> output_item_mutex;
|
||||
|
||||
uint8_t fire_address;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
// Created by rhetenor on 14.12.18.
|
||||
//
|
||||
|
||||
#include <thread>
|
||||
#include "output/DisplayBoardPinController.h"
|
||||
|
||||
#include "DisplayBoardPinController.h"
|
||||
#include <thread>
|
||||
|
||||
#include "utility/config.h"
|
||||
|
||||
@@ -12,8 +12,6 @@ namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
DisplayBoardPinController::DisplayBoardPinController(std::map<std::string, uint8_t> pins_display) :
|
||||
pins_display_board(std::move(pins_display))
|
||||
@@ -77,6 +75,5 @@ void DisplayBoardPinController::run_display(uint8_t address) const
|
||||
write_pin(pins_display_board.at("display_select_" + std::to_string(address)), 1);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
//
|
||||
// Created by rhetenor on 14.12.18.
|
||||
//
|
||||
|
||||
#ifndef FLIPPR_DRIVER_OUTPUT_IMPL_DISPLAYPINCONTROLLER_H
|
||||
#define FLIPPR_DRIVER_OUTPUT_IMPL_DISPLAYPINCONTROLLER_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "output/DisplayBoardPinController.h"
|
||||
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
class DisplayBoardPinController : public output::DisplayBoardPinController
|
||||
{
|
||||
public:
|
||||
explicit DisplayBoardPinController(std::map<std::string, uint8_t> pins_display);
|
||||
~DisplayBoardPinController() override = default;
|
||||
|
||||
void activate_displays() const override;
|
||||
void deactivate_displays() const override;
|
||||
|
||||
void write_display(const items::OutputDisplay &display) const override;
|
||||
|
||||
private:
|
||||
void write_display_digit(uint8_t display_address, uint8_t content, uint8_t position) const;
|
||||
void select_display_segment(uint8_t digit) const;
|
||||
void select_display_digit(uint8_t content) const;
|
||||
void run_display(uint8_t address) const;
|
||||
|
||||
private:
|
||||
const std::map<std::string, uint8_t> pins_display_board;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif //FLIPPR_DRIVER_DISPLAYPINCONTROLLER_H
|
||||
@@ -5,7 +5,7 @@
|
||||
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
|
||||
*/
|
||||
|
||||
#include "DisplayController.h"
|
||||
#include "output/DisplayController.h"
|
||||
|
||||
#include "utility/config.h"
|
||||
|
||||
@@ -13,8 +13,6 @@ namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
DisplayController::DisplayController(std::vector<std::shared_ptr<items::OutputDisplay>> displays, std::unique_ptr<DisplayBoardPinController> pin_controller)
|
||||
: displays(std::move(displays)), pin_controller(std::move(pin_controller)), is_running(true)
|
||||
@@ -58,4 +56,3 @@ void DisplayController::deactivate_displays() const
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* DisplayController.h
|
||||
*
|
||||
* Created on: Aug 7, 2018
|
||||
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
|
||||
*/
|
||||
|
||||
#ifndef _SRC_OUTPUT_DISPLAYCONTROLLER_H_
|
||||
#define _SRC_OUTPUT_DISPLAYCONTROLLER_H_
|
||||
|
||||
#include <vector>
|
||||
#include <thread>
|
||||
|
||||
#include "output/DisplayController.h"
|
||||
|
||||
#include "output/items/OutputDisplay.h"
|
||||
#include "output/DisplayBoardPinController.h"
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
class DisplayController : public output::DisplayController
|
||||
{
|
||||
public:
|
||||
explicit DisplayController(std::vector<std::shared_ptr<items::OutputDisplay>> displays, std::unique_ptr<DisplayBoardPinController> pin_controller);
|
||||
~DisplayController() override;
|
||||
|
||||
void activate_displays() const override;
|
||||
void deactivate_displays() const override;
|
||||
|
||||
private:
|
||||
void cycle_displays() const;
|
||||
|
||||
private:
|
||||
const std::vector<std::shared_ptr<items::OutputDisplay>> displays;
|
||||
|
||||
const std::shared_ptr<DisplayBoardPinController> pin_controller;
|
||||
|
||||
std::thread display_cycle_thread;
|
||||
bool is_running;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <boost/range/algorithm/copy.hpp>
|
||||
#include <thread>
|
||||
|
||||
#include "OutputDriver.h"
|
||||
#include "output/OutputDriver.h"
|
||||
|
||||
#include "utility/config.h"
|
||||
|
||||
@@ -17,13 +17,18 @@ namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
using namespace items;
|
||||
|
||||
OutputDriver::OutputDriver(std::unique_ptr<output::DisplayController> display_controller, std::map<std::string, std::shared_ptr<Solenoid>> solenoids, std::map<std::string, std::shared_ptr<Lamp>> lamps, std::map<std::string, std::shared_ptr<Sound>> sounds, std::map<uint8_t, std::shared_ptr<items::Display>> displays)
|
||||
: display_controller(std::move(display_controller)), solenoids(std::move(solenoids)), lamps(std::move(lamps)), sounds(std::move(sounds)), displays(std::move(displays))
|
||||
OutputDriver::OutputDriver(std::unique_ptr<output::DisplayController> display_controller, std::map<std::string, std::shared_ptr<Solenoid>> solenoids,
|
||||
std::map<std::string, std::shared_ptr<Lamp>> lamps, std::map<std::string, std::shared_ptr<Sound>> sounds,
|
||||
std::map<std::string, std::shared_ptr<items::Flipper>> flippers, std::map<uint8_t, std::shared_ptr<items::Display>> displays):
|
||||
display_controller(std::move(display_controller)),
|
||||
solenoids(std::move(solenoids)),
|
||||
lamps(std::move(lamps)),
|
||||
sounds(std::move(sounds)),
|
||||
flippers(std::move(flippers)),
|
||||
displays(std::move(displays))
|
||||
{
|
||||
CLOG(INFO, OUTPUT_LOGGER) << "Created OutputDriver";
|
||||
}
|
||||
@@ -61,6 +66,16 @@ void OutputDriver::rotate_all_lamps() const
|
||||
}
|
||||
}
|
||||
|
||||
void OutputDriver::activate_all_flipper_relays() const
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void OutputDriver::deactivate_all_flipper_relays() const
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<Sound>> OutputDriver::get_sounds() const
|
||||
{
|
||||
std::vector<std::shared_ptr<Sound>> sounds;
|
||||
@@ -89,6 +104,15 @@ std::vector<std::shared_ptr<Lamp>> OutputDriver::get_lamps() const
|
||||
return lamps;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<items::Flipper>> OutputDriver::get_flippers() const
|
||||
{
|
||||
std::vector<std::shared_ptr<Flipper>> flippers;
|
||||
|
||||
boost::copy(this->flippers | boost::adaptors::map_values, std::back_inserter(flippers));
|
||||
|
||||
return flippers;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<Solenoid>> OutputDriver::get_solenoids() const
|
||||
{
|
||||
std::vector<std::shared_ptr<Solenoid>> solenoids;
|
||||
@@ -113,6 +137,11 @@ boost::optional<std::shared_ptr<items::Sound>> OutputDriver::get_sound(const std
|
||||
return this->sounds.find(name)->second;
|
||||
}
|
||||
|
||||
boost::optional<std::shared_ptr<items::Flipper>> OutputDriver::get_flipper(const std::string &name) const
|
||||
{
|
||||
return this->flippers.find(name)->second;
|
||||
}
|
||||
|
||||
boost::optional<std::shared_ptr<items::Display>> OutputDriver::get_display(uint8_t number) const
|
||||
{
|
||||
return this->displays.find(number)->second;
|
||||
@@ -121,4 +150,3 @@ boost::optional<std::shared_ptr<items::Display>> OutputDriver::get_display(uint8
|
||||
|
||||
}
|
||||
} /* namespace output */
|
||||
}
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* OutputDriver.h
|
||||
*
|
||||
* Created on: Aug 2, 2018
|
||||
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
|
||||
*/
|
||||
|
||||
#ifndef _SRC_OUTPUT_OUTPUTDRIVER_H_
|
||||
#define _SRC_OUTPUT_OUTPUTDRIVER_H_
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "output/OutputDriver.h"
|
||||
#include "output/DisplayController.h"
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
class OutputDriver : public output::OutputDriver
|
||||
{
|
||||
public:
|
||||
OutputDriver(std::unique_ptr<output::DisplayController> display_controller, std::map<std::string, std::shared_ptr<items::Solenoid>> solenoids,
|
||||
std::map<std::string, std::shared_ptr<items::Lamp>> lamps, std::map<std::string, std::shared_ptr<items::Sound>> sounds,
|
||||
std::map<uint8_t, std::shared_ptr<output::items::Display>> displays);
|
||||
|
||||
~OutputDriver() override = default;
|
||||
|
||||
void activate_displays() const override;
|
||||
void deactivate_displays() const override;
|
||||
|
||||
void activate_all_lamps() const override;
|
||||
void deactivate_all_lamps() const override;
|
||||
void rotate_all_lamps() const override;
|
||||
|
||||
void activate_flipper_relay();
|
||||
void activate_top_flipper_relay();
|
||||
void deactivate_flipper_relay();
|
||||
void deactivate_top_flipper_relay();
|
||||
|
||||
// todo driver board run for activate/deactivate?
|
||||
// todo what is flipper_relay ?
|
||||
std::vector<std::shared_ptr<items::Lamp>> get_lamps() const override;
|
||||
std::vector<std::shared_ptr<items::Solenoid>> get_solenoids() const override;
|
||||
std::vector<std::shared_ptr<items::Sound>> get_sounds() const override;
|
||||
std::vector<std::shared_ptr<items::Display>> get_displays() const override;
|
||||
|
||||
boost::optional<std::shared_ptr<items::Lamp>> get_lamp(const std::string &name) const override;
|
||||
boost::optional<std::shared_ptr<items::Solenoid>> get_solenoid(const std::string &name) const override;
|
||||
boost::optional<std::shared_ptr<items::Sound>> get_sound(const std::string &name) const override;
|
||||
boost::optional<std::shared_ptr<items::Display>> get_display(uint8_t number) const override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<output::DisplayController> display_controller;
|
||||
|
||||
const std::map<std::string, std::shared_ptr<items::Lamp>> lamps;
|
||||
const std::map<std::string, std::shared_ptr<items::Solenoid>> solenoids;
|
||||
const std::map<std::string, std::shared_ptr<items::Sound>> sounds;
|
||||
|
||||
const std::map<uint8_t, std::shared_ptr<items::Display>> displays;
|
||||
};
|
||||
|
||||
}
|
||||
} /* namespace output */
|
||||
}
|
||||
#endif
|
||||
@@ -2,7 +2,7 @@
|
||||
// Created by rhetenor on 14.12.18.
|
||||
//
|
||||
|
||||
#include "SoundBoardPinController.h"
|
||||
#include "output/SoundBoardPinController.h"
|
||||
|
||||
#include "utility/config.h"
|
||||
|
||||
@@ -10,8 +10,6 @@ namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
SoundBoardPinController::SoundBoardPinController(std::shared_ptr<std::mutex> output_item_mutex, const uint8_t & fire_address) :
|
||||
output_item_mutex(std::move(output_item_mutex)),
|
||||
@@ -64,4 +62,3 @@ void SoundBoardPinController::write_pin(const uint8_t & pin, const bool & value)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
//
|
||||
// Created by rhetenor on 14.12.18.
|
||||
//
|
||||
|
||||
#ifndef FLIPPR_DRIVER_OUTPUT_IMPL_SOUNDBOARDPINCONTROLLER_H
|
||||
#define FLIPPR_DRIVER_OUTPUT_IMPL_SOUNDBOARDPINCONTROLLER_H
|
||||
|
||||
#include "output/SoundBoardPinController.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
class SoundBoardPinController : public output::SoundBoardPinController
|
||||
{
|
||||
public:
|
||||
SoundBoardPinController(std::shared_ptr<std::mutex> output_item_mutex, const uint8_t & fire_address);
|
||||
~SoundBoardPinController() override = default;
|
||||
|
||||
void activate(const items::detail::Sound &sound) override;
|
||||
void deactivate(const items::detail::Sound &sound) override;
|
||||
|
||||
private:
|
||||
void write_sound_address(const uint8_t & address) const;
|
||||
void fire_sound() const;
|
||||
|
||||
void write_pin(const uint8_t & pin, const bool & value) const;
|
||||
|
||||
private:
|
||||
std::shared_ptr<std::mutex> output_item_mutex;
|
||||
|
||||
uint8_t fire_address;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif //FLIPPR_DRIVER_SOUNDBOARDPINCONTROLLER_H
|
||||
@@ -17,7 +17,7 @@ namespace items
|
||||
namespace detail
|
||||
{
|
||||
|
||||
Display::Display(uint8_t address, uint8_t id) :
|
||||
Display::Display(const uint8_t & address, const uint8_t & id) :
|
||||
address(address),
|
||||
id(id)
|
||||
{
|
||||
@@ -29,7 +29,7 @@ uint8_t Display::get_id() const
|
||||
return this->id;
|
||||
}
|
||||
|
||||
void Display::write_score(unsigned int score, unsigned int length)
|
||||
void Display::write_score(const unsigned int & score, const unsigned int & length)
|
||||
{
|
||||
auto score_string = std::to_string(score);
|
||||
|
||||
@@ -38,7 +38,7 @@ void Display::write_score(unsigned int score, unsigned int length)
|
||||
write_content(score_string, length);
|
||||
}
|
||||
|
||||
std::string Display::fit_score_string(std::string &score_string, unsigned int length)
|
||||
std::string Display::fit_score_string(std::string & score_string, const unsigned int & length)
|
||||
{
|
||||
auto score_length = score_string.length();
|
||||
|
||||
@@ -46,7 +46,6 @@ std::string Display::fit_score_string(std::string &score_string, unsigned int le
|
||||
{
|
||||
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, length, '9');
|
||||
}
|
||||
|
||||
@@ -54,7 +53,7 @@ std::string Display::fit_score_string(std::string &score_string, unsigned int le
|
||||
return score_string;
|
||||
}
|
||||
|
||||
void Display::write_content(std::string content, unsigned int length)
|
||||
void Display::write_content(std::string & content, const unsigned int & length)
|
||||
{
|
||||
if(content.size() > length)
|
||||
{
|
||||
|
||||
@@ -24,18 +24,18 @@ namespace detail
|
||||
class Display : public items::OutputDisplay
|
||||
{
|
||||
public:
|
||||
Display(uint8_t address, uint8_t id);
|
||||
Display(const uint8_t & address, const uint8_t & id);
|
||||
virtual ~Display() = default;
|
||||
|
||||
void write_score(unsigned int score, unsigned int length);
|
||||
void write_content(std::string content, unsigned int length);
|
||||
void write_score(const unsigned int & score, const unsigned int & length);
|
||||
void write_content(std::string & content, const unsigned int & length);
|
||||
|
||||
std::string get_content() const override;
|
||||
uint8_t get_address() const override;
|
||||
uint8_t get_id() const override;
|
||||
|
||||
private:
|
||||
std::string fit_score_string(std::string &score_string, unsigned int length);
|
||||
std::string fit_score_string(std::string & score_string, const unsigned int & length);
|
||||
|
||||
public:
|
||||
std::string content;
|
||||
|
||||
Reference in New Issue
Block a user