refactored utility namespace
This commit is contained in:
@@ -10,6 +10,9 @@
|
||||
|
||||
#include "ICabinetItem.h"
|
||||
|
||||
#include "utilities/IOutputGPIOInterface.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace FlippR_Driver
|
||||
@@ -20,8 +23,9 @@ namespace output
|
||||
class CabinetItem : public ICabinetItem
|
||||
{
|
||||
public:
|
||||
CabinetItem();
|
||||
CabinetItem(std::shared_ptr<IOutputGPIOInterface> output_gpio_interface, int address, std::string name);
|
||||
virtual ~CabinetItem();
|
||||
|
||||
virtual bool isActivated();
|
||||
virtual bool activate();
|
||||
virtual bool deactivate();
|
||||
|
||||
@@ -9,15 +9,16 @@
|
||||
|
||||
namespace FlippR_Driver
|
||||
{
|
||||
namespace output {
|
||||
namespace output
|
||||
{
|
||||
|
||||
Sound::Sound() {
|
||||
// TODO Auto-generated constructor stub
|
||||
Sound::Sound(std::shared_ptr<IOutputGPIOInterface> output_gpio_interface, int address, std::string name)
|
||||
: output_gpio_interface(output_gpio_interface), address(address), name(name)
|
||||
{}
|
||||
|
||||
}
|
||||
|
||||
Sound::~Sound() {
|
||||
// TODO Auto-generated destructor stub
|
||||
void Sound::play()
|
||||
{
|
||||
this->output_gpio_interface->activate(this);
|
||||
}
|
||||
|
||||
} /* namespace output */
|
||||
|
||||
@@ -10,8 +10,11 @@
|
||||
|
||||
#include "ISound.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "utilities/IOutputGPIOInterface.h"
|
||||
|
||||
namespace FlippR_Driver
|
||||
{
|
||||
namespace output
|
||||
@@ -20,12 +23,14 @@ namespace output
|
||||
class Sound : ISound
|
||||
{
|
||||
public:
|
||||
Sound();
|
||||
virtual ~Sound();
|
||||
Sound(std::shared_ptr<IOutputGPIOInterface> output_gpio_interface, int address, std::string name);
|
||||
virtual ~Sound() = default;
|
||||
|
||||
virtual void play();
|
||||
|
||||
private:
|
||||
std::shared_ptr<IOutputGPIOInterface> output_gpio_interface;
|
||||
|
||||
int address;
|
||||
std::string name;
|
||||
};
|
||||
|
||||
@@ -16,6 +16,11 @@
|
||||
|
||||
using namespace boost;
|
||||
|
||||
namespace FlippR_Driver
|
||||
{
|
||||
namespace utility
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
class BlockingQueue : public IBlockingQueue<T>
|
||||
{
|
||||
@@ -37,12 +42,15 @@ public:
|
||||
T pop()
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(this->d_mutex);
|
||||
this->d_condition.wait(lock, [=]{ return !this->p_queue.empty(); });
|
||||
this->d_condition.wait(lock, [=]
|
||||
{ return !this->p_queue.empty(); });
|
||||
T rc = *this->p_queue.begin();
|
||||
this->p_queue.pop();
|
||||
return rc;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -12,6 +12,11 @@
|
||||
#include "wiringPi/wiringPi.h"
|
||||
#include "json/json.hpp"
|
||||
|
||||
namespace FlippR_Driver
|
||||
{
|
||||
namespace utility
|
||||
{
|
||||
|
||||
std::once_flag GPIOInterface::GPIO_LIB_INITIALIZED;
|
||||
|
||||
void GPIOInterface::initialize_input_pin(char address)
|
||||
@@ -24,7 +29,6 @@ void GPIOInterface::write_pin(char address, char data)
|
||||
digitalWrite(address, data);
|
||||
}
|
||||
|
||||
|
||||
bool GPIOInterface::read_pin(char address)
|
||||
{
|
||||
return PULLDOWN == digitalRead(address);
|
||||
@@ -39,3 +43,5 @@ GPIOInterface::GPIOInterface()
|
||||
{
|
||||
std::call_once(GPIO_LIB_INITIALIZED, wiringPiSetup);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,13 +15,18 @@
|
||||
|
||||
#include <mutex>
|
||||
#include <fstream>
|
||||
namespace FlippR_Driver
|
||||
{
|
||||
namespace utility
|
||||
{
|
||||
|
||||
class GPIOInterface
|
||||
{
|
||||
public:
|
||||
GPIOInterface();
|
||||
|
||||
virtual ~GPIOInterface() {};
|
||||
virtual ~GPIOInterface()
|
||||
{};
|
||||
|
||||
static void initialize_input_pin(char address);
|
||||
|
||||
@@ -35,7 +40,8 @@ public:
|
||||
static std::once_flag GPIO_LIB_INITIALIZED;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -8,15 +8,23 @@
|
||||
#ifndef SRC_UTILITIES_IBLOCKINGQUEUE_H_
|
||||
#define SRC_UTILITIES_IBLOCKINGQUEUE_H_
|
||||
|
||||
namespace FlippR_Driver
|
||||
{
|
||||
namespace utility
|
||||
{
|
||||
template<typename T>
|
||||
class IBlockingQueue
|
||||
{
|
||||
public:
|
||||
virtual ~IBlockingQueue(){};
|
||||
virtual ~IBlockingQueue()
|
||||
{};
|
||||
|
||||
virtual void push(T const &value) = 0;
|
||||
virtual T pop() = 0;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -8,13 +8,21 @@
|
||||
#ifndef SRC_UTILITIES_IINPUTGPIOINTERFACE_H_
|
||||
#define SRC_UTILITIES_IINPUTGPIOINTERFACE_H_
|
||||
|
||||
namespace FlippR_Driver
|
||||
{
|
||||
namespace utility
|
||||
{
|
||||
|
||||
class IInputGPIOInterface
|
||||
{
|
||||
public:
|
||||
virtual ~IInputGPIOInterface(){};
|
||||
virtual ~IInputGPIOInterface()
|
||||
{};
|
||||
|
||||
virtual bool read_data(char pin) = 0;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -5,8 +5,16 @@
|
||||
#ifndef FLIPPR_DRIVER_IOUTPUTGPIOINTERFACE_H
|
||||
#define FLIPPR_DRIVER_IOUTPUTGPIOINTERFACE_H
|
||||
|
||||
namespace FlippR_Driver
|
||||
{
|
||||
namespace utility
|
||||
{
|
||||
|
||||
class IOutputGPIOInterface
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
#endif //FLIPPR_DRIVER_IOUTPUTGPIOINTERFACE_H
|
||||
@@ -13,6 +13,11 @@
|
||||
#include "easylogging/easylogging++.h"
|
||||
#include "config.h"
|
||||
#include <string>
|
||||
namespace FlippR_Driver
|
||||
{
|
||||
namespace utility
|
||||
{
|
||||
|
||||
using namespace nlohmann;
|
||||
|
||||
bool InputGPIOInterface::read_data(char pin)
|
||||
@@ -41,7 +46,6 @@ void InputGPIOInterface::write_col(char data)
|
||||
write_pin(this->col_address_C, data & 0b100);
|
||||
}
|
||||
|
||||
|
||||
InputGPIOInterface::InputGPIOInterface(std::istream &input_config_stream)
|
||||
{
|
||||
init_members(input_config_stream);
|
||||
@@ -54,7 +58,8 @@ void InputGPIOInterface::init_members(std::istream &input_config_stream)
|
||||
json input_config;
|
||||
input_config_stream >> input_config;
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
json row_json = input_config.at("row");
|
||||
row_address_A = row_json.at("A").get<json::number_integer_t>();
|
||||
row_address_B = row_json.at("B").get<json::number_integer_t>();
|
||||
@@ -66,9 +71,13 @@ void InputGPIOInterface::init_members(std::istream &input_config_stream)
|
||||
col_address_C = col_json.at("C").get<json::number_integer_t>();
|
||||
|
||||
data_address = input_config.at("data").get<json::number_integer_t>();
|
||||
} catch (json::type_error& e) {
|
||||
}
|
||||
catch(json::type_error &e)
|
||||
{
|
||||
CLOG(ERROR, INPUT_LOGGER) << e.what();
|
||||
} catch (json::out_of_range& e) {
|
||||
}
|
||||
catch(json::out_of_range &e)
|
||||
{
|
||||
CLOG(ERROR, INPUT_LOGGER) << e.what();
|
||||
}
|
||||
}
|
||||
@@ -85,3 +94,6 @@ void InputGPIOInterface::init_pins()
|
||||
|
||||
initialize_input_pin(data_address);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,11 @@
|
||||
#include "IInputGPIOInterface.h"
|
||||
#include "GPIOInterface.h"
|
||||
|
||||
namespace FlippR_Driver
|
||||
{
|
||||
namespace utility
|
||||
{
|
||||
|
||||
class InputGPIOInterface : public IInputGPIOInterface, GPIOInterface
|
||||
{
|
||||
public:
|
||||
@@ -34,4 +39,6 @@ private:
|
||||
char data_address;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -10,6 +10,11 @@
|
||||
#define EASYLOGGING_IS_INITIALIZED
|
||||
INITIALIZE_EASYLOGGINGPP
|
||||
#endif
|
||||
|
||||
namespace FlippR_Driver
|
||||
{
|
||||
namespace utility
|
||||
{
|
||||
namespace LoggerFactory
|
||||
{
|
||||
|
||||
@@ -60,3 +65,6 @@ void CreateOutputLogger(el::Level level)
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,11 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
namespace FlippR_Driver
|
||||
{
|
||||
namespace utility
|
||||
{
|
||||
|
||||
namespace LoggerFactory
|
||||
{
|
||||
void CreateInputTestLogger(el::Level level = el::Level::Global);
|
||||
@@ -19,4 +24,6 @@ namespace LoggerFactory
|
||||
void CreateOutputLogger(el::Level level = el::Level::Info);
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -11,6 +11,10 @@
|
||||
#include "GPIOInterface.h"
|
||||
#include <mcp23017.h>
|
||||
|
||||
namespace FlippR_Driver
|
||||
{
|
||||
namespace utility
|
||||
{
|
||||
class OutputGPIOInterface : GPIOInterface
|
||||
{
|
||||
|
||||
@@ -24,6 +28,7 @@ private:
|
||||
IBlockingQueue <CabinetItem> event_queue;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user