Lamp factory adaption
This commit is contained in:
@@ -47,14 +47,18 @@ std::shared_ptr<OutputDriver> get_OutputDriver(const std::string & solenoid_conf
|
||||
auto display_board_pin_controller = std::make_shared<detail::DisplayBoardPinController>();
|
||||
auto displays = get_items<DisplayFactory, detail::DisplayBoardPinController, items::Display>(display_config_path, display_board_pin_controller);
|
||||
|
||||
nlohmann::json display_config;
|
||||
std::ifstream(display_config_path) >> display_config;
|
||||
std::chrono::milliseconds update_frequency(1/display_config.at(config_path::display_update_frequency).get<uint>());
|
||||
auto display_controller = std::make_unique<detail::DisplayController>(displays, display_board_pin_controller, update_frequency);
|
||||
auto display_controller = std::make_unique<detail::DisplayController>(displays, display_board_pin_controller, get_update_frequency(display_config_path));
|
||||
|
||||
return std::make_shared<OutputDriver>(std::move(display_controller), solenoids, lamps, sounds, flippers, displays);
|
||||
}
|
||||
|
||||
std::chrono::seconds get_update_frequency(const std::string & display_config_path)
|
||||
{
|
||||
nlohmann::json display_config;
|
||||
std::ifstream(display_config_path) >> display_config;
|
||||
return std::chrono::seconds{1/display_config.at(config_path::display_update_frequency).get<uint>()};
|
||||
}
|
||||
|
||||
template<typename FactoryType, typename ControllerType, typename ItemType>
|
||||
std::map<std::string, std::shared_ptr<ItemType>> get_items(const std::string &config_path, std::shared_ptr<PinController> pin_controller)
|
||||
{
|
||||
|
||||
@@ -28,6 +28,8 @@ std::shared_ptr<OutputDriver> get_OutputDriver(const std::string & solenoid_conf
|
||||
const std::string & sound_config_path,
|
||||
const std::string & display_config_path);
|
||||
|
||||
std::chrono::seconds get_update_frequency(const std::string & display_config_path);
|
||||
|
||||
template<typename FactoryType, typename ControllerType, typename ItemType>
|
||||
std::map<std::string, std::shared_ptr<ItemType>> get_items(const std::string & config_path, std::shared_ptr<PinController> pin_controller);
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace config_path
|
||||
|
||||
const char sound_path[] = "sounds";
|
||||
const char fire_pin[] = "fire_pin";
|
||||
const char sound_address_pins[] = "address_pins";
|
||||
const char address_pins[] = "address_pins";
|
||||
|
||||
const char flipper_path[] = "flippers";
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#include <output/items/Lamp.h>
|
||||
#include <output/detail/DriverBoardPinController.h>
|
||||
#include "LampFactory.h"
|
||||
#include "output/items/detail/Lamp.h"
|
||||
|
||||
@@ -35,5 +36,28 @@ std::map<std::string, std::shared_ptr<items::Lamp>> LampFactory::getItemMap()
|
||||
return lamp_map;
|
||||
}
|
||||
|
||||
void LampFactory::set_address_pins()
|
||||
{
|
||||
auto address_pins = this->object.at(config_path::address_pins);
|
||||
|
||||
std::array<uint8_t, 3> pins;
|
||||
|
||||
pins.at(0) = address_pins.at("A0");
|
||||
pins.at(1) = address_pins.at("A1");
|
||||
pins.at(2) = address_pins.at("A2");
|
||||
|
||||
std::dynamic_pointer_cast<detail::DriverBoardPinController>(this->pin_controller)->set_address_pins(pins);
|
||||
}
|
||||
|
||||
uint8_t LampFactory::get_address_pin(nlohmann::json & pin_object)
|
||||
{
|
||||
auto address = pin_object.at(config_path::item_address).get<uint8_t>();
|
||||
auto extender = pin_object.at(config_path::item_extender).get<std::string>();
|
||||
auto pin_base = this->get_extender_pin_base(extender);
|
||||
|
||||
return address + pin_base;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,10 @@ class LampFactory : ItemFactory
|
||||
public:
|
||||
LampFactory(nlohmann::json & object, std::shared_ptr<DriverBoardPinController> pin_controller);
|
||||
std::map<std::string, std::shared_ptr<items::Lamp>> getItemMap();
|
||||
|
||||
private:
|
||||
void set_address_pins();
|
||||
uint8_t get_address_pin(nlohmann::json & pin_object);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -50,14 +50,16 @@ void SoundFactory::set_fire_pin()
|
||||
|
||||
void SoundFactory::set_address_pins()
|
||||
{
|
||||
auto address_pins = object.at(config_path::sound_address_pins);
|
||||
auto address_pins = object.at(config_path::address_pins);
|
||||
|
||||
std::vector<uint8_t> pins;
|
||||
|
||||
//todo mach nen array draus
|
||||
for (auto & pin_json : address_pins)
|
||||
{
|
||||
pins.push_back(0);
|
||||
}
|
||||
|
||||
for (auto & pin_json : address_pins)
|
||||
{
|
||||
uint8_t pin = pin_json.at(config_path::item_address).get<uint8_t>();
|
||||
|
||||
Reference in New Issue
Block a user