From 423fb500969196eaafedecf7c4a97aa339a63b63 Mon Sep 17 00:00:00 2001 From: Jonas Zeunert Date: Wed, 19 Dec 2018 22:49:54 +0100 Subject: [PATCH] added display pins --- .../output/Output_Pin_Config.json | 2 +- .../src/output/OutputDriverFactory.cpp | 80 ++++++++++++++++--- 2 files changed, 71 insertions(+), 11 deletions(-) diff --git a/FlippR-Driver/contrib/json_example/output/Output_Pin_Config.json b/FlippR-Driver/contrib/json_example/output/Output_Pin_Config.json index e6b4a07..697e403 100644 --- a/FlippR-Driver/contrib/json_example/output/Output_Pin_Config.json +++ b/FlippR-Driver/contrib/json_example/output/Output_Pin_Config.json @@ -7,7 +7,7 @@ "2" : 0, "3" : 0, "4" : 0, - "5" : 0, + "5" : 0 }, "segment_select" : { diff --git a/FlippR-Driver/src/output/OutputDriverFactory.cpp b/FlippR-Driver/src/output/OutputDriverFactory.cpp index e991f2a..6ac253c 100644 --- a/FlippR-Driver/src/output/OutputDriverFactory.cpp +++ b/FlippR-Driver/src/output/OutputDriverFactory.cpp @@ -122,7 +122,23 @@ std::map parse_pins_display_board(json &display_board_conf try { pins_display["run"] = display_board_config.at("run"); - //todo + + json display_select = display_board_config.at("display_select"); + for(json::iterator it = display_select.begin(); it != display_select.end(); it++) + { + pins_display["display_select" + it.key()] = it.value().get(); + } + + json segment_select = display_board_config.at("segment_select"); + pins_display["segment_select_A"] = segment_select.at("A").get(); + pins_display["segment_select_B"] = segment_select.at("B").get(); + pins_display["segment_select_C"] = segment_select.at("C").get(); + + json digit_select = display_board_config.at("digit_select"); + pins_display["digit_select_A"] = digit_select.at("A").get(); + pins_display["digit_select_B"] = digit_select.at("B").get(); + pins_display["digit_select_C"] = digit_select.at("C").get(); + pins_display["digit_select_D"] = digit_select.at("D").get(); } catch(json::exception &e) { @@ -142,7 +158,18 @@ std::map> create_solenoids(std::is auto deactivation_time = get_deactivation_time(solenoid_config_json); - json solenoids_json = solenoid_config_json.at("solenoids"); + json solenoids_json; + + try + { + solenoids_json = solenoid_config_json.at("solenoids"); + } + catch(json::exception &e) + { + CLOG(ERROR, OUTPUT_LOGGER) << "Output solenoids config file corrupted: Key \"solenoids\" of type array needed. \n" << e.what(); + exit(EXIT_FAILURE); + } + for(auto &solenoid_json : solenoids_json) { auto solenoid = create_solenoid(solenoid_json, output_gpio_interface, deactivation_time); @@ -159,7 +186,18 @@ std::map> create_lamps(std::istream &l json lamp_config_json; lamp_config >> lamp_config_json; - json lamps_json = lamp_config_json.at("lamps"); + json lamps_json; + + try + { + lamps_json = lamp_config_json.at("lamps"); + } + catch(json::exception &e) + { + CLOG(ERROR, OUTPUT_LOGGER) << "Output lamp config file corrupted: Key \"lamps\" of type array needed. \n" << e.what(); + exit(EXIT_FAILURE); + } + for(auto &lamp_json : lamps_json) { auto lamp = create_lamp(lamp_json, output_gpio_interface); @@ -178,7 +216,18 @@ std::map> create_sounds(std::istream auto deactivation_time = get_deactivation_time(sounds_config_json); - json sounds_json = sounds_config_json.at("sounds"); // todo catch + json sounds_json; + + try + { + sounds_json = sounds_config_json.at("sounds"); + } + catch(json::exception &e) + { + CLOG(ERROR, OUTPUT_LOGGER) << "Output sound config file corrupted: Key \"sounds\" of type array needed. \n" << e.what(); + exit(EXIT_FAILURE); + } + for(auto &sound_json : sounds_json) { auto sound = create_sound(sound_json, output_gpio_interface, deactivation_time); @@ -197,7 +246,7 @@ std::chrono::milliseconds get_deactivation_time(nlohmann::json &json) } catch(json::exception &e) { - // todo log and exit + CLOG(ERROR, OUTPUT_LOGGER) << "Output config file at deactivation_time_milliseconds corrupted: " << e.what(); exit(EXIT_FAILURE); } } @@ -218,7 +267,7 @@ std::shared_ptr create_solenoid(nlohmann::json &solenoi } catch(json::exception &e) { - // todo log and exit + CLOG(ERROR, OUTPUT_LOGGER) << "Output solenoid config file corrupted: " << e.what(); exit(EXIT_FAILURE); } } @@ -233,7 +282,7 @@ std::shared_ptr create_lamp(nlohmann::json &lamp_json, std: } catch(json::exception &e) { - // todo log and exit + CLOG(ERROR, OUTPUT_LOGGER) << "Output lamp config file corrupted: " << e.what(); exit(EXIT_FAILURE); } } @@ -249,7 +298,7 @@ std::shared_ptr create_sound(nlohmann::json &sound_json, s } catch(json::exception &e) { - // todo log and exit + CLOG(ERROR, OUTPUT_LOGGER) << "Output sound config file corrupted: " << e.what(); exit(EXIT_FAILURE); } } @@ -261,7 +310,18 @@ std::vector> create_displays(std::istream json display_config_json; display_config >> display_config_json; - json displays_json = display_config_json.at("displays"); + json displays_json; + + try + { + displays_json = display_config_json.at("displays"); + } + catch(json::exception &e) + { + CLOG(ERROR, OUTPUT_LOGGER) << "Output display config file corrupted: Key \"displays\" of type array needed. \n" << e.what(); + exit(EXIT_FAILURE); + } + for(json &display_json : displays_json) { auto display = create_display(display_json); @@ -294,7 +354,7 @@ std::shared_ptr create_display(nlohmann::json &display_jso } catch(json::exception &e) { - // todo log + CLOG(ERROR, OUTPUT_LOGGER) << "Output display config file corrupted: " << e.what(); exit(EXIT_FAILURE); } }