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