Impelements and integrates DisplayFactory. Further does some refactoring
This commit is contained in:
@@ -31,9 +31,9 @@ namespace output
|
||||
class OutputDriver
|
||||
{
|
||||
public:
|
||||
OutputDriver(std::unique_ptr<output::DisplayController> display_controller, std::map<std::string, std::shared_ptr<items::Solenoid>> solenoids,
|
||||
OutputDriver(std::shared_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<std::string, std::shared_ptr<items::Flipper>> flippers, std::map<uint8_t, std::shared_ptr<output::items::Display>> displays);
|
||||
std::map<std::string, std::shared_ptr<items::Flipper>> flippers, std::map<std::string, std::shared_ptr<output::items::Display>> displays);
|
||||
|
||||
~OutputDriver() = default;
|
||||
|
||||
@@ -62,13 +62,13 @@ public:
|
||||
boost::optional<std::shared_ptr<items::Display>> get_display(uint8_t number) const;
|
||||
|
||||
private:
|
||||
std::unique_ptr<output::DisplayController> display_controller;
|
||||
std::shared_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<std::string, std::shared_ptr<items::Flipper>> flippers;
|
||||
const std::map<uint8_t, std::shared_ptr<items::Display>> displays;
|
||||
const std::map<std::string, std::shared_ptr<items::Display>> displays;
|
||||
};
|
||||
|
||||
} /* namespace output */
|
||||
|
||||
@@ -22,6 +22,8 @@ public:
|
||||
virtual void deactivate_displays() const = 0;
|
||||
|
||||
virtual void write_display(const items::OutputDisplay &display) const = 0;
|
||||
|
||||
virtual void set_pin_map(std::map<std::string, uint8_t> & pins_display) = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <output/factories/SoundFactory.h>
|
||||
#include <output/factories/FlipperFactory.h>
|
||||
#include <output/factories/SolenoidFactory.h>
|
||||
#include <output/factories/DisplayFactory.h>
|
||||
#include "OutputDriverFactory.h"
|
||||
|
||||
#include "utility/LoggerFactory.h"
|
||||
@@ -42,94 +43,15 @@ std::shared_ptr<OutputDriver> get_OutputDriver(const std::string & solenoid_conf
|
||||
auto solenoids = get_items<SolenoidFactory, detail::DriverBoardPinController>(solenoid_config_path, driver_board_pin_controller);
|
||||
auto lamps = get_items<LampFactory, detail::DriverBoardPinController>(lamp_config_path, driver_board_pin_controller);
|
||||
|
||||
auto sound_board_pin_controller = create_SoundBoardPinController();
|
||||
auto sound_board_pin_controller = std::make_shared<detail::SoundBoardPinController>(output_pin_mutex);
|
||||
auto sounds = get_items<SoundFactory, detail::SoundBoardPinController>(sound_config_path, sound_board_pin_controller);
|
||||
|
||||
auto display_board_pin_controller = std::make_shared<detail::DisplayBoardPinController>();
|
||||
auto displays = get_items<DisplayFactory, detail::DisplayBoardPinController>(display_config_path, display_board_pin_controller);
|
||||
|
||||
auto display_controller = std::make_unique<detail::DisplayController>(displays, display_board_pin_controller);
|
||||
|
||||
/*std::unique_ptr<DisplayBoardPinController> display_board_pin_controller(new detail::DisplayBoardPinController(parse_pins_display_board(display_config)));
|
||||
auto displays = create_displays();
|
||||
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<OutputDriver>(std::move(display_controller), solenoids, lamps, sounds, flippers, display_map);*/
|
||||
}
|
||||
|
||||
std::map<std::string, uint8_t> parse_pins_display_board(std::istream &display_config)
|
||||
{
|
||||
/* std::string config_file = "display_config.json";
|
||||
|
||||
json display_board_config = get_element("display_board", config::displays, 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 displays_json = get_element("displays", config::displays, "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;
|
||||
}
|
||||
|
||||
std::shared_ptr<SoundBoardPinController> create_SoundBoardPinController()
|
||||
{
|
||||
return std::shared_ptr<SoundBoardPinController>();
|
||||
//return std::make_shared<OutputDriver>(std::move(display_controller), solenoids, lamps, sounds, flippers, displays);
|
||||
}
|
||||
|
||||
template<typename FactoryType, typename ControllerType>
|
||||
@@ -150,6 +72,8 @@ std::map<std::string, std::shared_ptr<items::Item>> get_items(const std::string
|
||||
CLOG(INFO, OUTPUT_LOGGER) << "File " << config_path << " seems to be corrupted: " << ": " << e.what();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,15 +31,6 @@ std::shared_ptr<OutputDriver> get_OutputDriver(const std::string & solenoid_conf
|
||||
template<typename FactoryType, typename ControllerType>
|
||||
std::map<std::string, std::shared_ptr<items::Item>> get_items(const std::string & config_path, std::shared_ptr<PinController> pin_controller);
|
||||
|
||||
std::shared_ptr<SoundBoardPinController> create_SoundBoardPinController();
|
||||
|
||||
std::map<std::string, uint8_t> parse_pins_display_board(std::istream & display_config);
|
||||
std::vector<std::shared_ptr<items::OutputDisplay>> create_displays();
|
||||
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);
|
||||
|
||||
template<typename type>
|
||||
type get_value(const std::string & name, nlohmann::json & object, const std::string & file_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,14 +15,20 @@ namespace output
|
||||
namespace detail
|
||||
{
|
||||
|
||||
DisplayBoardPinController::DisplayBoardPinController(std::map<std::string, uint8_t> pins_display) :
|
||||
pins_display_board(std::move(pins_display))
|
||||
DisplayBoardPinController::DisplayBoardPinController(std::map<std::string, uint8_t> & pins_display) :
|
||||
pins_display_board{std::move(pins_display)}
|
||||
{
|
||||
initialize_pins_output(0, pins_display.begin(), pins_display.end());
|
||||
|
||||
CLOG(INFO, OUTPUT_LOGGER) << "Created DisplayBoardPinController";
|
||||
}
|
||||
|
||||
DisplayBoardPinController::DisplayBoardPinController() :
|
||||
pins_display_board{}
|
||||
{
|
||||
CLOG(INFO, OUTPUT_LOGGER) << "Created DisplayBoardPinController without pin map";
|
||||
}
|
||||
|
||||
void DisplayBoardPinController::activate_displays() const
|
||||
{
|
||||
write_pin(pins_display_board.at("run"), 1);
|
||||
@@ -77,6 +83,12 @@ void DisplayBoardPinController::run_display(uint8_t address) const
|
||||
write_pin(pins_display_board.at("display_select_" + std::to_string(address)), 1);
|
||||
}
|
||||
|
||||
void DisplayBoardPinController::set_pin_map(std::map<std::string, uint8_t> & pins_display)
|
||||
{
|
||||
this->pins_display_board.insert(pins_display.begin(), pins_display.end());
|
||||
initialize_pins_output(0, pins_display.begin(), pins_display.end());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,8 @@ namespace detail
|
||||
class DisplayBoardPinController : public output::DisplayBoardPinController
|
||||
{
|
||||
public:
|
||||
explicit DisplayBoardPinController(std::map<std::string, uint8_t> pins_display);
|
||||
explicit DisplayBoardPinController(std::map<std::string, uint8_t> & pins_display);
|
||||
explicit DisplayBoardPinController();
|
||||
~DisplayBoardPinController() override = default;
|
||||
|
||||
void activate_displays() const;
|
||||
@@ -27,6 +28,8 @@ public:
|
||||
|
||||
void write_display(const items::OutputDisplay &display) const;
|
||||
|
||||
void set_pin_map(std::map<std::string, uint8_t> & pins_display);
|
||||
|
||||
private:
|
||||
void write_display_digit(uint8_t display_address, uint8_t content, uint8_t position) const;
|
||||
void select_display_segment(uint8_t digit) const;
|
||||
@@ -34,7 +37,7 @@ private:
|
||||
void run_display(uint8_t address) const;
|
||||
|
||||
private:
|
||||
const std::map<std::string, uint8_t> pins_display_board;
|
||||
std::map<std::string, uint8_t> pins_display_board;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -18,13 +18,18 @@ namespace output
|
||||
namespace detail
|
||||
{
|
||||
|
||||
DisplayController::DisplayController(std::vector<std::shared_ptr<items::OutputDisplay>> displays,
|
||||
std::unique_ptr<DisplayBoardPinController> pin_controller
|
||||
DisplayController::DisplayController(std::map<std::string, std::shared_ptr<items::Item>> & displays,
|
||||
std::shared_ptr<DisplayBoardPinController> pin_controller
|
||||
)
|
||||
: displays(std::move(displays)), pin_controller(std::move(pin_controller)), is_running(true)
|
||||
: pin_controller{pin_controller}, is_running(true)
|
||||
{
|
||||
this->display_cycle_thread = std::thread(&DisplayController::cycle_displays, this);
|
||||
|
||||
for (auto display : displays)
|
||||
{
|
||||
this->displays.push_back(std::dynamic_pointer_cast<items::OutputDisplay>(display.second));
|
||||
}
|
||||
|
||||
CLOG(INFO, OUTPUT_LOGGER) << "Created DisplayController and started cycling them.";
|
||||
|
||||
activate_displays();
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace detail
|
||||
class DisplayController : public output::DisplayController
|
||||
{
|
||||
public:
|
||||
explicit DisplayController(std::vector<std::shared_ptr<items::OutputDisplay>> displays, std::unique_ptr<DisplayBoardPinController> pin_controller);
|
||||
explicit DisplayController(std::map<std::string, std::shared_ptr<items::Item>> &displays, std::shared_ptr<DisplayBoardPinController> pin_controller);
|
||||
~DisplayController() override;
|
||||
|
||||
void activate_displays() const override;
|
||||
@@ -35,7 +35,7 @@ private:
|
||||
void cycle_displays() const;
|
||||
|
||||
private:
|
||||
const std::vector<std::shared_ptr<items::OutputDisplay>> displays;
|
||||
std::vector<std::shared_ptr<items::OutputDisplay>> displays;
|
||||
|
||||
const std::shared_ptr<DisplayBoardPinController> pin_controller;
|
||||
|
||||
|
||||
@@ -20,9 +20,9 @@ namespace output
|
||||
|
||||
using namespace items;
|
||||
|
||||
OutputDriver::OutputDriver(std::unique_ptr<output::DisplayController> display_controller, std::map<std::string, std::shared_ptr<Solenoid>> solenoids,
|
||||
OutputDriver::OutputDriver(std::shared_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):
|
||||
std::map<std::string, std::shared_ptr<items::Flipper>> flippers, std::map<std::string, std::shared_ptr<items::Display>> displays):
|
||||
display_controller(std::move(display_controller)),
|
||||
solenoids(std::move(solenoids)),
|
||||
lamps(std::move(lamps)),
|
||||
@@ -149,7 +149,8 @@ boost::optional<std::shared_ptr<items::Flipper>> OutputDriver::get_flipper(const
|
||||
|
||||
boost::optional<std::shared_ptr<items::Display>> OutputDriver::get_display(uint8_t number) const
|
||||
{
|
||||
return this->displays.find(number)->second;
|
||||
std::string num{static_cast<char>(number)};
|
||||
return this->displays.find(num)->second;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -16,13 +16,20 @@ namespace detail
|
||||
SoundBoardPinController::SoundBoardPinController(std::shared_ptr<std::mutex> output_item_mutex,
|
||||
uint8_t fire_address,
|
||||
const std::vector<uint8_t> address_pins) :
|
||||
output_item_mutex(output_item_mutex),
|
||||
fire_address(fire_address),
|
||||
address_pins(address_pins)
|
||||
output_item_mutex{output_item_mutex},
|
||||
fire_address{fire_address},
|
||||
address_pins{address_pins}
|
||||
{
|
||||
CLOG(INFO, OUTPUT_LOGGER) << "Created SoundBoardPinController";
|
||||
}
|
||||
|
||||
|
||||
SoundBoardPinController::SoundBoardPinController(std::shared_ptr<std::mutex> output_item_mutex) :
|
||||
output_item_mutex{output_item_mutex}
|
||||
{
|
||||
CLOG(INFO, OUTPUT_LOGGER) << "Created SoundBoardPinController without addresses!";
|
||||
}
|
||||
|
||||
void SoundBoardPinController::activate(const items::detail::Sound &sound)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(*output_item_mutex);
|
||||
@@ -68,6 +75,16 @@ void SoundBoardPinController::write_pin(const uint8_t &pin, const bool &value) c
|
||||
PinController::write_pin(this->fire_address, false);
|
||||
}
|
||||
|
||||
void SoundBoardPinController::set_address_pins(std::vector<uint8_t> address_pins)
|
||||
{
|
||||
this->address_pins = address_pins;
|
||||
}
|
||||
|
||||
void SoundBoardPinController::set_fire_address(const uint8_t &fire_address)
|
||||
{
|
||||
this->fire_address = fire_address;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,12 +19,16 @@ namespace detail
|
||||
class SoundBoardPinController : public output::SoundBoardPinController
|
||||
{
|
||||
public:
|
||||
SoundBoardPinController(std::shared_ptr<std::mutex> output_item_mutex, uint8_t fire_address, const std::vector<uint8_t> address_pins);
|
||||
explicit SoundBoardPinController(std::shared_ptr<std::mutex> output_item_mutex, uint8_t fire_address, const std::vector<uint8_t> address_pins);
|
||||
explicit SoundBoardPinController(std::shared_ptr<std::mutex> output_item_mutex);
|
||||
~SoundBoardPinController() override = default;
|
||||
|
||||
void activate(const items::detail::Sound &sound);
|
||||
void deactivate(const items::detail::Sound &sound);
|
||||
|
||||
void set_fire_address(const uint8_t & fire_address);
|
||||
void set_address_pins(const std::vector<uint8_t> address_pins);
|
||||
|
||||
private:
|
||||
void write_sound_address(const uint8_t & address) const;
|
||||
void fire_sound() const;
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
|
||||
*/
|
||||
|
||||
#include <output/DisplayBoardPinController.h>
|
||||
#include "output/DisplayBoardPinController.h"
|
||||
#include "output/items/detail/EightDigitDisplay.h"
|
||||
#include "output/items/detail/SevenDigitDisplay.h"
|
||||
#include "DisplayFactory.h"
|
||||
|
||||
|
||||
@@ -17,12 +19,50 @@ namespace output
|
||||
DisplayFactory::DisplayFactory(nlohmann::json &object, std::shared_ptr<DisplayBoardPinController> pin_controller) :
|
||||
ItemFactory{object, pin_controller}
|
||||
{
|
||||
|
||||
this->create_pin_map();
|
||||
pin_controller->set_pin_map(this->pin_map);
|
||||
}
|
||||
|
||||
std::map<std::string, std::shared_ptr<items::Item>> DisplayFactory::getItemMap()
|
||||
{
|
||||
return std::map<std::string, std::shared_ptr<items::Item>>();
|
||||
std::map<std::string, std::shared_ptr<items::Item>> display_map;
|
||||
auto displays = this->object.at(config_path::display_list);
|
||||
for (auto & display : displays)
|
||||
{
|
||||
auto id = display.at(config_path::item_identifier).get<uint8_t>();
|
||||
auto address = display.at(config_path::item_address).get<uint8_t>();
|
||||
auto digits = display.at(config_path::display_digits).get<uint8_t>();
|
||||
if (digits == 8)
|
||||
display_map.emplace(std::string{static_cast<char>(id)}, std::make_shared<items::detail::EightDigitDisplay>(address, id));
|
||||
else if (digits == 7)
|
||||
display_map.emplace(std::string{static_cast<char>(id)}, std::make_shared<items::detail::SevenDigitDisplay>(address, id));
|
||||
else
|
||||
throw new std::logic_error{"Display digits can either be 7 or 8"};
|
||||
}
|
||||
return display_map;
|
||||
}
|
||||
|
||||
void DisplayFactory::create_pin_map()
|
||||
{
|
||||
nlohmann::json board_config = this->object.at(config_path::display_board);
|
||||
this->pin_map["run"] = board_config.at(config_path::run_pin);
|
||||
|
||||
nlohmann::json display_select = board_config.at(config_path::display_select);
|
||||
for(int i = 1; i < 6; i++)
|
||||
{
|
||||
this->pin_map["display_select" + std::to_string(i)] = display_select.at(std::to_string(i));
|
||||
}
|
||||
|
||||
nlohmann::json segment_select = board_config.at(config_path::display_segement_select);
|
||||
this->pin_map["segment_select_A"] = segment_select.at("A");
|
||||
this->pin_map["segment_select_B"] = segment_select.at("B");
|
||||
this->pin_map["segment_select_C"] = segment_select.at("C");
|
||||
|
||||
nlohmann::json digit_select = board_config.at(config_path::display_digit_select);
|
||||
this->pin_map["digit_select_A"] = digit_select.at("A");
|
||||
this->pin_map["digit_select_B"] = digit_select.at("B");
|
||||
this->pin_map["digit_select_C"] = digit_select.at("C");
|
||||
this->pin_map["digit_select_D"] = digit_select.at("D");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#define FLIPPR_DRIVER_DISPLAYFACTORY_H
|
||||
|
||||
#include "ItemFactory.h"
|
||||
#include "output/DisplayBoardPinController.h"
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
@@ -17,10 +18,15 @@ namespace output
|
||||
|
||||
class DisplayFactory : ItemFactory
|
||||
{
|
||||
public:
|
||||
explicit DisplayFactory(nlohmann::json & object, std::shared_ptr<DisplayBoardPinController> pin_controller);
|
||||
std::map<std::string, std::shared_ptr<items::Item>> getItemMap() override;
|
||||
public:
|
||||
|
||||
private:
|
||||
void create_pin_map();
|
||||
|
||||
private:
|
||||
std::map<std::string, uint8_t> pin_map;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -16,8 +16,11 @@ ItemFactory::ItemFactory(nlohmann::json &object, std::shared_ptr<PinController>
|
||||
pin_controller{pin_controller}
|
||||
{
|
||||
this->object = object;
|
||||
this->initialize_port_extenders();
|
||||
this->port_extenders = object.at("port_extenders");
|
||||
if (object.find(config_path::port_extenders) != object.end())
|
||||
{
|
||||
this->port_extenders = object.at(config_path::port_extenders);
|
||||
this->initialize_port_extenders();
|
||||
}
|
||||
}
|
||||
|
||||
void ItemFactory::initialize_port_extender(nlohmann::json &extender)
|
||||
@@ -29,7 +32,7 @@ void ItemFactory::initialize_port_extender(nlohmann::json &extender)
|
||||
|
||||
void ItemFactory::initialize_port_extenders()
|
||||
{
|
||||
for (auto extender : port_extenders)
|
||||
for (auto extender : this->port_extenders)
|
||||
{
|
||||
this->initialize_port_extender(extender);
|
||||
}
|
||||
|
||||
@@ -24,13 +24,25 @@ namespace config_path
|
||||
const char item_address[] = "address";
|
||||
const char item_extender[] = "extender";
|
||||
const char item_identifier[] = "id";
|
||||
const char port_extenders[] = "port_extenders";
|
||||
|
||||
const char deactivation_time[] = "deactivation_time_milliseconds";
|
||||
|
||||
const char sound_path[] = "sounds";
|
||||
const char fire_pin[] = "fire_pin";
|
||||
const char sound_address_pins[] = "address_pins";
|
||||
|
||||
const char flipper_path[] = "flippers";
|
||||
|
||||
const char solenoid_path[] = "solenoids";
|
||||
|
||||
const char display_board[] = "display_board";
|
||||
const char run_pin[] = "run";
|
||||
const char display_select[] = "display_select";
|
||||
const char display_segement_select[] = "segment_select";
|
||||
const char display_digit_select[] = "digit_select";
|
||||
const char display_digits[] = "digits";
|
||||
const char display_list[] = "displays";
|
||||
}
|
||||
|
||||
class ItemFactory
|
||||
|
||||
@@ -4,8 +4,9 @@
|
||||
* Created on: December 28, 2019
|
||||
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
|
||||
*/
|
||||
#include <output/SoundBoardPinController.h>
|
||||
|
||||
#include "SoundFactory.h"
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
@@ -19,6 +20,9 @@ SoundFactory::SoundFactory(nlohmann::json &object, std::shared_ptr<SoundBoardPin
|
||||
{
|
||||
this->deactivation_time = object.at(config_path::deactivation_time).get<uint8_t>();
|
||||
}
|
||||
|
||||
this->set_fire_pin();
|
||||
this->set_address_pins();
|
||||
}
|
||||
|
||||
std::map<std::string, std::shared_ptr<items::Item>> SoundFactory::getItemMap()
|
||||
@@ -45,5 +49,31 @@ std::map<std::string, std::shared_ptr<items::Item>> SoundFactory::getItemMap()
|
||||
return sound_map;
|
||||
}
|
||||
|
||||
void SoundFactory::set_fire_pin()
|
||||
{
|
||||
auto fire_pin = object.at(config_path::fire_pin);
|
||||
auto fire_pin_address = fire_pin.at(config_path::item_address).get<uint8_t>();
|
||||
if (fire_pin.find(config_path::item_extender) != fire_pin.end())
|
||||
{
|
||||
auto extender_name = fire_pin.at(config_path::item_extender).get<std::string>();
|
||||
fire_pin_address += this->get_extender_pin_base(extender_name);
|
||||
}
|
||||
std::dynamic_pointer_cast<detail::SoundBoardPinController>(this->pin_controller)->set_fire_address(fire_pin_address);
|
||||
}
|
||||
|
||||
void SoundFactory::set_address_pins()
|
||||
{
|
||||
auto address_pins = object.at(config_path::sound_address_pins);
|
||||
|
||||
std::vector<uint8_t> pins;
|
||||
|
||||
for (auto & pin : address_pins)
|
||||
{
|
||||
pins.push_back(pin.get<uint8_t>());
|
||||
}
|
||||
|
||||
std::dynamic_pointer_cast<detail::SoundBoardPinController>(this->pin_controller)->set_address_pins(pins);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
#include "ItemFactory.h"
|
||||
|
||||
#include "output/SoundBoardPinController.h"
|
||||
#include "output/detail/SoundBoardPinController.h"
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
@@ -23,6 +23,10 @@ public:
|
||||
explicit SoundFactory(nlohmann::json & object, std::shared_ptr<SoundBoardPinController> pin_controller);
|
||||
std::map<std::string, std::shared_ptr<items::Item>> getItemMap() override;
|
||||
|
||||
private:
|
||||
void set_fire_pin();
|
||||
void set_address_pins();
|
||||
|
||||
private:
|
||||
uint8_t deactivation_time;
|
||||
};
|
||||
|
||||
@@ -40,7 +40,7 @@ private:
|
||||
public:
|
||||
std::string content;
|
||||
|
||||
private:
|
||||
protected:
|
||||
const uint8_t id;
|
||||
const uint8_t address;
|
||||
|
||||
|
||||
@@ -24,7 +24,10 @@ class EightDigitDisplay : public items::detail::Display, public items::EightDigi
|
||||
{
|
||||
public:
|
||||
EightDigitDisplay(uint8_t address, uint8_t id) :
|
||||
detail::Display(address, id) {}
|
||||
detail::Display(address, id)
|
||||
{
|
||||
CLOG(INFO, OUTPUT_LOGGER) << "Created EightDigitDisplay with address " << int{this->address} << " and id: " << int{id};
|
||||
}
|
||||
|
||||
~EightDigitDisplay() override = default;
|
||||
|
||||
@@ -38,7 +41,10 @@ public:
|
||||
detail::Display::write_content(content, 8);
|
||||
}
|
||||
|
||||
|
||||
std::string get_name() const override
|
||||
{
|
||||
return "EightDigitDisplay " + this->id;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -35,6 +35,11 @@ public:
|
||||
|
||||
~SevenDigitDisplay() override = default;
|
||||
|
||||
std::string get_name() const override
|
||||
{
|
||||
return "EightDigitDisplay " + this->id;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Solenoid.cpp
|
||||
* Solenoid.cppthis->pins_display_board.end(),
|
||||
*
|
||||
* Created on: Aug 2, 2018
|
||||
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
|
||||
@@ -21,7 +21,7 @@ namespace detail
|
||||
Solenoid::Solenoid(std::shared_ptr<DriverBoardPinController> pin_controller, const uint8_t & address, const uint8_t & pin_base, const std::string & name, const std::chrono::milliseconds & deactivation_time)
|
||||
: detail::Item(std::move(name)), DriverBoardItem(pin_controller, address, pin_base), pin_controller(pin_controller), deactivation_time(deactivation_time)
|
||||
{
|
||||
CLOG(INFO, OUTPUT_LOGGER) << "Created solenoid " << name << " with address " << address << " and deactivation-time: " << deactivation_time.count();
|
||||
//CLOG(INFO, OUTPUT_LOGGER) << "Created solenoid " << name << " with address " << address << " and deactivation-time: " << deactivation_time.count();
|
||||
}
|
||||
|
||||
void Solenoid::triggerTask()
|
||||
|
||||
Reference in New Issue
Block a user