implements and integrates sound factory
This commit is contained in:
@@ -18,6 +18,16 @@ namespace flippR_driver
|
||||
namespace output
|
||||
{
|
||||
|
||||
namespace config_path
|
||||
{
|
||||
const char item_name[] = "name";
|
||||
const char item_address[] = "address";
|
||||
const char item_extender[] = "extender";
|
||||
const char item_identifier[] = "id";
|
||||
const char deactivation_time[] = "deactivation_time_milliseconds";
|
||||
const char sound_path[] = "sounds";
|
||||
}
|
||||
|
||||
class Factory
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -12,14 +12,37 @@ namespace output
|
||||
{
|
||||
|
||||
SoundFactory::SoundFactory(nlohmann::json &object, std::shared_ptr<SoundBoardPinController> pin_controller) :
|
||||
Factory{object, pin_controller}
|
||||
Factory{object, pin_controller},
|
||||
deactivation_time{0}
|
||||
{
|
||||
|
||||
if (object.find(config_path::deactivation_time) != object.end())
|
||||
{
|
||||
this->deactivation_time = object.at(config_path::deactivation_time).get<uint8_t>();
|
||||
}
|
||||
}
|
||||
|
||||
std::map<std::string, std::shared_ptr<items::Item>> SoundFactory::getItemMap()
|
||||
{
|
||||
return std::map<std::string, std::shared_ptr<items::Item>>();
|
||||
auto sounds = this->object.at(config_path::sound_path);
|
||||
std::map<std::string, std::shared_ptr<items::Item>> sound_map;
|
||||
for (auto sound : sounds)
|
||||
{
|
||||
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};
|
||||
if (object.find(config_path::deactivation_time) != object.end())
|
||||
{
|
||||
deactivation_time_chrono = std::chrono::milliseconds{object.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);
|
||||
|
||||
sound_map.emplace(name, sound_item);
|
||||
}
|
||||
return sound_map;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
|
||||
#include "Factory.h"
|
||||
|
||||
#include "output/SoundBoardPinController.h"
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
@@ -20,10 +22,12 @@ class SoundFactory : Factory
|
||||
public:
|
||||
explicit SoundFactory(nlohmann::json & object, std::shared_ptr<SoundBoardPinController> pin_controller);
|
||||
std::map<std::string, std::shared_ptr<items::Item>> getItemMap() override;
|
||||
|
||||
private:
|
||||
uint8_t deactivation_time;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif //FLIPPR_DRIVER_SOUNDFACTORY_H
|
||||
|
||||
Reference in New Issue
Block a user