factoryyyyyN
This commit is contained in:
@@ -4,6 +4,9 @@
|
||||
|
||||
#include "OutputDriverFactory.h"
|
||||
|
||||
#include "OutputDriver.h"
|
||||
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
@@ -16,7 +19,7 @@ namespace
|
||||
|
||||
using namespace nlohmann;
|
||||
|
||||
std::shared_ptr<IOutputDriver> get_OutputDriver(std::istream &output_pin_config, std::istream &solenoid_config, std::istream &lamp_config, std::istream &sound_config)
|
||||
std::shared_ptr<IOutputDriver> get_OutputDriver(std::istream &output_pin_config, std::istream &solenoid_config, std::istream &lamp_config, std::istream &sound_config, std::istream &display_config)
|
||||
{
|
||||
auto output_gpio_interface = create_OutputGPIOInterface(output_pin_config);
|
||||
|
||||
@@ -24,7 +27,9 @@ std::shared_ptr<IOutputDriver> get_OutputDriver(std::istream &output_pin_config,
|
||||
auto lamps = create_lamps(lamp_config, output_gpio_interface);
|
||||
auto sounds = create_sounds(sound_config, output_gpio_interface);
|
||||
|
||||
return std::make_shared<IOutputDriver>(solenoids, lamps, sounds);
|
||||
auto displays = create_displays(display_config, output_gpio_interface);
|
||||
|
||||
return std::make_shared<OutputDriver>(solenoids, lamps, sounds, displays);
|
||||
}
|
||||
|
||||
std::shared_ptr<OutputGPIOInterface> create_OutputGPIOInterface(std::istream &output_pin_config)
|
||||
@@ -88,39 +93,85 @@ std::map<std::string, uint8_t> parse_pins_display(json &display_board_config)
|
||||
return std::map<std::string, uint8_t>();
|
||||
}
|
||||
|
||||
std::map<std::string, std::shared_ptr<items::ISolenoid>> create_solenoids(std::istream &solenoid_config, std::shared_ptr<IOutputGPIOInterface> output_gpio_interface)
|
||||
std::map<std::string, std::shared_ptr<items::ISolenoid>> create_solenoids(std::istream &solenoid_config, std::shared_ptr<OutputGPIOInterface> output_gpio_interface)
|
||||
{
|
||||
std::map<std::string, items::ISolenoid> solenoids;
|
||||
std::map<std::string, std::shared_ptr<items::ISolenoid>> solenoids;
|
||||
|
||||
json solenoids_json;
|
||||
solenoid_config >> solenoids_json;
|
||||
|
||||
auto deactivation_time = get_deactivation_time(solenoids_json);
|
||||
|
||||
for(auto &solenoid_json : solenoids_json)
|
||||
{
|
||||
auto solenoid = create_solenoid(solenoid_json, output_gpio_interface, deactivation_time);
|
||||
solenoids.emplace(solenoid->Item::get_name(), solenoid_json);
|
||||
}
|
||||
return solenoids;
|
||||
}
|
||||
|
||||
std::map<std::string, std::shared_ptr<items::ILamp>> create_lamps(std::istream &lamp_config, std::shared_ptr<IOutputGPIOInterface> output_gpio_interface)
|
||||
std::map<std::string, std::shared_ptr<items::ILamp>> create_lamps(std::istream &lamp_config, std::shared_ptr<OutputGPIOInterface> output_gpio_interface)
|
||||
{
|
||||
std::map<std::string, items::ILamp> lamps;
|
||||
std::map<std::string, std::shared_ptr<items::ILamp>> lamps;
|
||||
|
||||
json lamps_json;
|
||||
lamp_config >> lamps_json;
|
||||
|
||||
for(auto &lamp_json : lamps_json)
|
||||
{
|
||||
auto lamp = create_lamp(lamp_json, output_gpio_interface);
|
||||
lamps.emplace(lamp->Item::get_name(), lamp);
|
||||
}
|
||||
|
||||
return lamps;
|
||||
}
|
||||
|
||||
std::map<std::string, std::shared_ptr<items::ISound>> create_sounds(std::istream &sound_config, std::shared_ptr<IOutputGPIOInterface> output_gpio_interface)
|
||||
std::map<std::string, std::shared_ptr<items::ISound>> create_sounds(std::istream &sound_config, std::shared_ptr<OutputGPIOInterface> output_gpio_interface)
|
||||
{
|
||||
std::map<std::string, std::shared_ptr<items::ISound>> sounds;
|
||||
|
||||
json sounds_json;
|
||||
sound_config >> sounds_json;
|
||||
|
||||
auto deactivation_time = get_deactivation_time(sounds_json);
|
||||
|
||||
for(auto &sound_json : sounds_json)
|
||||
{
|
||||
auto sound = create_sound(sound_json);
|
||||
sounds.emplace(sound->get_name(), sound);
|
||||
auto sound = create_sound(sound_json, output_gpio_interface, deactivation_time);
|
||||
sounds.emplace(sound->Item::get_name(), sound);
|
||||
}
|
||||
|
||||
return sounds;
|
||||
}
|
||||
std::shared_ptr<items::ISolenoid> create_solenoid(nlohmann::json &solenoid_json, std::shared_ptr<IOutputGPIOInterface> output_gpio_interface)
|
||||
|
||||
std::chrono::milliseconds get_deactivation_time(nlohmann::json &json)
|
||||
{
|
||||
return std::shared_ptr<items::ISolenoid>();
|
||||
try
|
||||
{
|
||||
uint deactivation_time = json.at("deactivation_time_milliseconds").get<uint>();
|
||||
return std::chrono::milliseconds(deactivation_time);
|
||||
}
|
||||
catch(json::type_error &e)
|
||||
{
|
||||
// todo log and exit
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<items::Sound> create_sound(nlohmann::json &sound_json, std::shared_ptr<IOutputGPIOInterface> &output_gpio_interface, std::chrono::milliseconds deactivation_time)
|
||||
std::shared_ptr<items::Solenoid> create_solenoid(nlohmann::json &solenoid_json, std::shared_ptr<OutputGPIOInterface> output_gpio_interface, std::chrono::milliseconds deactivation_time)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string name = solenoid_json.at("name");
|
||||
uint8_t address = solenoid_json.at("address").get<uint8_t>();
|
||||
return std::make_shared<items::Solenoid>(output_gpio_interface, address, name, deactivation_time);
|
||||
}
|
||||
catch(json::type_error &e)
|
||||
{
|
||||
// todo log and exit
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<items::Sound> create_sound(nlohmann::json &sound_json, std::shared_ptr<OutputGPIOInterface> &output_gpio_interface, std::chrono::milliseconds deactivation_time)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user