Impelements and integrates DisplayFactory. Further does some refactoring

This commit is contained in:
Johannes Wendel
2020-01-06 12:42:04 +01:00
parent 10b200e4e4
commit fda8197a26
21 changed files with 192 additions and 127 deletions

View File

@@ -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");
}
}

View File

@@ -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;
};
}

View File

@@ -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);
}

View File

@@ -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

View File

@@ -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);
}
}
}

View File

@@ -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;
};