Fixes initialization bug regarding port extenders
This commit is contained in:
@@ -54,7 +54,6 @@ void PinController::initialize_port_expander(const uint8_t i2c_address, const ui
|
||||
char hex_string[4];
|
||||
sprintf(hex_string, "%X", i2c_address);
|
||||
CLOG(INFO, OUTPUT_LOGGER) << "MCP23017 initialized with i2c-address 0x" << hex_string << " and pin-base " << int(pin_base);
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -131,9 +131,7 @@ std::map<std::string, std::shared_ptr<items::Lamp>> create_lamps(std::istream &l
|
||||
lamp_config >> lamp_config_json;
|
||||
|
||||
json port_extenders = get_element("port_extenders", lamp_config_json, "lamp_config.json");
|
||||
|
||||
initialize_port_extenders(port_extenders, pin_controller.get(), "lamp_config.json");
|
||||
|
||||
json solenoids_json = get_element("lamps", lamp_config_json, "lamp_config.json");
|
||||
|
||||
std::map<std::string, std::shared_ptr<items::Lamp>> lamps;
|
||||
@@ -164,11 +162,8 @@ std::map<std::string, std::shared_ptr<items::Sound>> create_sounds(std::istream
|
||||
sound_config >> sound_config_json;
|
||||
|
||||
json port_extenders = get_element("port_extenders", sound_config_json, "sound_config.json");
|
||||
|
||||
initialize_port_extenders(port_extenders, pin_controller.get(), "sound_config.json");
|
||||
|
||||
std::chrono::milliseconds deactivation_time{ get_value<int>("deactivation_time_milliseconds", sound_config_json, "solenoid_config.json") };
|
||||
|
||||
json sounds_json = get_element("sounds", sound_config_json, "sound_config.json");
|
||||
|
||||
std::map<std::string, std::shared_ptr<items::Sound>> sounds;
|
||||
@@ -302,8 +297,6 @@ void initialize_port_extenders(json &port_extenders, PinController * pin_control
|
||||
|
||||
uint8_t get_pin_base(json & object, json & port_extenders, const std::string & config_file_name)
|
||||
{
|
||||
uint8_t pin_base{ 0 };
|
||||
|
||||
if(object.find("extender") != object.end())
|
||||
{
|
||||
auto extender_name = get_value<std::string>("extender", object, config_file_name);
|
||||
@@ -312,11 +305,20 @@ uint8_t get_pin_base(json & object, json & port_extenders, const std::string & c
|
||||
auto actual_extender = get_value<std::string>("name", extender, config_file_name);
|
||||
if (actual_extender == extender_name)
|
||||
{
|
||||
pin_base = get_value<uint8_t>("pin_base", extender, config_file_name);
|
||||
try
|
||||
{
|
||||
return extender.at("pin_base").get<uint8_t >();
|
||||
}
|
||||
catch(json::exception &e)
|
||||
{
|
||||
CLOG(INFO, OUTPUT_LOGGER) << "pin_base not set for " << extender_name << " in " << config_file_name;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return pin_base;
|
||||
}
|
||||
CLOG(INFO, OUTPUT_LOGGER) << "Extender not set for " << object << " in " << config_file_name;
|
||||
return 0;
|
||||
}
|
||||
|
||||
json get_element(const std::string & name, json & object, const std::string & file_name)
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace detail
|
||||
Flipper::Flipper(std::shared_ptr<DriverBoardPinController> pin_controller, const uint8_t & address, const uint8_t & pin_base, const std::string & name) :
|
||||
Item(std::move(name)), DriverBoardItem(pin_controller, address, pin_base), pin_controller(std::move(pin_controller))
|
||||
{
|
||||
// CLOG(INFO, OUTPUT_LOGGER) << "Created Flipper relay " << this->name << " with address " << this->address;
|
||||
//CLOG(INFO , OUTPUT_LOGGER) << "Created flipper \"" << name << "\" with pin-base " << int(pin_base) << " and address " << int(address);
|
||||
}
|
||||
|
||||
Flipper::~Flipper()
|
||||
|
||||
@@ -26,7 +26,7 @@ Lamp::Lamp(std::shared_ptr<DriverBoardPinController> pin_controller, const uint8
|
||||
activated(false),
|
||||
activation_time(10)
|
||||
{
|
||||
// CLOG(INFO, OUTPUT_LOGGER) << "Created lamp " << name << " with address " << address;
|
||||
//CLOG(INFO , OUTPUT_LOGGER) << "Created lamp \"" << name << "\" with pin-base " << int(pin_base) << " and address " << int(address);
|
||||
}
|
||||
|
||||
void Lamp::activate()
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace detail
|
||||
Sound::Sound(std::shared_ptr<SoundBoardPinController> pin_controller, const uint8_t & address, const uint8_t & pin_base, const std::string & name, const std::chrono::milliseconds & deactivation_time, const u_int id)
|
||||
: detail::Item(std::move(name)), DriverBoardItem(pin_controller, address, pin_base), pin_controller(std::move(pin_controller)), deactivation_time(deactivation_time), id(id)
|
||||
{
|
||||
// CLOG(INFO, OUTPUT_LOGGER) << "Created sound " << id << " with name " << name << " and address " << address;
|
||||
//CLOG(INFO , OUTPUT_LOGGER) << "Created sound \"" << name << "\" with pin-base " << int(pin_base) << " and address " << int(address);
|
||||
}
|
||||
|
||||
void Sound::play()
|
||||
|
||||
Reference in New Issue
Block a user