implements and integrates sound factory
This commit is contained in:
@@ -20,7 +20,8 @@
|
|||||||
"id" : 0,
|
"id" : 0,
|
||||||
"address" : 22,
|
"address" : 22,
|
||||||
"name" : "Sound 1",
|
"name" : "Sound 1",
|
||||||
"extender" : "extender_0"
|
"extender" : "extender_0",
|
||||||
|
"deactivation_time_milliseconds" : 10
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id" : 1,
|
"id" : 1,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include <output/factories/LampFactory.h>
|
#include <output/factories/LampFactory.h>
|
||||||
|
#include <output/factories/SoundFactory.h>
|
||||||
#include "OutputDriverFactory.h"
|
#include "OutputDriverFactory.h"
|
||||||
|
|
||||||
#include "utility/LoggerFactory.h"
|
#include "utility/LoggerFactory.h"
|
||||||
@@ -62,10 +63,11 @@ std::shared_ptr<OutputDriver> get_OutputDriver(std::istream& solenoid_config,
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*auto sound_board_pin_controller = create_SoundBoardPinController();
|
auto sound_board_pin_controller = create_SoundBoardPinController();
|
||||||
auto sounds = create_sounds(sound_board_pin_controller);
|
SoundFactory sound_factory{config::sounds, sound_board_pin_controller};
|
||||||
|
auto sounds = sound_factory.getItemMap();
|
||||||
|
|
||||||
std::unique_ptr<DisplayBoardPinController> display_board_pin_controller(new detail::DisplayBoardPinController(parse_pins_display_board(display_config)));
|
/*std::unique_ptr<DisplayBoardPinController> display_board_pin_controller(new detail::DisplayBoardPinController(parse_pins_display_board(display_config)));
|
||||||
auto displays = create_displays();
|
auto displays = create_displays();
|
||||||
std::unique_ptr<DisplayController> display_controller(new detail::DisplayController(displays, std::move(display_board_pin_controller)));
|
std::unique_ptr<DisplayController> display_controller(new detail::DisplayController(displays, std::move(display_board_pin_controller)));
|
||||||
auto display_map = map_displays(displays);
|
auto display_map = map_displays(displays);
|
||||||
|
|||||||
@@ -18,6 +18,16 @@ namespace flippR_driver
|
|||||||
namespace output
|
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
|
class Factory
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -12,14 +12,37 @@ namespace output
|
|||||||
{
|
{
|
||||||
|
|
||||||
SoundFactory::SoundFactory(nlohmann::json &object, std::shared_ptr<SoundBoardPinController> pin_controller) :
|
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()
|
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 "Factory.h"
|
||||||
|
|
||||||
|
#include "output/SoundBoardPinController.h"
|
||||||
|
|
||||||
namespace flippR_driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace output
|
namespace output
|
||||||
@@ -20,10 +22,12 @@ class SoundFactory : Factory
|
|||||||
public:
|
public:
|
||||||
explicit SoundFactory(nlohmann::json & object, std::shared_ptr<SoundBoardPinController> pin_controller);
|
explicit SoundFactory(nlohmann::json & object, std::shared_ptr<SoundBoardPinController> pin_controller);
|
||||||
std::map<std::string, std::shared_ptr<items::Item>> getItemMap() override;
|
std::map<std::string, std::shared_ptr<items::Item>> getItemMap() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint8_t deactivation_time;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif //FLIPPR_DRIVER_SOUNDFACTORY_H
|
#endif //FLIPPR_DRIVER_SOUNDFACTORY_H
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ Lamp::Lamp(std::shared_ptr<DriverBoardPinController> pin_controller, const uint8
|
|||||||
activated(false),
|
activated(false),
|
||||||
activation_time(10)
|
activation_time(10)
|
||||||
{
|
{
|
||||||
CLOG(INFO , OUTPUT_LOGGER) << "Created lamp \"" << name << "\" with pin-base " << int(pin_base) << " and address " << int(address);
|
//CLOG(INFO , OUTPUT_LOGGER) << "Created lamp \"" << name << "\" with pin-base " << int(pin_base) << " and address " << int(address);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Lamp::activate()
|
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)
|
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)
|
: 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 \"" << name << "\" with pin-base " << int(pin_base) << " and address " << int(address);
|
CLOG(INFO , OUTPUT_LOGGER) << "Created sound " << id << " \"" << name << "\" with pin-base " << int(pin_base) << " and address " << int(address) << ". Deactivation time is: " << deactivation_time.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sound::play()
|
void Sound::play()
|
||||||
|
|||||||
Reference in New Issue
Block a user