This commit is contained in:
Jonas Zeunert
2019-08-15 22:17:09 +02:00
7 changed files with 149 additions and 134 deletions

View File

@@ -8,7 +8,6 @@
#include "PinController.h"
#include "utility/config.h"
#ifndef NO_WIRING_PI
#include <wiringPi.h>
#include <mcp23017.h>

View File

@@ -53,6 +53,7 @@ std::shared_ptr<OutputDriver> get_OutputDriver(std::istream& solenoid_config,
std::map<std::string, std::shared_ptr<items::Solenoid>> create_solenoids(std::istream & solenoid_config, std::shared_ptr<DriverBoardPinController> &pin_controller)
{
solenoid_config.clear();
json solenoid_config_json;
solenoid_config >> solenoid_config_json;
@@ -74,6 +75,7 @@ std::map<std::string, std::shared_ptr<items::Solenoid>> create_solenoids(std::is
std::shared_ptr<items::detail::Solenoid> create_solenoid(nlohmann::json &solenoid_json, nlohmann::json &port_extenders, std::shared_ptr<DriverBoardPinController> &pin_controller, std::chrono::milliseconds deactivation_time)
{
solenoid_json;
std::string config_file_name = "solenoid_config.json";
uint8_t pin_base = get_pin_base(solenoid_json, port_extenders, config_file_name);
@@ -81,16 +83,18 @@ std::shared_ptr<items::detail::Solenoid> create_solenoid(nlohmann::json &solenoi
auto name = get_value<std::string>("name", solenoid_json, config_file_name);
auto address = get_value<uint8_t>("address", solenoid_json, config_file_name);
if(solenoid_json.find("deactivation_time_milliseconds") != solenoid_json.end())
{
deactivation_time = std::chrono::milliseconds(get_value<uint8_t>("deactivation_time_milliseconds", solenoid_json, config_file_name));
}
if(solenoid_json.find("deactivation_time_milliseconds") != solenoid_json.end())
{
deactivation_time = std::chrono::milliseconds(get_value<uint8_t>("deactivation_time_milliseconds", solenoid_json, config_file_name));
}
return std::make_shared<items::detail::Solenoid>(pin_controller, address, pin_base, name, deactivation_time);
}
std::map<std::string, std::shared_ptr<items::Flipper>> create_flippers(std::istream &solenoid_config, std::shared_ptr<DriverBoardPinController> &pin_controller)
{
solenoid_config.clear();
solenoid_config.seekg(0, std::ios::beg);
json solenoid_config_json;
solenoid_config >> solenoid_config_json;
@@ -121,6 +125,8 @@ std::shared_ptr<items::detail::Flipper> create_flipper(nlohmann::json &flipper_j
std::map<std::string, std::shared_ptr<items::Lamp>> create_lamps(std::istream &lamp_config, std::shared_ptr<DriverBoardPinController> &pin_controller)
{
lamp_config.clear();
lamp_config.seekg(0, std::ios::beg);
json lamp_config_json;
lamp_config >> lamp_config_json;
@@ -152,6 +158,8 @@ std::shared_ptr<items::detail::Lamp> create_lamp(json &lamp_json, json & port_ex
std::map<std::string, std::shared_ptr<items::Sound>> create_sounds(std::istream &sound_config, std::shared_ptr<SoundBoardPinController> &pin_controller)
{
sound_config.clear();
sound_config.seekg(0, std::ios::beg);
json sound_config_json;
sound_config >> sound_config_json;
@@ -161,13 +169,13 @@ std::map<std::string, std::shared_ptr<items::Sound>> create_sounds(std::istream
std::chrono::milliseconds deactivation_time{ get_value<int>("deactivation_time_milliseconds", sound_config_json, "solenoid_config.json") };
json solenoids_json = get_element("sounds", sound_config_json, "sound_config.json");
json sounds_json = get_element("sounds", sound_config_json, "sound_config.json");
std::map<std::string, std::shared_ptr<items::Sound>> sounds;
for(auto &solenoid_json : solenoids_json)
for(auto &sound_json : sounds_json)
{
auto solenoid = create_sound(solenoid_json, port_extenders, pin_controller, deactivation_time);
sounds.emplace(solenoid->get_name(), solenoid);
auto sound = create_sound(sound_json, port_extenders, pin_controller, deactivation_time);
sounds.emplace(sound->get_name(), sound);
}
return sounds;
}
@@ -186,6 +194,8 @@ std::shared_ptr<items::detail::Sound> create_sound(json &sound_json, json &port_
uint8_t get_sound_fire_address(std::istream &sound_config)
{
sound_config.clear();
sound_config.seekg(0, std::ios::beg);
json sound_config_json;
sound_config >> sound_config_json;
@@ -200,6 +210,8 @@ uint8_t get_sound_fire_address(std::istream &sound_config)
std::map<std::string, uint8_t> parse_pins_display_board(std::istream &display_config)
{
display_config.clear();
display_config.seekg(0, std::ios::beg);
std::string config_file = "display_config.json";
json display_config_json;
@@ -233,7 +245,8 @@ std::map<std::string, uint8_t> parse_pins_display_board(std::istream &display_co
std::vector<std::shared_ptr<items::OutputDisplay>> create_displays(std::istream &display_config)
{
display_config.clear();
display_config.seekg(0, std::ios::beg);
json display_config_json;
display_config >> display_config_json;
@@ -279,7 +292,6 @@ std::map<uint8_t, std::shared_ptr<items::Display>> map_displays(const std::vecto
void initialize_port_extenders(json &port_extenders, PinController * pin_controller, const std::string & file_name)
{
for (auto & extender_json : port_extenders)
{
auto i2c_address = get_value<uint8_t>("i2c_address", extender_json, file_name);
@@ -334,7 +346,7 @@ type get_value(const std::string & name, json & object, const std::string & file
}
catch(json::exception &e)
{
CLOG(ERROR, OUTPUT_LOGGER) << "File " << file_name << " seems to be corrupted at " << name << ": " << e.what();
/*CLOG(ERROR, OUTPUT_LOGGER)*/ std::cerr << "File " << file_name << " seems to be corrupted at " << name << ": " << e.what();
exit(EXIT_FAILURE);
}
return element;