Finished LampFactory
This commit is contained in:
@@ -15,7 +15,35 @@ namespace output
|
|||||||
Factory::Factory(nlohmann::json &object) :
|
Factory::Factory(nlohmann::json &object) :
|
||||||
object{object}
|
object{object}
|
||||||
{
|
{
|
||||||
|
this->initialize_port_extenders();
|
||||||
|
this->port_extenders = this->object.at("port_extenders");
|
||||||
|
}
|
||||||
|
|
||||||
|
void Factory::initialize_port_extender(nlohmann::json &extender)
|
||||||
|
{
|
||||||
|
auto i2c_address = extender.at("i2c_address").get<uint8_t>();
|
||||||
|
auto pin_base = extender.at("pin_base").get<uint8_t>();
|
||||||
|
this->pin_controller->initialize_port_expander(i2c_address, pin_base);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Factory::initialize_port_extenders()
|
||||||
|
{
|
||||||
|
for (auto extender : port_extenders)
|
||||||
|
{
|
||||||
|
this->initialize_port_extender(extender);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t Factory::get_extender_pin_base(std::string &name)
|
||||||
|
{
|
||||||
|
for (auto extender : port_extenders)
|
||||||
|
{
|
||||||
|
if (extender.at("name").get<std::string>() == name)
|
||||||
|
{
|
||||||
|
return extender.at("pin_base").get<uint8_t>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#ifndef FLIPPR_DRIVER_FACTORY_H
|
#ifndef FLIPPR_DRIVER_FACTORY_H
|
||||||
#define FLIPPR_DRIVER_FACTORY_H
|
#define FLIPPR_DRIVER_FACTORY_H
|
||||||
|
|
||||||
|
#include <PinController.h>
|
||||||
#include "utility/config.h"
|
#include "utility/config.h"
|
||||||
#include "json/json.hpp"
|
#include "json/json.hpp"
|
||||||
#include "output/items/Item.h"
|
#include "output/items/Item.h"
|
||||||
@@ -24,8 +25,17 @@ public:
|
|||||||
|
|
||||||
virtual std::map<std::string, std::shared_ptr<items::Item>> getItemMap() = 0;
|
virtual std::map<std::string, std::shared_ptr<items::Item>> getItemMap() = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void initialize_port_extender(nlohmann::json & extender);
|
||||||
|
void initialize_port_extenders();
|
||||||
|
uint8_t get_extender_pin_base(std::string & name);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
nlohmann::json object;
|
nlohmann::json object;
|
||||||
|
std::shared_ptr<PinController> pin_controller;
|
||||||
|
|
||||||
|
private:
|
||||||
|
nlohmann::json port_extenders;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,22 +5,33 @@
|
|||||||
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
|
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <output/items/Lamp.h>
|
||||||
#include "LampFactory.h"
|
#include "LampFactory.h"
|
||||||
|
#include "output/items/detail/Lamp.h"
|
||||||
|
|
||||||
namespace flippR_driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace output
|
namespace output
|
||||||
{
|
{
|
||||||
|
|
||||||
LampFactory::LampFactory(nlohmann::json &object) : Factory(object)
|
LampFactory::LampFactory(nlohmann::json &object) :
|
||||||
{
|
Factory(object)
|
||||||
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
std::map<std::string, std::shared_ptr<items::Item>> LampFactory::getItemMap()
|
std::map<std::string, std::shared_ptr<items::Item>> LampFactory::getItemMap()
|
||||||
{
|
{
|
||||||
return std::map<std::string, std::shared_ptr<items::Item>>();
|
auto lamps = object.at("lamps");
|
||||||
|
std::map<std::string, std::shared_ptr<items::Item>> lamp_map;
|
||||||
|
for (auto lamp : lamps)
|
||||||
|
{
|
||||||
|
auto name = lamp.at("name").get<std::string>();
|
||||||
|
auto address = lamp.at("address").get<uint8_t >();
|
||||||
|
auto extender = lamp.at("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);
|
||||||
|
lamp_map.emplace(name, lamp_item);
|
||||||
|
}
|
||||||
|
return lamp_map;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ class LampFactory : Factory
|
|||||||
public:
|
public:
|
||||||
explicit LampFactory(nlohmann::json & object);
|
explicit LampFactory(nlohmann::json & object);
|
||||||
std::map<std::string, std::shared_ptr<items::Item>> getItemMap() override;
|
std::map<std::string, std::shared_ptr<items::Item>> getItemMap() override;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user