enough for today

This commit is contained in:
Jonas Zeunert
2018-12-11 00:03:48 +01:00
parent 6367e79898
commit b0d649018e
9 changed files with 29 additions and 31 deletions

View File

@@ -21,7 +21,7 @@ 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::istream &display_config)
{
auto output_gpio_interface = create_OutputGPIOInterface(output_pin_config);
std::shared_ptr<IOutputGPIOInterface> output_gpio_interface = std::shared_ptr<IOutputGPIOInterface>(create_OutputGPIOInterface(output_pin_config));
auto solenoids = create_solenoids(solenoid_config, output_gpio_interface);
auto lamps = create_lamps(lamp_config, output_gpio_interface);
@@ -32,16 +32,14 @@ std::shared_ptr<IOutputDriver> get_OutputDriver(std::istream &output_pin_config,
return std::make_shared<OutputDriver>(solenoids, lamps, sounds, displays);
}
std::shared_ptr<OutputGPIOInterface> create_OutputGPIOInterface(std::istream &output_pin_config)
IOutputGPIOInterface* create_OutputGPIOInterface(std::istream &output_pin_config)
{
json output_config;
output_pin_config >> output_config;
return std::make_shared<OutputGPIOInterface>(
parse_pins_driver_board(output_config.at("driver_board")),
return new OutputGPIOInterface(parse_pins_driver_board(output_config.at("driver_board")),
parse_pins_sound(output_config.at("sound_board")),
parse_pins_sound(output_config.at("display_board"))
);
parse_pins_sound(output_config.at("display_board")));
}
std::map<std::string, uint8_t> parse_pins_driver_board(json &driver_board_config)
@@ -93,7 +91,7 @@ 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<OutputGPIOInterface> output_gpio_interface)
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>> solenoids;
@@ -105,12 +103,12 @@ std::map<std::string, std::shared_ptr<items::ISolenoid>> create_solenoids(std::i
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);
solenoids.emplace(solenoid->get_name(), solenoid);
}
return solenoids;
}
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, 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>> lamps;
@@ -120,13 +118,13 @@ std::map<std::string, std::shared_ptr<items::ILamp>> create_lamps(std::istream &
for(auto &lamp_json : lamps_json)
{
auto lamp = create_lamp(lamp_json, output_gpio_interface);
lamps.emplace(lamp->Item::get_name(), lamp);
lamps.emplace(lamp->get_name(), lamp);
}
return lamps;
}
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>> create_sounds(std::istream &sound_config, std::shared_ptr<IOutputGPIOInterface> output_gpio_interface)
{
std::map<std::string, std::shared_ptr<items::ISound>> sounds;
@@ -138,7 +136,7 @@ std::map<std::string, std::shared_ptr<items::ISound>> create_sounds(std::istream
for(auto &sound_json : sounds_json)
{
auto sound = create_sound(sound_json, output_gpio_interface, deactivation_time);
sounds.emplace(sound->Item::get_name(), sound);
sounds.emplace(sound->get_name(), sound);
}
return sounds;
@@ -157,7 +155,7 @@ std::chrono::milliseconds get_deactivation_time(nlohmann::json &json)
}
}
std::shared_ptr<items::Solenoid> create_solenoid(nlohmann::json &solenoid_json, std::shared_ptr<OutputGPIOInterface> output_gpio_interface, std::chrono::milliseconds deactivation_time)
std::shared_ptr<items::Solenoid> create_solenoid(nlohmann::json &solenoid_json, std::shared_ptr<IOutputGPIOInterface> output_gpio_interface, std::chrono::milliseconds deactivation_time)
{
try
{
@@ -171,7 +169,7 @@ std::shared_ptr<items::Solenoid> create_solenoid(nlohmann::json &solenoid_json,
}
}
std::shared_ptr<items::Sound> create_sound(nlohmann::json &sound_json, std::shared_ptr<OutputGPIOInterface> &output_gpio_interface, std::chrono::milliseconds deactivation_time)
std::shared_ptr<items::Sound> create_sound(nlohmann::json &sound_json, std::shared_ptr<IOutputGPIOInterface> &output_gpio_interface, std::chrono::milliseconds deactivation_time)
{
try
{