This commit is contained in:
Jonas Zeunert
2018-11-20 21:42:02 +01:00
9 changed files with 421 additions and 21 deletions

View File

@@ -0,0 +1,380 @@
@startuml
/' Objects '/
namespace flippR_driver::output {
class Display <template <int DigitCount>> {
+Display(int address, int id)
+~Display()
-address : int
+getID() : int
-id : int
+content : std::array<char, DigitCount>
-fit_string(std::string& score_string) : std::string
+write_content(std::array<char, DigitCount> content) : void
+write_score(int score) : void
}
}
namespace flippR_driver::output {
class DisplayController {
+DisplayController(std::vector<std::shared_ptr<IDisplay> > displays, std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface)
+~DisplayController()
-is_running : bool
-output_gpio_interface : std::shared_ptr<utility::IOutputGPIOInterface>
-display_cycle_thread : std::thread
-displays : std::vector<std::shared_ptr<IDisplay> >
-cycle_displays() : void
}
}
class DisplayGPIOInterface {
+DisplayGPIOInterface()
+~DisplayGPIOInterface()
}
namespace flippR_driver::input {
class Event {
+Event(char address, int priority, std::string name)
+operator<(const Event& left, const Event& right) : bool
+operator==(const Event& left, const Event& right) : bool
+address : char
+priority : int
+name : std::string
}
}
namespace flippR_driver::input {
class EventHandler {
+EventHandler(std::shared_ptr<IInputDriver> input_driver)
+~EventHandler()
-input_driver : std::shared_ptr<IInputDriver>
+handle(Event& event) : void
}
}
namespace flippR_driver::utility {
class GPIOInterface {
+GPIOInterface()
+~GPIOInterface()
+{static} read_pin(char address) : bool
+{static} GPIO_LIB_INITIALIZED : static std::once_flag
+{static} initialize_input_pin(char address) : void
+{static} initialize_output_pin(char address) : void
+{static} write_pin(char address, char data) : void
}
}
namespace flippR_driver::utility {
abstract class IBlockingQueue <template<typename T>> {
+~IBlockingQueue()
+{abstract} pop() : T
+{abstract} push(T const& value) : void
}
}
namespace flippR_driver::output {
abstract class IDisplay {
+IDisplay()
+~IDisplay()
+{abstract} getID() : int
-fit_string(std::string& score_string) : std::string
+{abstract} write_content(std::array<char, DigitCount> content) : void
+{abstract} write_score(int score) : void
}
}
namespace flippR_driver::output {
class IDisplayController {
+IDisplayController()
+~IDisplayController()
}
}
abstract class IEventHandler {
+~IEventHandler()
+{abstract} handle(flippR_driver::input::Event& event) : void
}
namespace flippR_driver::input {
abstract class IInputDriver {
+~IInputDriver()
+{abstract} get_event(std::string name) : std::shared_ptr<Event>
+{abstract} register_event_handler(IEventHandler* handler) : void
+{abstract} unregister_event_handler(IEventHandler* handler) : void
}
}
namespace flippR_driver::utility {
abstract class IInputGPIOInterface {
+~IInputGPIOInterface()
+{abstract} read_data(char pin) : bool
}
}
namespace flippR_driver::output {
class ILamp {
}
}
namespace flippR_driver::output {
class IOutputDriver {
+IOutputDriver()
+~IOutputDriver()
}
}
namespace flippR_driver::utility {
class IOutputGPIOInterface {
+activate_pin(int i2c_address, int pin) : void
+deactivate_pin(int i2c_address, int pin) : void
+set_address(int i2c_address, int address) : void
}
}
namespace flippR_driver::output {
abstract class IOutputItem {
-~IOutputItem()
-{abstract} activate() : bool
-{abstract} deactivate() : bool
-{abstract} isActivated() : bool
}
}
namespace flippR_driver::output {
class ISolenoid {
}
}
namespace flippR_driver::output {
abstract class ISound {
+ISound()
+~ISound()
+{abstract} play() : void
}
}
namespace flippR_driver::utility {
class InputGPIOInterface {
+InputGPIOInterface(std::istream& input_config_stream)
+read_data(char pin) : bool
-col_address_A : char
-col_address_B : char
-col_address_C : char
-data_address : char
-row_address_A : char
-row_address_B : char
-row_address_C : char
-init_members(std::istream& input_config_stream) : void
-init_pins() : void
-write_col(char data) : void
-write_row(char data) : void
}
}
namespace flippR_driver::output {
class Lamp {
+Lamp(std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface, int address, std::string name, bool activated)
+~Lamp()
-activated : bool
+is_activated() : bool
+activate() : void
+deactivate() : void
}
}
namespace flippR_driver::output {
class OutputDriver {
+OutputDriver(std::map<std::string, std::shared_ptr<IOutputtItem> > cabinet_items, std::map<char, std::shared_ptr<IDisplay> > displays, std::map<std::string, std::shared_ptr<ISound> > sounds)
+~OutputDriver()
-displays : std::map<char, std::shared_ptr<IDisplay> >
-cabinet_items : std::map<std::string, std::shared_ptr<IOutputtItem> >
-sounds : std::map<std::string, std::shared_ptr<ISound> >
+get_display(char number) : std::shared_ptr<IDisplay>
+get_cabinet_item(std::string name) : std::shared_ptr<IOutputtItem>
+get_sound(std::string name) : std::shared_ptr<ISound>
+get_displays() : std::vector<std::shared_ptr<IDisplay> >
+get_cabinet_items() : std::vector<std::shared_ptr<IOutputtItem> >
+get_sounds() : std::vector<std::shared_ptr<ISound> >
}
}
namespace flippR_driver::output {
class OutputDriverFactory {
+{static} getOutputDriver(std::ifstream& output_gpio_config, std::ifstream& output_config) : std::shared_ptr<OutputDriver>
}
}
namespace flippR_driver::utility {
class OutputGPIOInterface {
+activate_cabinet_item(CabinetItem& item) : void
+write_display(Display& display) : void
-event_queue : void:IBlockingQueue<CabinetItem>
}
}
namespace flippR_driver::output {
class OutputItem {
+OutputItem(std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface, int address, std::string name)
+~OutputItem()
#address : int
#data_pin_address : int
#i2c_address : int
#output_gpio_interface : std::shared_ptr<utility::IOutputGPIOInterface>
#name : std::string
}
}
namespace flippR_driver::output {
class Solenoid {
+Solenoid(std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface, int address, std::string name, std::chrono::milliseconds deactivation_time)
+~Solenoid()
-deactivation_time : std::chrono::milliseconds
-wait_thread : std::future<void>
-activate() : void
-deactivate() : void
+trigger() : void
}
}
namespace flippR_driver::output {
class Sound {
+Sound(std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface, int address, std::string name)
+~Sound()
-address : int
-output_gpio_interface : std::shared_ptr<utility::IOutputGPIOInterface>
-name : std::string
+play() : void
}
}
/' Inheritance relationships '/
namespace flippR_driver::utility {
GPIOInterface <|-- InputGPIOInterface
}
namespace flippR_driver::utility {
GPIOInterface <|-- OutputGPIOInterface
}
namespace flippR_driver::output {
IDisplay <|-- Display
}
namespace flippR_driver::output {
IDisplayController <|-- DisplayController
}
.IEventHandler <|-- flippR_driver::input.EventHandler
namespace flippR_driver::utility {
IInputGPIOInterface <|-- InputGPIOInterface
}
namespace flippR_driver::output {
IOutputDriver <|-- OutputDriver
}
namespace flippR_driver::output {
IOutputItem <|-- OutputItem
}
namespace flippR_driver::output {
ISound <|-- Sound
}
namespace flippR_driver::output {
OutputItem <|-- Lamp
}
namespace flippR_driver::output {
OutputItem <|-- Solenoid
}
/' Aggregation relationships '/
namespace flippR_driver::output {
DisplayController o-- IDisplay
}
flippR_driver::output.DisplayController o-- flippR_driver::utility.IOutputGPIOInterface
namespace flippR_driver::input {
EventHandler o-- IInputDriver
}
namespace flippR_driver::output {
OutputDriver o-- IDisplay
}
namespace flippR_driver::output {
OutputDriver o-- ISound
}
namespace flippR_driver::utility {
OutputGPIOInterface o-- IBlockingQueue
}
flippR_driver::output.OutputItem o-- flippR_driver::utility.IOutputGPIOInterface
flippR_driver::output.Sound o-- flippR_driver::utility.IOutputGPIOInterface
@enduml

View File

@@ -14,9 +14,9 @@ namespace flippR_driver
namespace output namespace output
{ {
class ICabinetItem class IOutputItem
{ {
virtual ~ICabinetItem(); virtual ~IOutputItem();
virtual bool isActivated() = 0; virtual bool isActivated() = 0;
virtual bool activate() = 0; virtual bool activate() = 0;
virtual bool deactivate() = 0; virtual bool deactivate() = 0;

View File

@@ -12,8 +12,9 @@ namespace flippR_driver
namespace output namespace output
{ {
Lamp::Lamp(std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface, int address, std::string name) : Lamp::Lamp(std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface, int address, std::string name, bool activated) :
OutputItem(output_gpio_interface, address, name) OutputItem(output_gpio_interface, address, name),
activated(activated)
{ {
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub

View File

@@ -18,7 +18,7 @@ namespace output
class Lamp : public OutputItem class Lamp : public OutputItem
{ {
public: public:
Lamp(std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface, int address, std::string name); Lamp(std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface, int address, std::string name, bool activated = false);
virtual ~Lamp(); virtual ~Lamp();
void activate(); void activate();

View File

@@ -15,13 +15,13 @@ namespace flippR_driver
namespace output namespace output
{ {
OutputDriver::OutputDriver(std::map<std::string, std::shared_ptr<ICabinetItem>> cabinet_items, std::map<char, std::shared_ptr<IDisplay>> displays, std::map<std::string, std::shared_ptr<ISound>> sounds) OutputDriver::OutputDriver(std::map<std::string, std::shared_ptr<IOutputtItem>> cabinet_items, std::map<char, std::shared_ptr<IDisplay>> displays, std::map<std::string, std::shared_ptr<ISound>> sounds)
: cabinet_items(cabinet_items), displays(displays), sounds(sounds) : cabinet_items(cabinet_items), displays(displays), sounds(sounds)
{} {}
std::vector<std::shared_ptr<ICabinetItem>> OutputDriver::get_cabinet_items() std::vector<std::shared_ptr<IOutputtItem>> OutputDriver::get_cabinet_items()
{ {
std::vector<std::shared_ptr<ICabinetItem>> cabinet_items; std::vector<std::shared_ptr<IOutputtItem>> cabinet_items;
boost::copy(this->cabinet_items | boost::adaptors::map_values, std::back_inserter(cabinet_items)); boost::copy(this->cabinet_items | boost::adaptors::map_values, std::back_inserter(cabinet_items));
@@ -46,7 +46,7 @@ std::vector<std::shared_ptr<IDisplay>> OutputDriver::get_displays()
return displays; return displays;
} }
std::shared_ptr<ICabinetItem> OutputDriver::get_cabinet_item(std::string name) std::shared_ptr<IOutputtItem> OutputDriver::get_cabinet_item(std::string name)
{ {
return this->cabinet_items.find(name)->second; return this->cabinet_items.find(name)->second;
} }

View File

@@ -25,20 +25,20 @@ namespace output
class OutputDriver : public IOutputDriver class OutputDriver : public IOutputDriver
{ {
public: public:
OutputDriver(std::map<std::string, std::shared_ptr<ICabinetItem>> cabinet_items, std::map<char, std::shared_ptr<IDisplay>> displays, std::map<std::string, std::shared_ptr<ISound>> sounds); OutputDriver(std::map<std::string, std::shared_ptr<IOutputtItem>> cabinet_items, std::map<char, std::shared_ptr<IDisplay>> displays, std::map<std::string, std::shared_ptr<ISound>> sounds);
virtual ~OutputDriver() = default; virtual ~OutputDriver() = default;
std::vector<std::shared_ptr<ICabinetItem>> get_cabinet_items(); std::vector<std::shared_ptr<IOutputtItem>> get_cabinet_items();
std::vector<std::shared_ptr<ISound>> get_sounds(); std::vector<std::shared_ptr<ISound>> get_sounds();
std::vector<std::shared_ptr<IDisplay>> get_displays(); std::vector<std::shared_ptr<IDisplay>> get_displays();
std::shared_ptr<ICabinetItem> get_cabinet_item(std::string name); std::shared_ptr<IOutputtItem> get_cabinet_item(std::string name);
std::shared_ptr<ISound> get_sound(std::string name); std::shared_ptr<ISound> get_sound(std::string name);
std::shared_ptr<IDisplay> get_display(char number); std::shared_ptr<IDisplay> get_display(char number);
private: private:
std::map<std::string, std::shared_ptr<ICabinetItem>> cabinet_items; std::map<std::string, std::shared_ptr<IOutputtItem>> cabinet_items;
std::map<char, std::shared_ptr<IDisplay>> displays; std::map<char, std::shared_ptr<IDisplay>> displays;
std::map<std::string, std::shared_ptr<ISound>> sounds; std::map<std::string, std::shared_ptr<ISound>> sounds;
}; };

View File

@@ -8,9 +8,8 @@
#ifndef _SRC_OUTPUT_CABINETITEM_H_ #ifndef _SRC_OUTPUT_CABINETITEM_H_
#define _SRC_OUTPUT_CABINETITEM_H_ #define _SRC_OUTPUT_CABINETITEM_H_
#include "ICabinetItem.h" #include "IOutputItem.h"
#include "ActivationStrategy.h"
#include "utility/IOutputGPIOInterface.h" #include "utility/IOutputGPIOInterface.h"
#include <memory> #include <memory>
@@ -21,7 +20,7 @@ namespace flippR_driver
namespace output namespace output
{ {
class OutputItem : public ICabinetItem class OutputItem : public IOutputItem
{ {
public: public:
OutputItem(std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface, int address, std::string name); OutputItem(std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface, int address, std::string name);
@@ -31,8 +30,6 @@ protected:
int address, i2c_address, data_pin_address; int address, i2c_address, data_pin_address;
std::string name; std::string name;
strategy::ActivationStrategy* strategy;
std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface; std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface;
}; };

View File

@@ -11,8 +11,9 @@ namespace flippR_driver
{ {
namespace output { namespace output {
Solenoid::Solenoid(std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface, int address, std::string name) : Solenoid::Solenoid(std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface, int address, std::string name, std::chrono::milliseconds deactivation_time) :
OutputItem(output_gpio_interface, address, name) OutputItem(output_gpio_interface, address, name),
deactivation_time(deactivation_time)
{ {
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
@@ -30,5 +31,15 @@ void Solenoid::trigger()
// deactivate // deactivate
} }
void Solenoid::activate()
{
}
void Solenoid::deactivate()
{
}
} /* namespace output */ } /* namespace output */
} }

View File

@@ -10,6 +10,10 @@
#include "OutputItem.h" #include "OutputItem.h"
#include <future>
#include <thread>
#include <chrono>
namespace flippR_driver namespace flippR_driver
{ {
namespace output namespace output
@@ -18,11 +22,18 @@ namespace output
class Solenoid : public OutputItem class Solenoid : public OutputItem
{ {
public: public:
Solenoid(std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface, int address, std::string name); Solenoid(std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface, int address, std::string name, std::chrono::milliseconds deactivation_time);
virtual ~Solenoid(); virtual ~Solenoid();
//muss task sein //muss task sein
void trigger(); void trigger();
private:
std::future<void> wait_thread;
std::chrono::milliseconds deactivation_time;
void activate();
void deactivate();
}; };
} /* namespace output */ } /* namespace output */