This commit is contained in:
Jonas Zeunert
2018-12-10 23:04:44 +01:00
parent 5e0687f7c6
commit d65d87b8f1
15 changed files with 101 additions and 47 deletions

View File

@@ -16,10 +16,21 @@ namespace
using namespace nlohmann;
std::shared_ptr<OutputGPIOInterface> createOutputGPIOInterface(std::istream &output_gpio_config)
std::shared_ptr<IOutputDriver> get_OutputDriver(std::istream &output_pin_config, std::istream &solenoid_config, std::istream &lamp_config, std::istream &sound_config)
{
auto output_gpio_interface = create_OutputGPIOInterface(output_pin_config);
auto solenoids = create_solenoids(solenoid_config, output_gpio_interface);
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);
}
std::shared_ptr<OutputGPIOInterface> create_OutputGPIOInterface(std::istream &output_pin_config)
{
json output_config;
output_gpio_config >> output_config;
output_pin_config >> output_config;
return std::make_shared<OutputGPIOInterface>(
parse_pins_driver_board(output_config.at("driver_board")),
@@ -77,8 +88,54 @@ 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, items::ISolenoid> solenoids;
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, items::ILamp> lamps;
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>> sounds;
json sounds_json;
sound_config >> sounds_json;
for(auto &sound_json : sounds_json)
{
auto sound = create_sound(sound_json);
sounds.emplace(sound->get_name(), sound);
}
return sounds;
}
std::shared_ptr<items::ISolenoid> create_solenoid(nlohmann::json &solenoid_json, std::shared_ptr<IOutputGPIOInterface> output_gpio_interface)
{
return std::shared_ptr<items::ISolenoid>();
}
std::shared_ptr<items::Sound> create_sound(nlohmann::json &sound_json, std::shared_ptr<IOutputGPIOInterface> &output_gpio_interface, std::chrono::milliseconds deactivation_time)
{
try
{
uint id = sound_json.at("id").get<uint>();
std::string name = sound_json.at("name");
uint8_t address = sound_json.at("address").get<uint8_t>();
return std::make_shared<items::Sound>(output_gpio_interface, address, name, deactivation_time, id);
}
catch(json::type_error &e)
{
// todo log and exit
}
}
}
}
}
}