factory
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
|
"deactivation_time_milliseconds" : 10,
|
||||||
"sounds" :
|
"sounds" :
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#define _SRC_OUTPUT_ICABINETITEM_H_
|
#define _SRC_OUTPUT_ICABINETITEM_H_
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace flippR_driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
@@ -23,6 +24,7 @@ public:
|
|||||||
virtual ~IItem() = default;
|
virtual ~IItem() = default;
|
||||||
|
|
||||||
virtual uint8_t get_address() = 0;
|
virtual uint8_t get_address() = 0;
|
||||||
|
virtual std::string get_name() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,7 @@
|
|||||||
#ifndef _SRC_OUTPUT_ILAMP_H_
|
#ifndef _SRC_OUTPUT_ILAMP_H_
|
||||||
#define _SRC_OUTPUT_ILAMP_H_
|
#define _SRC_OUTPUT_ILAMP_H_
|
||||||
|
|
||||||
|
#include "IItem.h"
|
||||||
namespace flippR_driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace output
|
namespace output
|
||||||
@@ -15,7 +16,7 @@ namespace output
|
|||||||
namespace items
|
namespace items
|
||||||
{
|
{
|
||||||
|
|
||||||
class ILamp
|
class ILamp : public IItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
~ILamp()
|
~ILamp()
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
#ifndef _SRC_OUTPUT_ISOLENOID_H_
|
#ifndef _SRC_OUTPUT_ISOLENOID_H_
|
||||||
#define _SRC_OUTPUT_ISOLENOID_H_
|
#define _SRC_OUTPUT_ISOLENOID_H_
|
||||||
|
|
||||||
|
#include "IItem.h"
|
||||||
|
|
||||||
namespace flippR_driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace output
|
namespace output
|
||||||
@@ -15,7 +17,7 @@ namespace output
|
|||||||
namespace items
|
namespace items
|
||||||
{
|
{
|
||||||
|
|
||||||
class ISolenoid
|
class ISolenoid : public IItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
~ISolenoid()
|
~ISolenoid()
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
#ifndef _SRC_OUTPUT_ISOUND_H_
|
#ifndef _SRC_OUTPUT_ISOUND_H_
|
||||||
#define _SRC_OUTPUT_ISOUND_H_
|
#define _SRC_OUTPUT_ISOUND_H_
|
||||||
|
|
||||||
|
#include "IItem.h"
|
||||||
|
|
||||||
namespace flippR_driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace output
|
namespace output
|
||||||
@@ -15,7 +17,7 @@ namespace output
|
|||||||
namespace items
|
namespace items
|
||||||
{
|
{
|
||||||
|
|
||||||
class ISound
|
class ISound : public IItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ISound();
|
ISound();
|
||||||
|
|||||||
@@ -35,9 +35,6 @@ protected:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
static std::once_flag GPIO_LIB_INITIALIZED;
|
static std::once_flag GPIO_LIB_INITIALIZED;
|
||||||
|
|
||||||
private:
|
|
||||||
unsigned int pin_base;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
#include "IOutputGPIOInterface.h"
|
#include "IOutputGPIOInterface.h"
|
||||||
|
|
||||||
#include "output/items/IDriverBoardItem.h"
|
#include "output/items/IDriverBoardItem.h"
|
||||||
#include "output/items/ISoundItem.h"
|
#include "output/items/ISound.h"
|
||||||
#include "output/items/IDisplay.h"
|
#include "output/items/IDisplay.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
@@ -23,10 +23,10 @@ public:
|
|||||||
virtual ~IOutputGPIOInterface() = default;
|
virtual ~IOutputGPIOInterface() = default;
|
||||||
|
|
||||||
virtual void activate(items::IDriverBoardItem *driver_board_item) = 0;
|
virtual void activate(items::IDriverBoardItem *driver_board_item) = 0;
|
||||||
virtual void activate(items::ISoundItem *sound) = 0;
|
virtual void activate(items::ISound *sound) = 0;
|
||||||
|
|
||||||
virtual void deactivate(items::IDriverBoardItem *driver_board_item) = 0;
|
virtual void deactivate(items::IDriverBoardItem *driver_board_item) = 0;
|
||||||
virtual void deactivate(items::ISoundItem *sound) = 0;
|
virtual void deactivate(items::ISound *sound) = 0;
|
||||||
|
|
||||||
virtual void write_display(std::shared_ptr<output::items::IDisplay> display) = 0;
|
virtual void write_display(std::shared_ptr<output::items::IDisplay> display) = 0;
|
||||||
//Display gpio interface!
|
//Display gpio interface!
|
||||||
|
|||||||
@@ -16,10 +16,21 @@ namespace
|
|||||||
|
|
||||||
using namespace nlohmann;
|
using namespace nlohmann;
|
||||||
|
|
||||||
std::shared_ptr<OutputGPIOInterface> createOutputGPIOInterface(std::istream &output_gpio_config)
|
std::shared_ptr<IOutputDriver> get_OutputDriver(std::istream &output_pin_config, std::istream &solenoid_config, std::istream &lamp_config, std::istream &sound_config)
|
||||||
|
{
|
||||||
|
auto output_gpio_interface = create_OutputGPIOInterface(output_pin_config);
|
||||||
|
|
||||||
|
auto solenoids = create_solenoids(solenoid_config, output_gpio_interface);
|
||||||
|
auto lamps = create_lamps(lamp_config, output_gpio_interface);
|
||||||
|
auto sounds = create_sounds(sound_config, output_gpio_interface);
|
||||||
|
|
||||||
|
return std::make_shared<IOutputDriver>(solenoids, lamps, sounds);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<OutputGPIOInterface> create_OutputGPIOInterface(std::istream &output_pin_config)
|
||||||
{
|
{
|
||||||
json output_config;
|
json output_config;
|
||||||
output_gpio_config >> output_config;
|
output_pin_config >> output_config;
|
||||||
|
|
||||||
return std::make_shared<OutputGPIOInterface>(
|
return std::make_shared<OutputGPIOInterface>(
|
||||||
parse_pins_driver_board(output_config.at("driver_board")),
|
parse_pins_driver_board(output_config.at("driver_board")),
|
||||||
@@ -77,8 +88,54 @@ std::map<std::string, uint8_t> parse_pins_display(json &display_board_config)
|
|||||||
return std::map<std::string, uint8_t>();
|
return std::map<std::string, uint8_t>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::map<std::string, std::shared_ptr<items::ISolenoid>> create_solenoids(std::istream &solenoid_config, std::shared_ptr<IOutputGPIOInterface> output_gpio_interface)
|
||||||
|
{
|
||||||
|
std::map<std::string, items::ISolenoid> solenoids;
|
||||||
|
return solenoids;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::map<std::string, std::shared_ptr<items::ILamp>> create_lamps(std::istream &lamp_config, std::shared_ptr<IOutputGPIOInterface> output_gpio_interface)
|
||||||
|
{
|
||||||
|
std::map<std::string, items::ILamp> lamps;
|
||||||
|
return lamps;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::map<std::string, std::shared_ptr<items::ISound>> create_sounds(std::istream &sound_config, std::shared_ptr<IOutputGPIOInterface> output_gpio_interface)
|
||||||
|
{
|
||||||
|
std::map<std::string, std::shared_ptr<items::ISound>> sounds;
|
||||||
|
|
||||||
|
json sounds_json;
|
||||||
|
sound_config >> sounds_json;
|
||||||
|
|
||||||
|
for(auto &sound_json : sounds_json)
|
||||||
|
{
|
||||||
|
auto sound = create_sound(sound_json);
|
||||||
|
sounds.emplace(sound->get_name(), sound);
|
||||||
|
}
|
||||||
|
|
||||||
|
return sounds;
|
||||||
|
}
|
||||||
|
std::shared_ptr<items::ISolenoid> create_solenoid(nlohmann::json &solenoid_json, std::shared_ptr<IOutputGPIOInterface> output_gpio_interface)
|
||||||
|
{
|
||||||
|
return std::shared_ptr<items::ISolenoid>();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<items::Sound> create_sound(nlohmann::json &sound_json, std::shared_ptr<IOutputGPIOInterface> &output_gpio_interface, std::chrono::milliseconds deactivation_time)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
uint id = sound_json.at("id").get<uint>();
|
||||||
|
std::string name = sound_json.at("name");
|
||||||
|
uint8_t address = sound_json.at("address").get<uint8_t>();
|
||||||
|
return std::make_shared<items::Sound>(output_gpio_interface, address, name, deactivation_time, id);
|
||||||
|
}
|
||||||
|
catch(json::type_error &e)
|
||||||
|
{
|
||||||
|
// todo log and exit
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -5,7 +5,10 @@
|
|||||||
#ifndef flippR_driver_OUTPUTDRIVERFACTORY_H
|
#ifndef flippR_driver_OUTPUTDRIVERFACTORY_H
|
||||||
#define flippR_driver_OUTPUTDRIVERFACTORY_H
|
#define flippR_driver_OUTPUTDRIVERFACTORY_H
|
||||||
|
|
||||||
#include <output/IOutputDriver.h>
|
#include "output/IOutputDriver.h"
|
||||||
|
#include "output/items/Solenoid.h"
|
||||||
|
#include "output/items/Lamp.h"
|
||||||
|
#include "output/items/Sound.h"
|
||||||
#include "OutputGPIOInterface.h"
|
#include "OutputGPIOInterface.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@@ -16,15 +19,23 @@ namespace output
|
|||||||
{
|
{
|
||||||
namespace OutputDriverFactory
|
namespace OutputDriverFactory
|
||||||
{
|
{
|
||||||
static std::shared_ptr<IOutputDriver> get_OutputDriver(std::istream &output_pin_config, std::istream &solenoid_config, std::istream &lamp_config, std::istream &sound_config);
|
std::shared_ptr<IOutputDriver> get_OutputDriver(std::istream &output_pin_config, std::istream &solenoid_config, std::istream &lamp_config, std::istream &sound_config);
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
static std::shared_ptr<OutputGPIOInterface> createOutputGPIOInterface(std::istream &output_gpio_config);
|
std::map<std::string, std::shared_ptr<items::ISolenoid>> create_solenoids(std::istream &solenoid_config, std::shared_ptr<IOutputGPIOInterface> output_gpio_interface);
|
||||||
|
std::shared_ptr<items::ISolenoid> create_solenoid(nlohmann::json &solenoid_json, std::shared_ptr<IOutputGPIOInterface> output_gpio_interface);
|
||||||
|
|
||||||
static std::map<std::string, uint8_t> parse_pins_driver_board(nlohmann::json &driver_board_config);
|
std::map<std::string, std::shared_ptr<items::ILamp>> create_lamps(std::istream &lamp_config, std::shared_ptr<IOutputGPIOInterface> output_gpio_interface);
|
||||||
static std::map<std::string, uint8_t> parse_pins_sound(nlohmann::json &sound_board_config);
|
std::shared_ptr<items::ILamp> create_lamp(nlohmann::json &lamp_json, std::shared_ptr<IOutputGPIOInterface> output_gpio_interface);
|
||||||
static std::map<std::string, uint8_t> parse_pins_display(nlohmann::json &display_board_config);
|
|
||||||
|
std::map<std::string, std::shared_ptr<items::ISound>> create_sounds(std::istream &sound_config, std::shared_ptr<IOutputGPIOInterface> output_gpio_interface);
|
||||||
|
std::shared_ptr<items::ISound> create_sound(nlohmann::json &sound_json, std::shared_ptr<IOutputGPIOInterface> output_gpio_interface, std::chrono::milliseconds deactivation_time);
|
||||||
|
|
||||||
|
std::shared_ptr<OutputGPIOInterface> create_OutputGPIOInterface(std::istream &output_pin_config);
|
||||||
|
std::map<std::string, uint8_t> parse_pins_driver_board(nlohmann::json &driver_board_config);
|
||||||
|
std::map<std::string, uint8_t> parse_pins_sound(nlohmann::json &sound_board_config);
|
||||||
|
std::map<std::string, uint8_t> parse_pins_display(nlohmann::json &display_board_config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
#include <mcp23017.h>
|
#include <mcp23017.h>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <output/items/ISound.h>
|
||||||
namespace flippR_driver
|
namespace flippR_driver
|
||||||
{
|
{
|
||||||
namespace output
|
namespace output
|
||||||
@@ -32,10 +33,10 @@ public:
|
|||||||
~OutputGPIOInterface() override = default;
|
~OutputGPIOInterface() override = default;
|
||||||
|
|
||||||
void activate(items::IDriverBoardItem *driver_board_item) override;
|
void activate(items::IDriverBoardItem *driver_board_item) override;
|
||||||
void activate(items::ISoundItem *sound) override;
|
void activate(items::ISound *sound) override;
|
||||||
|
|
||||||
void deactivate(items::IDriverBoardItem *driver_board_item) override;
|
void deactivate(items::IDriverBoardItem *driver_board_item) override;
|
||||||
void deactivate(items::ISoundItem *sound) override;
|
void deactivate(items::ISound *sound) override;
|
||||||
|
|
||||||
void write_display(std::shared_ptr<output::items::IDisplay> display) override;
|
void write_display(std::shared_ptr<output::items::IDisplay> display) override;
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#ifndef FLIPPR_DRIVER_IDRIVERBOARDITEM_H
|
#ifndef FLIPPR_DRIVER_IDRIVERBOARDITEM_H
|
||||||
#define FLIPPR_DRIVER_IDRIVERBOARDITEM_H
|
#define FLIPPR_DRIVER_IDRIVERBOARDITEM_H
|
||||||
|
|
||||||
#include "IItem.h"
|
#include "output/items/IItem.h"
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by rhetenor on 23.11.18.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef FLIPPR_DRIVER_ISOUNDITEM_H
|
|
||||||
#define FLIPPR_DRIVER_ISOUNDITEM_H
|
|
||||||
|
|
||||||
#include "IItem.h"
|
|
||||||
namespace flippR_driver
|
|
||||||
{
|
|
||||||
namespace output
|
|
||||||
{
|
|
||||||
namespace items
|
|
||||||
{
|
|
||||||
class ISoundItem : public IItem
|
|
||||||
{
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif //FLIPPR_DRIVER_ISOUNDITEM_H
|
|
||||||
@@ -21,6 +21,10 @@ uint8_t Item::get_address()
|
|||||||
{
|
{
|
||||||
return this->address;
|
return this->address;
|
||||||
}
|
}
|
||||||
|
std::string Item::get_name()
|
||||||
|
{
|
||||||
|
return this->name;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
#ifndef _SRC_OUTPUT_CABINETITEM_H_
|
#ifndef _SRC_OUTPUT_CABINETITEM_H_
|
||||||
#define _SRC_OUTPUT_CABINETITEM_H_
|
#define _SRC_OUTPUT_CABINETITEM_H_
|
||||||
|
|
||||||
#include "IItem.h"
|
#include "output/items/IItem.h"
|
||||||
|
|
||||||
#include "output/IOutputGPIOInterface.h"
|
#include "output/IOutputGPIOInterface.h"
|
||||||
|
|
||||||
@@ -29,6 +29,7 @@ public:
|
|||||||
~Item() override = default;
|
~Item() override = default;
|
||||||
|
|
||||||
uint8_t get_address() override;
|
uint8_t get_address() override;
|
||||||
|
std::string get_name() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const uint8_t address;
|
const uint8_t address;
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
#define _SRC_OUTPUT_SOUND_H_
|
#define _SRC_OUTPUT_SOUND_H_
|
||||||
|
|
||||||
#include "output/items/ISound.h"
|
#include "output/items/ISound.h"
|
||||||
#include "ISoundItem.h"
|
|
||||||
#include "Item.h"
|
#include "Item.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@@ -25,7 +24,7 @@ namespace output
|
|||||||
namespace items
|
namespace items
|
||||||
{
|
{
|
||||||
|
|
||||||
class Sound : public ISound, Item, ISoundItem
|
class Sound : public ISound, Item
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
u_int id;
|
u_int id;
|
||||||
|
|||||||
Reference in New Issue
Block a user