added display pins

This commit is contained in:
Jonas Zeunert
2018-12-19 22:49:54 +01:00
parent 95b1ac85b8
commit 423fb50096
2 changed files with 71 additions and 11 deletions

View File

@@ -7,7 +7,7 @@
"2" : 0,
"3" : 0,
"4" : 0,
"5" : 0,
"5" : 0
},
"segment_select" :
{

View File

@@ -122,7 +122,23 @@ std::map<std::string, uint8_t> 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<uint8_t>();
}
json segment_select = display_board_config.at("segment_select");
pins_display["segment_select_A"] = segment_select.at("A").get<uint8_t>();
pins_display["segment_select_B"] = segment_select.at("B").get<uint8_t>();
pins_display["segment_select_C"] = segment_select.at("C").get<uint8_t>();
json digit_select = display_board_config.at("digit_select");
pins_display["digit_select_A"] = digit_select.at("A").get<uint8_t>();
pins_display["digit_select_B"] = digit_select.at("B").get<uint8_t>();
pins_display["digit_select_C"] = digit_select.at("C").get<uint8_t>();
pins_display["digit_select_D"] = digit_select.at("D").get<uint8_t>();
}
catch(json::exception &e)
{
@@ -142,7 +158,18 @@ std::map<std::string, std::shared_ptr<items::Solenoid>> 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<std::string, std::shared_ptr<items::Lamp>> 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<std::string, std::shared_ptr<items::Sound>> 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<items::detail::Solenoid> 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<items::detail::Lamp> 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<items::detail::Sound> 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<std::shared_ptr<items::OutputDisplay>> 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<items::OutputDisplay> 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);
}
}