Implements and integrates SolenoidFactory

This commit is contained in:
Johannes Wendel
2020-01-06 09:20:53 +01:00
parent 06663751d7
commit d90e904b4c
9 changed files with 96 additions and 9 deletions

View File

@@ -17,9 +17,9 @@ namespace output
class DisplayFactory : ItemFactory
{
public:
explicit DisplayFactory(nlohmann::json & object, std::shared_ptr<DisplayBoardPinController> pin_controller);
std::map<std::string, std::shared_ptr<items::Item>> getItemMap() override;
public:
};

View File

@@ -22,11 +22,11 @@ std::map<std::string, std::shared_ptr<items::Item>> FlipperFactory::getItemMap()
{
auto flippers = this->object.at(config_path::flipper_path);
std::map<std::string, std::shared_ptr<items::Item>> flipper_map;
for (auto lamp : flippers)
for (auto flipper : flippers)
{
auto name = lamp.at(config_path::item_name).get<std::string>();
auto address = lamp.at(config_path::item_address).get<uint8_t >();
auto extender = lamp.at(config_path::item_extender).get<std::string>();
auto name = flipper.at(config_path::item_name).get<std::string>();
auto address = flipper.at(config_path::item_address).get<uint8_t >();
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);

View File

@@ -29,6 +29,8 @@ namespace config_path
const char sound_path[] = "sounds";
const char flipper_path[] = "flippers";
const char solenoid_path[] = "solenoids";
}
class ItemFactory

View File

@@ -8,7 +8,7 @@
#ifndef FLIPPR_DRIVER_LAMPFACTORY_H
#define FLIPPR_DRIVER_LAMPFACTORY_H
#include <output/DriverBoardPinController.h>
#include "output/DriverBoardPinController.h"
#include "ItemFactory.h"
namespace flippR_driver

View File

@@ -0,0 +1,50 @@
/*
* SolenoidFactory.cpp
*
* Created on: January 6, 2020
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
*/
#include "output/items/detail/Solenoid.h"
#include "SolenoidFactory.h"
namespace flippR_driver
{
namespace output
{
SolenoidFactory::SolenoidFactory(nlohmann::json &object, std::shared_ptr<DriverBoardPinController> pin_controller) :
ItemFactory{object, pin_controller}
{
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>> SolenoidFactory::getItemMap()
{
auto solenoids = this->object.at(config_path::solenoid_path);
std::map<std::string, std::shared_ptr<items::Item>> solenoid_map;
for (auto solenoid : solenoids)
{
auto name = solenoid.at(config_path::item_name).get<std::string>();
auto address = solenoid.at(config_path::item_address).get<uint8_t >();
auto extender = solenoid.at(config_path::item_extender).get<std::string>();
auto pin_base = this->get_extender_pin_base(extender);
std::chrono::milliseconds deactivation_time_chrono{this->deactivation_time};
if (solenoid.find(config_path::deactivation_time) != solenoid.end())
{
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);
solenoid_map.emplace(name, solenoid_item);
}
return solenoid_map;
}
}
}

View File

@@ -0,0 +1,33 @@
/*
* SolenoidFactory.h
*
* Created on: January 6, 2020
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
*/
#ifndef FLIPPR_DRIVER_SOLENOIDFACTORY_H
#define FLIPPR_DRIVER_SOLENOIDFACTORY_H
#include "output/DriverBoardPinController.h"
#include "ItemFactory.h"
namespace flippR_driver
{
namespace output
{
class SolenoidFactory : public ItemFactory
{
public:
explicit SolenoidFactory(nlohmann::json &object, std::shared_ptr<DriverBoardPinController> pin_controller);
std::map<std::string, std::shared_ptr<items::Item>> getItemMap() override;
private:
uint8_t deactivation_time;
};
}
}
#endif //FLIPPR_DRIVER_SOLENOIDFACTORY_H