Refactores item factories
This commit is contained in:
@@ -23,9 +23,9 @@ DisplayFactory::DisplayFactory(nlohmann::json &object, std::shared_ptr<DisplayBo
|
||||
pin_controller->set_pin_map(this->pin_map);
|
||||
}
|
||||
|
||||
std::map<std::string, std::shared_ptr<items::Item>> DisplayFactory::getItemMap()
|
||||
std::map<std::string, std::shared_ptr<items::Display>> DisplayFactory::getItemMap()
|
||||
{
|
||||
std::map<std::string, std::shared_ptr<items::Item>> display_map;
|
||||
std::map<std::string, std::shared_ptr<items::Display>> display_map;
|
||||
auto displays = this->object.at(config_path::display_list);
|
||||
for (auto & display : displays)
|
||||
{
|
||||
@@ -33,9 +33,9 @@ std::map<std::string, std::shared_ptr<items::Item>> DisplayFactory::getItemMap()
|
||||
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));
|
||||
display_map.emplace(std::string{static_cast<char>(id)}, std::dynamic_pointer_cast<items::Display>(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));
|
||||
display_map.emplace(std::string{static_cast<char>(id)}, std::dynamic_pointer_cast<items::Display>(std::make_shared<items::detail::SevenDigitDisplay>(address, id)));
|
||||
else
|
||||
throw new std::logic_error{"Display digits can either be 7 or 8"};
|
||||
}
|
||||
|
||||
@@ -20,7 +20,8 @@ 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;
|
||||
|
||||
std::map<std::string, std::shared_ptr<items::Display>> getItemMap();
|
||||
|
||||
private:
|
||||
void create_pin_map();
|
||||
|
||||
@@ -18,10 +18,10 @@ FlipperFactory::FlipperFactory(nlohmann::json &object, std::shared_ptr<DriverBoa
|
||||
ItemFactory{object, pin_controller}
|
||||
{}
|
||||
|
||||
std::map<std::string, std::shared_ptr<items::Item>> FlipperFactory::getItemMap()
|
||||
std::map<std::string, std::shared_ptr<items::Flipper>> FlipperFactory::getItemMap()
|
||||
{
|
||||
auto flippers = this->object.at(config_path::flipper_path);
|
||||
std::map<std::string, std::shared_ptr<items::Item>> flipper_map;
|
||||
std::map<std::string, std::shared_ptr<items::Flipper>> flipper_map;
|
||||
for (auto flipper : flippers)
|
||||
{
|
||||
auto name = flipper.at(config_path::item_name).get<std::string>();
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#define FLIPPR_DRIVER_FLIPPERFACTORY_H
|
||||
|
||||
#include "ItemFactory.h"
|
||||
#include "output/items/Flipper.h"
|
||||
#include <string>
|
||||
|
||||
namespace flippR_driver
|
||||
@@ -20,7 +21,7 @@ class FlipperFactory : ItemFactory
|
||||
{
|
||||
public:
|
||||
explicit FlipperFactory(nlohmann::json & object, std::shared_ptr<DriverBoardPinController> pin_controller);
|
||||
std::map <std::string, std::shared_ptr<items::Item>> getItemMap() override;
|
||||
std::map <std::string, std::shared_ptr<items::Flipper>> getItemMap();
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -36,6 +36,8 @@ namespace config_path
|
||||
|
||||
const char solenoid_path[] = "solenoids";
|
||||
|
||||
const char lamps_path[] = "lamps";
|
||||
|
||||
const char display_board[] = "display_board";
|
||||
const char run_pin[] = "run";
|
||||
const char display_select[] = "display_select";
|
||||
@@ -50,7 +52,7 @@ class ItemFactory
|
||||
public:
|
||||
ItemFactory(nlohmann::json &object, std::shared_ptr<PinController> pin_controller);
|
||||
|
||||
virtual std::map<std::string, std::shared_ptr<items::Item>> getItemMap() = 0;
|
||||
//virtual std::map<std::string, std::shared_ptr<items::Item>> getItemMap() = 0;
|
||||
|
||||
protected:
|
||||
void initialize_port_extender(nlohmann::json & extender);
|
||||
|
||||
@@ -18,15 +18,15 @@ LampFactory::LampFactory(nlohmann::json &object, std::shared_ptr<DriverBoardPinC
|
||||
ItemFactory{object, pin_controller}
|
||||
{}
|
||||
|
||||
std::map<std::string, std::shared_ptr<items::Item>> LampFactory::getItemMap()
|
||||
std::map<std::string, std::shared_ptr<items::Lamp>> LampFactory::getItemMap()
|
||||
{
|
||||
auto lamps = this->object.at("lamps");
|
||||
std::map<std::string, std::shared_ptr<items::Item>> lamp_map;
|
||||
auto lamps = this->object.at(config_path::lamps_path);
|
||||
std::map<std::string, std::shared_ptr<items::Lamp>> lamp_map;
|
||||
for (auto lamp : lamps)
|
||||
{
|
||||
auto name = lamp.at("name").get<std::string>();
|
||||
auto address = lamp.at("address").get<uint8_t >();
|
||||
auto extender = lamp.at("extender").get<std::string>();
|
||||
auto name = lamp.at(config_path::item_name).get<std::string>();
|
||||
auto address = lamp.at(config_path::item_address).get<uint8_t >();
|
||||
auto extender = lamp.at(config_path::item_extender).get<std::string>();
|
||||
auto pin_base = this->get_extender_pin_base(extender);
|
||||
auto lamp_item = std::make_shared<items::detail::Lamp>(std::static_pointer_cast<DriverBoardPinController>(this->pin_controller), address, pin_base, name);
|
||||
lamp_map.emplace(name, lamp_item);
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
#include "output/DriverBoardPinController.h"
|
||||
#include "ItemFactory.h"
|
||||
#include "output/items/Lamp.h"
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
@@ -20,7 +21,7 @@ class LampFactory : ItemFactory
|
||||
{
|
||||
public:
|
||||
explicit LampFactory(nlohmann::json & object, std::shared_ptr<DriverBoardPinController> pin_controller);
|
||||
std::map<std::string, std::shared_ptr<items::Item>> getItemMap() override;
|
||||
std::map<std::string, std::shared_ptr<items::Lamp>> getItemMap();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -22,10 +22,10 @@ SolenoidFactory::SolenoidFactory(nlohmann::json &object, std::shared_ptr<DriverB
|
||||
}
|
||||
}
|
||||
|
||||
std::map<std::string, std::shared_ptr<items::Item>> SolenoidFactory::getItemMap()
|
||||
std::map<std::string, std::shared_ptr<items::Solenoid>> SolenoidFactory::getItemMap()
|
||||
{
|
||||
auto solenoids = this->object.at(config_path::solenoid_path);
|
||||
std::map<std::string, std::shared_ptr<items::Item>> solenoid_map;
|
||||
std::map<std::string, std::shared_ptr<items::Solenoid>> solenoid_map;
|
||||
|
||||
for (auto solenoid : solenoids)
|
||||
{
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
#include "output/DriverBoardPinController.h"
|
||||
#include "ItemFactory.h"
|
||||
#include "output/items/Solenoid.h"
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
@@ -21,7 +22,7 @@ class SolenoidFactory : public ItemFactory
|
||||
public:
|
||||
explicit SolenoidFactory(nlohmann::json &object, std::shared_ptr<DriverBoardPinController> pin_controller);
|
||||
|
||||
std::map<std::string, std::shared_ptr<items::Item>> getItemMap() override;
|
||||
std::map<std::string, std::shared_ptr<items::Solenoid>> getItemMap();
|
||||
|
||||
private:
|
||||
uint8_t deactivation_time;
|
||||
|
||||
@@ -25,10 +25,10 @@ SoundFactory::SoundFactory(nlohmann::json &object, std::shared_ptr<SoundBoardPin
|
||||
this->set_address_pins();
|
||||
}
|
||||
|
||||
std::map<std::string, std::shared_ptr<items::Item>> SoundFactory::getItemMap()
|
||||
std::map<std::string, std::shared_ptr<items::Sound>> SoundFactory::getItemMap()
|
||||
{
|
||||
auto sounds = this->object.at(config_path::sound_path);
|
||||
std::map<std::string, std::shared_ptr<items::Item>> sound_map;
|
||||
std::map<std::string, std::shared_ptr<items::Sound>> sound_map;
|
||||
for (auto sound : sounds)
|
||||
{
|
||||
auto name = sound.at(config_path::item_name).get<std::string>();
|
||||
|
||||
@@ -21,7 +21,7 @@ class SoundFactory : ItemFactory
|
||||
{
|
||||
public:
|
||||
explicit SoundFactory(nlohmann::json & object, std::shared_ptr<SoundBoardPinController> pin_controller);
|
||||
std::map<std::string, std::shared_ptr<items::Item>> getItemMap() override;
|
||||
std::map<std::string, std::shared_ptr<items::Sound>> getItemMap();
|
||||
|
||||
private:
|
||||
void set_fire_pin();
|
||||
|
||||
Reference in New Issue
Block a user