refactored namespaces
This commit is contained in:
51
FlippR-Driver/src/output/items/Display.h
Normal file
51
FlippR-Driver/src/output/items/Display.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Display.h
|
||||
*
|
||||
* Created on: Aug 2, 2018
|
||||
* Author: rhetenor
|
||||
*/
|
||||
|
||||
#ifndef _SRC_OUTPUT_DISPLAY_H_
|
||||
#define _SRC_OUTPUT_DISPLAY_H_
|
||||
|
||||
#include "IDisplay.h"
|
||||
|
||||
#include <array>
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
namespace items
|
||||
{
|
||||
|
||||
template<int DigitCount>
|
||||
class Display : public IDisplay<DigitCount>
|
||||
{
|
||||
public:
|
||||
Display(int address, int id);
|
||||
virtual ~Display() = default;
|
||||
|
||||
virtual int getID();
|
||||
|
||||
virtual void write_score(int score);
|
||||
virtual void write_content(std::array<char, DigitCount> content);
|
||||
|
||||
public:
|
||||
std::array<char, DigitCount> content;
|
||||
|
||||
private:
|
||||
int address;
|
||||
int id;
|
||||
|
||||
std::string fit_string(std::string &score_string);
|
||||
};
|
||||
|
||||
}
|
||||
} /* namespace output */
|
||||
}
|
||||
|
||||
#include "Display.hpp"
|
||||
|
||||
|
||||
#endif
|
||||
66
FlippR-Driver/src/output/items/Display.hpp
Normal file
66
FlippR-Driver/src/output/items/Display.hpp
Normal file
@@ -0,0 +1,66 @@
|
||||
//
|
||||
// Created by rhetenor on 10.10.18.
|
||||
//
|
||||
|
||||
#include "utility/config.h"
|
||||
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
namespace items
|
||||
{
|
||||
|
||||
template<int DigitCount>
|
||||
Display<DigitCount>::Display(int address, int id) :
|
||||
address(address),
|
||||
id(id)
|
||||
{
|
||||
}
|
||||
|
||||
template<int DigitCount>
|
||||
int Display<DigitCount>::getID()
|
||||
{
|
||||
return this->id;
|
||||
}
|
||||
|
||||
template<int DigitCount>
|
||||
void Display<DigitCount>::write_score(int score)
|
||||
{
|
||||
auto score_string = std::to_string(score);
|
||||
|
||||
auto score_c_string = this->fit_string(score_string).c_str();
|
||||
|
||||
std::copy(std::begin(score_c_string), std::end(score_c_string), std::begin(this->content));
|
||||
}
|
||||
|
||||
template<int DigitCount>
|
||||
std::string Display<DigitCount>::fit_string(std::string& score_string)
|
||||
{
|
||||
auto score_length = score_string.length();
|
||||
|
||||
if (score_length > DigitCount)
|
||||
{
|
||||
CLOG(DEBUG, OUTPUT_LOGGER) << "Score too long for display";
|
||||
std::string full_display;
|
||||
// TODO mach mal schöner hier wird 9999 angezeigt wenn die zahl zu groß is
|
||||
return full_display.insert(0, DigitCount, '9');
|
||||
}
|
||||
|
||||
score_string.insert(0, DigitCount-score_length, '\0');
|
||||
return score_string;
|
||||
}
|
||||
|
||||
template<int DigitCount>
|
||||
void Display<DigitCount>::write_content( std::array<char, DigitCount> content)
|
||||
{
|
||||
this->content = content;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
22
FlippR-Driver/src/output/items/EightDigitDisplay.h
Normal file
22
FlippR-Driver/src/output/items/EightDigitDisplay.h
Normal file
@@ -0,0 +1,22 @@
|
||||
//
|
||||
// Created by rhetenor on 20.11.18.
|
||||
//
|
||||
|
||||
#ifndef FLIPPR_DRIVER_EIGHTDIGITDISPLAY_H
|
||||
#define FLIPPR_DRIVER_EIGHTDIGITDISPLAY_H
|
||||
|
||||
#include "IEightDigitDisplay"
|
||||
|
||||
namespace flippr_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
namespace items
|
||||
{
|
||||
|
||||
class EightDigitDisplay : public Display<8>, IEightDigitDisplay;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif //FLIPPR_DRIVER_EIGHTDIGITDISPLAY_H
|
||||
33
FlippR-Driver/src/output/items/IDisplay.h
Normal file
33
FlippR-Driver/src/output/items/IDisplay.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* IDisplay.h
|
||||
*
|
||||
* Created on: Aug 2, 2018
|
||||
* Author: rhetenor
|
||||
*/
|
||||
|
||||
#ifndef _SRC_OUTPUT_IDISPLAY_H_
|
||||
#define _SRC_OUTPUT_IDISPLAY_H_
|
||||
|
||||
#include <array>
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
namespace items
|
||||
{
|
||||
|
||||
class IDisplay
|
||||
{
|
||||
|
||||
public:
|
||||
IDisplay();
|
||||
virtual ~IDisplay();
|
||||
|
||||
virtual int getID() = 0;
|
||||
};
|
||||
|
||||
}
|
||||
} /* namespace output */
|
||||
}
|
||||
#endif
|
||||
34
FlippR-Driver/src/output/items/IOutputDisplay.h
Normal file
34
FlippR-Driver/src/output/items/IOutputDisplay.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* IOutputDisplay.h
|
||||
*
|
||||
* Created on: Nov 20, 2018
|
||||
* Author: johannes
|
||||
*/
|
||||
|
||||
#ifndef SRC_OUTPUT_IOUTPUTDISPLAY_H_
|
||||
#define SRC_OUTPUT_IOUTPUTDISPLAY_H_
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
namespace items
|
||||
{
|
||||
|
||||
class IDisplay
|
||||
{
|
||||
|
||||
public:
|
||||
IDisplay();
|
||||
virtual ~IDisplay();
|
||||
|
||||
virtual void write_score(int score) = 0;
|
||||
virtual void write_content(std::array<char, DigitCount> content) = 0;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif /* SRC_OUTPUT_IOUTPUTDISPLAY_H_ */
|
||||
31
FlippR-Driver/src/output/items/IOutputItem.h
Normal file
31
FlippR-Driver/src/output/items/IOutputItem.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* ICabinetItem.h
|
||||
*
|
||||
* Created on: Aug 7, 2018
|
||||
* Author: rhetenor
|
||||
*/
|
||||
|
||||
#ifndef _SRC_OUTPUT_ICABINETITEM_H_
|
||||
#define _SRC_OUTPUT_ICABINETITEM_H_
|
||||
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
namespace items
|
||||
{
|
||||
|
||||
class IOutputItem
|
||||
{
|
||||
virtual ~IOutputItem();
|
||||
virtual bool isActivated() = 0;
|
||||
virtual bool activate() = 0;
|
||||
virtual bool deactivate() = 0;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
35
FlippR-Driver/src/output/items/Lamp.cpp
Normal file
35
FlippR-Driver/src/output/items/Lamp.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Lamp.cpp
|
||||
*
|
||||
* Created on: Aug 2, 2018
|
||||
* Author: rhetenor
|
||||
*/
|
||||
|
||||
#include "Lamp.h"
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
namespace items
|
||||
{
|
||||
|
||||
Lamp::Lamp(std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface, int i2c_address, int data_pin, std::string name, bool activated)
|
||||
:
|
||||
OutputItem(output_gpio_interface, i2c_address, data_pin, name),
|
||||
activated(activated)
|
||||
{}
|
||||
|
||||
void Lamp::activate()
|
||||
{
|
||||
OutputItem::activate();
|
||||
}
|
||||
|
||||
void Lamp::deactivate()
|
||||
{
|
||||
OutputItem::deactivate();
|
||||
}
|
||||
|
||||
}
|
||||
} /* namespace output */
|
||||
}
|
||||
38
FlippR-Driver/src/output/items/Lamp.h
Normal file
38
FlippR-Driver/src/output/items/Lamp.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Lamp.h
|
||||
*
|
||||
* Created on: Aug 2, 2018
|
||||
* Author: rhetenor
|
||||
*/
|
||||
|
||||
#ifndef _SRC_OUTPUT_LAMP_H_
|
||||
#define _SRC_OUTPUT_LAMP_H_
|
||||
|
||||
#include "OutputItem.h"
|
||||
#include "../../../include/output/output_items/ILamp.h"
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
namespace items
|
||||
{
|
||||
|
||||
class Lamp : public OutputItem, ILamp
|
||||
{
|
||||
public:
|
||||
Lamp(std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface, int i2c_address, int data_pin, std::string name, bool activated = false);
|
||||
virtual ~Lamp() = default;
|
||||
|
||||
void activate();
|
||||
void deactivate();
|
||||
bool is_activated();
|
||||
|
||||
private:
|
||||
bool activated;
|
||||
};
|
||||
|
||||
}
|
||||
} /* namespace output */
|
||||
}
|
||||
#endif
|
||||
44
FlippR-Driver/src/output/items/OutputItem.h
Normal file
44
FlippR-Driver/src/output/items/OutputItem.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* CabinetItem.h
|
||||
*
|
||||
* Created on: Aug 2, 2018
|
||||
* Author: rhetenor
|
||||
*/
|
||||
|
||||
#ifndef _SRC_OUTPUT_CABINETITEM_H_
|
||||
#define _SRC_OUTPUT_CABINETITEM_H_
|
||||
|
||||
#include "IOutputItem.h"
|
||||
|
||||
#include "utility/IOutputGPIOInterface.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
namespace items
|
||||
{
|
||||
|
||||
class OutputItem : public IOutputItem
|
||||
{
|
||||
public:
|
||||
OutputItem(std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface, int i2c_address, int data_pin_address, std::string name);
|
||||
virtual ~OutputItem();
|
||||
|
||||
protected:
|
||||
int i2c_address, data_pin_address;
|
||||
std::string name;
|
||||
|
||||
std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface;
|
||||
|
||||
void activate();
|
||||
void deactivate();
|
||||
};
|
||||
|
||||
}
|
||||
} /* namespace output */
|
||||
}
|
||||
#endif
|
||||
20
FlippR-Driver/src/output/items/SevenDigitDisplay.h
Normal file
20
FlippR-Driver/src/output/items/SevenDigitDisplay.h
Normal file
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// Created by rhetenor on 20.11.18.
|
||||
//
|
||||
|
||||
#ifndef FLIPPR_DRIVER_SEVENDIGITDISPLAY_H
|
||||
#define FLIPPR_DRIVER_SEVENDIGITDISPLAY_H
|
||||
|
||||
namespace flippr_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
namespace items
|
||||
{
|
||||
|
||||
class SevenDigitDisplay : public Display<7>, ISevenDigitDisplay;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif //FLIPPR_DRIVER_SEVENDIGITDISPLAY_H
|
||||
37
FlippR-Driver/src/output/items/Solenoid.cpp
Normal file
37
FlippR-Driver/src/output/items/Solenoid.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Solenoid.cpp
|
||||
*
|
||||
* Created on: Aug 2, 2018
|
||||
* Author: rhetenor
|
||||
*/
|
||||
|
||||
#include "Solenoid.h"
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
namespace items
|
||||
{
|
||||
Solenoid::Solenoid(std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface, int i2c_address, int data_pin, std::string name, std::chrono::milliseconds deactivation_time)
|
||||
:
|
||||
OutputItem(output_gpio_interface, i2c_address, data_pin, name),
|
||||
deactivation_time(deactivation_time)
|
||||
{}
|
||||
|
||||
void Solenoid::triggerTask()
|
||||
{
|
||||
OutputItem::activate();
|
||||
|
||||
std::this_thread::sleep_for(50 /*todo change magic number */);
|
||||
|
||||
OutputItem::deactivate();
|
||||
}
|
||||
void Solenoid::trigger()
|
||||
{
|
||||
std::async(std::launch::async, &Solenoid::triggerTask);
|
||||
}
|
||||
|
||||
}
|
||||
} /* namespace output */
|
||||
}
|
||||
39
FlippR-Driver/src/output/items/Solenoid.h
Normal file
39
FlippR-Driver/src/output/items/Solenoid.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Solenoid.h
|
||||
*
|
||||
* Created on: Aug 2, 2018
|
||||
* Author: rhetenor
|
||||
*/
|
||||
|
||||
#ifndef _SRC_OUTPUT_SOLENOID_H_
|
||||
#define _SRC_OUTPUT_SOLENOID_H_
|
||||
|
||||
#include "OutputItem.h"
|
||||
#include "../../../include/output/output_items/ISolenoid.h"
|
||||
|
||||
#include <future>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
namespace items
|
||||
{
|
||||
|
||||
class Solenoid : public ISolenoid, OutputItem
|
||||
{
|
||||
public:
|
||||
Solenoid(std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface, int i2c_address, int data_pin, std::string name, std::chrono::milliseconds deactivation_time);
|
||||
virtual ~Solenoid() = default;
|
||||
|
||||
void trigger();
|
||||
|
||||
private:
|
||||
virtual void triggerTask();
|
||||
|
||||
}
|
||||
} /* namespace output */
|
||||
}
|
||||
#endif
|
||||
40
FlippR-Driver/src/output/items/Sound.cpp
Normal file
40
FlippR-Driver/src/output/items/Sound.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Sound.cpp
|
||||
*
|
||||
* Created on: Aug 2, 2018
|
||||
* Author: rhetenor
|
||||
*/
|
||||
|
||||
#include "Sound.h"
|
||||
|
||||
#include <future>
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
namespace items
|
||||
{
|
||||
|
||||
Sound::Sound(std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface, int i2c_address, int data_pin, std::string name)
|
||||
:
|
||||
OutputItem(output_gpio_interface, i2c_address, data_pin, name)
|
||||
{}
|
||||
|
||||
void Sound::play()
|
||||
{
|
||||
std::async(std::launch::async, &Sound::playTask);
|
||||
}
|
||||
|
||||
void Sound::playTask()
|
||||
{
|
||||
OutputItem::activate();
|
||||
|
||||
std::this_thread::sleep_for(50 /*todo change magic number */);
|
||||
|
||||
OutputItem::deactivate();
|
||||
}
|
||||
|
||||
}
|
||||
} /* namespace output */
|
||||
}
|
||||
40
FlippR-Driver/src/output/items/Sound.h
Normal file
40
FlippR-Driver/src/output/items/Sound.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Sound.h
|
||||
*
|
||||
* Created on: Aug 2, 2018
|
||||
* Author: rhetenor
|
||||
*/
|
||||
|
||||
#ifndef _SRC_OUTPUT_SOUND_H_
|
||||
#define _SRC_OUTPUT_SOUND_H_
|
||||
|
||||
#include "../../../include/output/output_items/ISound.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "utility/IOutputGPIOInterface.h"
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
namespace items
|
||||
{
|
||||
|
||||
class Sound : public ISound, OutputItem
|
||||
{
|
||||
public:
|
||||
Sound(std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface, int i2c_address, int data_pin, std::string name);
|
||||
virtual ~Sound() = default;
|
||||
|
||||
virtual void play();
|
||||
|
||||
private:
|
||||
virtual void playTask();
|
||||
};
|
||||
|
||||
}
|
||||
} /* namespace output */
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user