Fixes some issues with sounds and the appropriate factory. Further moved the calculation of pin addresses with pin base into the factories

This commit is contained in:
Johannes Wendel
2020-01-07 00:47:59 +01:00
parent 4b76b477f5
commit f5e2b1d0cd
18 changed files with 145 additions and 141 deletions

View File

@@ -3,8 +3,8 @@
"port_extenders" :
[
{
"name" : "extender_0",
"i2c_address" : 34,
"name" : "extender_0",
"pin_base" : 81
}
],
@@ -13,339 +13,321 @@
"address" : 13,
"extender" : "extender_0"
},
"address_pins" : [ 15, 14, 12, 10, 8, 9, 11 ],
"address_pins" :
[
{
"id" : 0,
"address" : 15,
"extender" : "extender_0"
},
{
"id" : 1,
"address" : 14,
"extender" : "extender_0"
},
{
"id" : 2,
"address" : 12,
"extender" : "extender_0"
},
{
"id" : 3,
"address" : 10,
"extender" : "extender_0"
},
{
"id" : 4,
"address" : 8,
"extender" : "extender_0"
},
{
"id" : 5,
"address" : 9,
"extender" : "extender_0"
},
{
"id" : 6,
"address" : 11,
"extender" : "extender_0"
}
],
"sounds" :
[
{
"id" : 0,
"address" : 22,
"name" : "Sound 1",
"extender" : "extender_0",
"deactivation_time_milliseconds" : 10
},
{
"id" : 1,
"address" : 23,
"name" : "Sound 2",
"extender" : "extender_0"
"name" : "Sound 2"
},
{
"id" : 2,
"address" : 24,
"name" : "Sound 3",
"extender" : "extender_0"
"name" : "Sound 3"
},
{
"id" : 3,
"address" : 25,
"name" : "Sound 4",
"extender" : "extender_0"
"name" : "Sound 4"
},
{
"id" : 4,
"address" : 26,
"name" : "Sound 5",
"extender" : "extender_0"
"name" : "Sound 5"
},
{
"id" : 5,
"address" : 27,
"name" : "Sound 6",
"extender" : "extender_0"
"name" : "Sound 6"
},
{
"id" : 6,
"address" : 28,
"name" : "Sound 7",
"extender" : "extender_0"
"name" : "Sound 7"
},
{
"id" : 7,
"address" : 29,
"name" : "Sound 8",
"extender" : "extender_0"
"name" : "Sound 8"
},
{
"id" : 8,
"address" : 30,
"name" : "Sound 9",
"extender" : "extender_0"
"name" : "Sound 9"
},
{
"id" : 9,
"address" : 31,
"name" : "Sound 10",
"extender" : "extender_0"
"name" : "Sound 10"
},
{
"id" : 10,
"address" : 32,
"name" : "Sound 11",
"extender" : "extender_0"
"name" : "Sound 11"
},
{
"id" : 11,
"address" : 33,
"name" : "Sound 12",
"extender" : "extender_0"
"name" : "Sound 12"
},
{
"id" : 12,
"address" : 34,
"name" : "Sound 13",
"extender" : "extender_0"
"name" : "Sound 13"
},
{
"id" : 13,
"address" : 35,
"name" : "Sound 14",
"extender" : "extender_0"
"name" : "Sound 14"
},
{
"id" : 14,
"address" : 36,
"name" : "Sound 15",
"extender" : "extender_0"
"name" : "Sound 15"
},
{
"id" : 15,
"address" : 37,
"name" : "Sound 16",
"extender" : "extender_0"
"name" : "Sound 16"
},
{
"id" : 16,
"address" : 38,
"name" : "Sound 17",
"extender" : "extender_0"
"name" : "Sound 17"
},
{
"id" : 17,
"address" : 39,
"name" : "Sound 18",
"extender" : "extender_0"
"name" : "Sound 18"
},
{
"id" : 18,
"address" : 40,
"name" : "Sound 19",
"extender" : "extender_0"
"name" : "Sound 19"
},
{
"id" : 19,
"address" : 41,
"name" : "Sound 20",
"extender" : "extender_0"
"name" : "Sound 20"
},
{
"id" : 20,
"address" : 42,
"name" : "Sound 21",
"extender" : "extender_0"
"name" : "Sound 21"
},
{
"id" : 21,
"address" : 43,
"name" : "Sound 22",
"extender" : "extender_0"
"name" : "Sound 22"
},
{
"id" : 22,
"address" : 44,
"name" : "Sound 23",
"extender" : "extender_0"
"name" : "Sound 23"
},
{
"id" : 23,
"address" : 45,
"name" : "Sound 24",
"extender" : "extender_0"
"name" : "Sound 24"
},
{
"id" : 24,
"address" : 46,
"name" : "Sound 25",
"extender" : "extender_0"
"name" : "Sound 25"
},
{
"id" : 25,
"address" : 47,
"name" : "Sound 26",
"extender" : "extender_0"
"name" : "Sound 26"
},
{
"id" : 26,
"address" : 48,
"name" : "Sound 27",
"extender" : "extender_0"
"name" : "Sound 27"
},
{
"id" : 27,
"address" : 49,
"name" : "Sound 28",
"extender" : "extender_0"
"name" : "Sound 28"
},
{
"id" : 28,
"address" : 50,
"name" : "Speech 1: \"You're good! But I'm still the Champ!\"",
"extender" : "extender_0"
"name" : "Speech 1: \"You're good! But I'm still the Champ!\""
},
{
"id" : 29,
"address" : 51,
"name" : "Speech 2: \"Twenty\"",
"extender" : "extender_0"
"name" : "Speech 2: \"Twenty\""
},
{
"id" : 30,
"address" : 52,
"name" : "Speech 3: \"Seconds\"",
"extender" : "extender_0"
"name" : "Speech 3: \"Seconds\""
},
{
"id" : 31,
"address" : 53,
"name" : "Speech 4: \"Five, Four, Three, Two, One.\"",
"extender" : "extender_0"
"name" : "Speech 4: \"Five, Four, Three, Two, One.\""
},
{
"id" : 32,
"address" : 54,
"name" : "Speech 5: \"Challenge the champ!\"",
"extender" : "extender_0"
"name" : "Speech 5: \"Challenge the champ!\""
},
{
"id" : 33,
"address" : 55,
"name" : "Speech 6: \"Good. You're a champ!\"",
"extender" : "extender_0"
},
"name" : "Speech 6: \"Good. You're a champ!\""
},
{
"id" : 34,
"address" : 56,
"name" : "Speech 7: \"Wow.\"",
"extender" : "extender_0"
"name" : "Speech 7: \"Wow.\""
},
{
"id" : 35,
"address" : 57,
"name" : "Speech 8: \"This is a maximum score.\"",
"extender" : "extender_0"
"name" : "Speech 8: \"This is a maximum score.\""
},
{
"id" : 36,
"address" : 58,
"name" : "Speech 9: \"What a low score!\"",
"extender" : "extender_0"
"name" : "Speech 9: \"What a low score!\""
},
{
"id" : 37,
"address" : 59,
"name" : "Speech 10: \"Try harder!\"",
"extender" : "extender_0"
"name" : "Speech 10: \"Try harder!\""
},
{
"id" : 38,
"address" : 60,
"name" : "Speech 11: \"Be careful.\"",
"extender" : "extender_0"
"name" : "Speech 11: \"Be careful.\""
},
{
"id" : 39,
"address" : 61,
"name" : "Speech 12: \"The last ball.\"",
"extender" : "extender_0"
"name" : "Speech 12: \"The last ball.\""
},
{
"id" : 40,
"address" : 62,
"name" : "Speech 13: \"Be ready for the Game Time Bonus.\"",
"extender" : "extender_0"
"name" : "Speech 13: \"Be ready for the Game Time Bonus.\""
},
{
"id" : 41,
"address" : 63,
"name" : "Speech 14: \"That's naughty!\"",
"extender" : "extender_0"
"name" : "Speech 14: \"That's naughty!\""
},
{
"id" : 42,
"address" : 64,
"name" : "Speech 15: \"Another coin please.\"",
"extender" : "extender_0"
"name" : "Speech 15: \"Another coin please.\""
},
{
"id" : 43,
"address" : 65,
"name" : "Speech 16: \"Sorry. The time is over.\"",
"extender" : "extender_0"
"name" : "Speech 16: \"Sorry. The time is over.\""
},
{
"id" : 44,
"address" : 66,
"name" : "Speech 17: \"I am the champ! Challenge me!\"",
"extender" : "extender_0"
"name" : "Speech 17: \"I am the champ! Challenge me!\""
},
{
"id" : 45,
"address" : 67,
"name" : "Speech 18: \"Time is short.\"",
"extender" : "extender_0"
"name" : "Speech 18: \"Time is short.\""
},
{
"id" : 46,
"address" : 68,
"name" : "Speech 19: \"Once again for the special.\"",
"extender" : "extender_0"
"name" : "Speech 19: \"Once again for the special.\""
},
{
"id" : 47,
"address" : 69,
"name" : "Speech 20: \"Go for the high level board.\"",
"extender" : "extender_0"
"name" : "Speech 20: \"Go for the high level board.\""
},
{
"id" : 48,
"address" : 70,
"name" : "Speech 21: \"Play gently to beat me.\"",
"extender" : "extender_0"
"name" : "Speech 21: \"Play gently to beat me.\""
},
{
"id" : 49,
"address" : 71,
"name" : "Speech 22: \"Quick! Hit the special.\"",
"extender" : "extender_0"
"name" : "Speech 22: \"Quick! Hit the special.\""
},
{
"id" : 50,
"address" : 72,
"name" : "Speech 23: \"Shoot the special.\"",
"extender" : "extender_0"
"name" : "Speech 23: \"Shoot the special.\""
},
{
"id" : 51,
"address" : 73,
"name" : "Speech 24: \"Thirty\"",
"extender" : "extender_0"
"name" : "Speech 24: \"Thirty\""
},
{
"id" : 52,
"address" : 74,
"name" : "Speech 25: \"Red\"",
"extender" : "extender_0"
"name" : "Speech 25: \"Red\""
},
{
"id" : 53,
"address" : 75,
"name" : "Speech 27: \"Yellow\"",
"extender" : "extender_0"
"name" : "Speech 27: \"Yellow\""
},
{
"id" : 54,
"address" : 76,
"name" : "Speech 28: \"Go for the Special.\"",
"extender" : "extender_0"
"name" : "Speech 28: \"Go for the Special.\""
}
]
}

View File

@@ -59,10 +59,9 @@ std::map<std::string, std::shared_ptr<ItemType>> get_items(const std::string &co
nlohmann::json config_json;
config_stream >> config_json;
FactoryType factory{config_json, std::static_pointer_cast<ControllerType>(pin_controller)};
std::map<std::string, std::shared_ptr<ItemType>> map;
try{
FactoryType factory{config_json, std::static_pointer_cast<ControllerType>(pin_controller)};
map = factory.getItemMap();
}
catch(json::exception & e)

View File

@@ -158,6 +158,8 @@ void OutputDriver::shut_down_driver() const
this->deactivate_all_flipper_relays();
this->deactivate_all_lamps();
this->deactivate_displays();
CLOG(INFO, OUTPUT_LOGGER) << "Deactivated all output items.";
}

View File

@@ -71,18 +71,28 @@ void SoundBoardPinController::write_pin(const uint8_t &pin, const bool &value) c
{
PinController::write_pin(pin, value);
PinController::write_pin(this->fire_address, true);
PinController::write_pin(this->fire_address, false);
}
void SoundBoardPinController::set_address_pins(std::vector<uint8_t> address_pins)
{
this->address_pins = address_pins;
//print string in a nice manner
std::stringstream ss;
for (auto & p : address_pins)
{
ss << int{p} << ", ";
}
ss << std::string(2, 0x08);
CLOG(DEBUG, OUTPUT_LOGGER) << "Pin addresses for sounds set to: [" << ss.str() << "]";
}
void SoundBoardPinController::set_fire_address(const uint8_t &fire_address)
{
this->fire_address = fire_address;
CLOG(DEBUG, OUTPUT_LOGGER) << "Fire-pin address for sounds set to: " << int{fire_address};
}
}

View File

@@ -29,7 +29,7 @@ std::map<std::string, std::shared_ptr<items::Flipper>> FlipperFactory::getItemMa
auto extender = flipper.at(config_path::item_extender).get<std::string>();
auto pin_base = this->get_extender_pin_base(extender);
auto flipper_item = std::make_shared<items::detail::Flipper>(std::static_pointer_cast<DriverBoardPinController>(this->pin_controller), address, pin_base, name);
auto flipper_item = std::make_shared<items::detail::Flipper>(std::static_pointer_cast<DriverBoardPinController>(this->pin_controller), address + pin_base, name);
flipper_map.emplace(name, flipper_item);
}
return flipper_map;

View File

@@ -28,7 +28,8 @@ std::map<std::string, std::shared_ptr<items::Lamp>> LampFactory::getItemMap()
auto address = lamp.at(config_path::item_address).get<uint8_t >();
auto extender = lamp.at(config_path::item_extender).get<std::string>();
auto pin_base = this->get_extender_pin_base(extender);
auto lamp_item = std::make_shared<items::detail::Lamp>(std::static_pointer_cast<DriverBoardPinController>(this->pin_controller), address, pin_base, name);
auto lamp_item = std::make_shared<items::detail::Lamp>(std::static_pointer_cast<DriverBoardPinController>(this->pin_controller), address + pin_base, name);
lamp_map.emplace(name, lamp_item);
}
return lamp_map;

View File

@@ -40,7 +40,7 @@ std::map<std::string, std::shared_ptr<items::Solenoid>> SolenoidFactory::getItem
deactivation_time_chrono = std::chrono::milliseconds{solenoid.at(config_path::deactivation_time).get<uint8_t>()};
}
auto solenoid_item = std::make_shared<items::detail::Solenoid>(std::static_pointer_cast<DriverBoardPinController>(this->pin_controller), address, pin_base, name, deactivation_time_chrono);
auto solenoid_item = std::make_shared<items::detail::Solenoid>(std::static_pointer_cast<DriverBoardPinController>(this->pin_controller), address + pin_base, name, deactivation_time_chrono);
solenoid_map.emplace(name, solenoid_item);
}
return solenoid_map;

View File

@@ -33,8 +33,6 @@ std::map<std::string, std::shared_ptr<items::Sound>> SoundFactory::getItemMap()
{
auto name = sound.at(config_path::item_name).get<std::string>();
auto address = sound.at(config_path::item_address).get<uint8_t >();
auto extender = sound.at(config_path::item_extender).get<std::string>();
auto pin_base = this->get_extender_pin_base(extender);
auto id = sound.at(config_path::item_identifier).get<uint>();
std::chrono::milliseconds deactivation_time_chrono{this->deactivation_time};
@@ -42,7 +40,7 @@ std::map<std::string, std::shared_ptr<items::Sound>> SoundFactory::getItemMap()
{
deactivation_time_chrono = std::chrono::milliseconds{sound.at(config_path::deactivation_time).get<uint8_t>()};
}
auto sound_item = std::make_shared<items::detail::Sound>(std::static_pointer_cast<SoundBoardPinController>(this->pin_controller), address, pin_base, name, deactivation_time_chrono, id);
auto sound_item = std::make_shared<items::detail::Sound>(std::static_pointer_cast<SoundBoardPinController>(this->pin_controller), address, name, deactivation_time_chrono, id);
sound_map.emplace(name, sound_item);
}
@@ -67,9 +65,21 @@ void SoundFactory::set_address_pins()
std::vector<uint8_t> pins;
for (auto & pin : address_pins)
for (auto & pin_json : address_pins)
{
pins.push_back(pin.get<uint8_t>());
pins.push_back(0);
}
for (auto & pin_json : address_pins)
{
uint8_t pin = pin_json.at(config_path::item_address).get<uint8_t>();
if (pin_json.find(config_path::item_extender) != pin_json.end())
{
auto extender_name = pin_json.at(config_path::item_extender).get<std::string>();
pin += this->get_extender_pin_base(extender_name);
}
uint8_t id = pin_json.at(config_path::item_identifier).get<uint8_t>();
pins[id] = pin;
}
std::dynamic_pointer_cast<detail::SoundBoardPinController>(this->pin_controller)->set_address_pins(pins);

View File

@@ -6,8 +6,8 @@
using namespace flippR_driver::output;
items::detail::DriverBoardItem::DriverBoardItem(std::shared_ptr<PinController> pin_controller, const uint8_t & address, const uint8_t & pin_base) :
address(pin_base + address)
items::detail::DriverBoardItem::DriverBoardItem(std::shared_ptr<PinController> pin_controller, const uint8_t & address) :
address(address)
{
pin_controller->initialize_output_pin(this->address);
}

View File

@@ -21,7 +21,7 @@ namespace detail
class DriverBoardItem : public output::items::DriverBoardItem
{
public:
DriverBoardItem(std::shared_ptr<PinController> pin_controller, const uint8_t & address, const uint8_t & pin_base);
DriverBoardItem(std::shared_ptr<PinController> pin_controller, const uint8_t & address);
~DriverBoardItem() override = default;

View File

@@ -20,10 +20,10 @@ namespace items
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))
Flipper::Flipper(std::shared_ptr<DriverBoardPinController> pin_controller, const uint8_t & address, const std::string & name) :
Item(std::move(name)), DriverBoardItem(pin_controller, address), pin_controller(std::move(pin_controller))
{
CLOG(DEBUG, OUTPUT_LOGGER) << "Created flipper \"" << name << "\" with pin-base " << int(pin_base) << " and address " << int(address);
CLOG(DEBUG, OUTPUT_LOGGER) << "Created flipper \"" << name << "\" with address " << int(address);
}
Flipper::~Flipper()

View File

@@ -23,7 +23,7 @@ namespace detail
class Flipper : public detail::Item, public items::Flipper, public detail::DriverBoardItem
{
public:
Flipper(std::shared_ptr<DriverBoardPinController> pin_controller, const uint8_t & address, const uint8_t & pin_base, const std::string & name);
Flipper(std::shared_ptr<DriverBoardPinController> pin_controller, const uint8_t & address, const std::string & name);
~Flipper() override;
void activate() override;

View File

@@ -19,14 +19,14 @@ namespace items
namespace detail
{
Lamp::Lamp(std::shared_ptr<DriverBoardPinController> pin_controller, const uint8_t & address, const uint8_t & pin_base, const std::string & name) :
Lamp::Lamp(std::shared_ptr<DriverBoardPinController> pin_controller, const uint8_t & address, const std::string & name) :
detail::Item(std::move(name)),
DriverBoardItem(pin_controller, address, pin_base),
DriverBoardItem(pin_controller, address),
pin_controller(std::move(pin_controller)),
activated(false),
activation_time(10)
{
CLOG(DEBUG, OUTPUT_LOGGER) << "Created lamp \"" << name << "\" with pin-base " << int(pin_base) << " and address " << int(address);
CLOG(DEBUG, OUTPUT_LOGGER) << "Created lamp \"" << name << "\" with address " << int(address);
}
void Lamp::activate()

View File

@@ -27,7 +27,7 @@ namespace detail
class Lamp : public detail::DriverBoardItem, public detail::Item, public items::Lamp
{
public:
Lamp(std::shared_ptr<DriverBoardPinController> pin_controller, const uint8_t & address, const uint8_t & pin_base, const std::string & name);
Lamp(std::shared_ptr<DriverBoardPinController> pin_controller, const uint8_t & address, const std::string & name);
~Lamp() override = default;
void activate() override;

View File

@@ -18,8 +18,8 @@ namespace items
namespace detail
{
Solenoid::Solenoid(std::shared_ptr<DriverBoardPinController> pin_controller, const uint8_t & address, const uint8_t & pin_base, const std::string & name, const std::chrono::milliseconds & deactivation_time)
: detail::Item(std::move(name)), DriverBoardItem(pin_controller, address, pin_base), pin_controller(pin_controller), deactivation_time(deactivation_time)
Solenoid::Solenoid(std::shared_ptr<DriverBoardPinController> pin_controller, const uint8_t & address, const std::string & name, const std::chrono::milliseconds & deactivation_time)
: detail::Item(std::move(name)), DriverBoardItem(pin_controller, address), pin_controller(pin_controller), deactivation_time(deactivation_time)
{
CLOG(DEBUG, OUTPUT_LOGGER) << "Created solenoid " << name << " with address " << int{address} << " and deactivation-time: " << deactivation_time.count();
}

View File

@@ -29,7 +29,7 @@ namespace detail
class Solenoid : public DriverBoardItem, public detail::Item, public items::Solenoid
{
public:
Solenoid(std::shared_ptr<DriverBoardPinController> pin_controller, const uint8_t & address, const uint8_t & pin_base, const std::string & name, const std::chrono::milliseconds & deactivation_time);
Solenoid(std::shared_ptr<DriverBoardPinController> pin_controller, const uint8_t & address, const std::string & name, const std::chrono::milliseconds & deactivation_time);
~Solenoid() override = default;
void trigger() override;

View File

@@ -20,10 +20,10 @@ namespace items
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)
Sound::Sound(std::shared_ptr<SoundBoardPinController> pin_controller, const uint8_t & address, const std::string & name, const std::chrono::milliseconds & deactivation_time, const u_int id)
: detail::Item(std::move(name)), DriverBoardItem(pin_controller, address), pin_controller(std::move(pin_controller)), deactivation_time(deactivation_time), id(id)
{
CLOG(DEBUG, OUTPUT_LOGGER) << "Created sound " << id << " \"" << name << "\" with pin-base " << int(pin_base) << " and address " << int(address) << ". Deactivation time is: " << deactivation_time.count();
CLOG(DEBUG, OUTPUT_LOGGER) << "Created sound " << id << " \"" << name << "\" with address " << int(address) << ". Deactivation time is: " << deactivation_time.count();
}
void Sound::play()

View File

@@ -35,7 +35,7 @@ public:
u_int id;
public:
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);
Sound(std::shared_ptr<SoundBoardPinController> pin_controller, const uint8_t & address, const std::string & name, const std::chrono::milliseconds & deactivation_time, const u_int id);
~Sound() override = default;
void play() override;