refactored outpugpiointerface
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include "utility/IInputGPIOInterface.h"
|
||||
#include "IInputGPIOInterface.h"
|
||||
|
||||
#include "IDetector.h"
|
||||
#include "DistributingEvent.h"
|
||||
|
||||
28
FlippR-Driver/src/input/IInputGPIOInterface.h
Normal file
28
FlippR-Driver/src/input/IInputGPIOInterface.h
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* InputGPIOInterface.h
|
||||
*
|
||||
* Created on: May 31, 2018
|
||||
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
|
||||
*/
|
||||
|
||||
#ifndef SRC_UTILITIES_IINPUTGPIOINTERFACE_H_
|
||||
#define SRC_UTILITIES_IINPUTGPIOINTERFACE_H_
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace utility
|
||||
{
|
||||
|
||||
class IInputGPIOInterface
|
||||
{
|
||||
public:
|
||||
virtual ~IInputGPIOInterface()
|
||||
{};
|
||||
|
||||
virtual bool read_data(char pin) = 0;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -14,7 +14,7 @@
|
||||
#include "Detector.h"
|
||||
#include "input/IInputDriver.h"
|
||||
|
||||
#include "utility/InputGPIOInterface.h"
|
||||
#include "InputGPIOInterface.h"
|
||||
#include "json/json.hpp"
|
||||
#include "IEventNotifier.h"
|
||||
|
||||
|
||||
99
FlippR-Driver/src/input/InputGPIOInterface.cpp
Normal file
99
FlippR-Driver/src/input/InputGPIOInterface.cpp
Normal file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* InputGPIOInterface.cpp
|
||||
*
|
||||
* Created on: May 31, 2018
|
||||
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
|
||||
*/
|
||||
|
||||
#include <fstream>
|
||||
#include <thread>
|
||||
|
||||
#include "InputGPIOInterface.h"
|
||||
#include "json/json.hpp"
|
||||
#include "easylogging/easylogging++.h"
|
||||
#include "utility/config.h"
|
||||
#include <string>
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace utility
|
||||
{
|
||||
|
||||
using namespace nlohmann;
|
||||
|
||||
InputGPIOInterface::InputGPIOInterface(std::istream &input_config)
|
||||
{
|
||||
init_members(input_config);
|
||||
|
||||
init_pins();
|
||||
}
|
||||
|
||||
bool InputGPIOInterface::read_data(char pin)
|
||||
{
|
||||
// setting address to read
|
||||
write_row(pin / INPUT_MATRIX_SIZE);
|
||||
write_col(pin % INPUT_MATRIX_SIZE);
|
||||
|
||||
// wait for mux to set address
|
||||
std::this_thread::sleep_for(std::chrono::nanoseconds(INPUT_SLEEP_DURATION_NANO));
|
||||
|
||||
return read_pin(this->data_address);
|
||||
}
|
||||
|
||||
void InputGPIOInterface::write_row(char data)
|
||||
{
|
||||
write_pin(this->row_address_A, data & 0b001);
|
||||
write_pin(this->row_address_B, data & 0b010);
|
||||
write_pin(this->row_address_C, data & 0b100);
|
||||
}
|
||||
|
||||
void InputGPIOInterface::write_col(char data)
|
||||
{
|
||||
write_pin(this->col_address_A, data & 0b001);
|
||||
write_pin(this->col_address_B, data & 0b010);
|
||||
write_pin(this->col_address_C, data & 0b100);
|
||||
}
|
||||
|
||||
void InputGPIOInterface::init_members(std::istream &input_config_stream)
|
||||
{
|
||||
json input_config;
|
||||
input_config_stream >> input_config;
|
||||
|
||||
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>();
|
||||
row_address_C = row_json.at("C").get<json::number_integer_t>();
|
||||
|
||||
json col_json = input_config.at("col");
|
||||
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_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)
|
||||
{
|
||||
CLOG(ERROR, INPUT_LOGGER) << e.what();
|
||||
}
|
||||
catch(json::out_of_range &e)
|
||||
{
|
||||
CLOG(ERROR, INPUT_LOGGER) << e.what();
|
||||
}
|
||||
}
|
||||
|
||||
void InputGPIOInterface::init_pins()
|
||||
{
|
||||
initialize_output_pin(col_address_A);
|
||||
initialize_output_pin(col_address_B);
|
||||
initialize_output_pin(col_address_C);
|
||||
|
||||
initialize_output_pin(row_address_A);
|
||||
initialize_output_pin(row_address_B);
|
||||
initialize_output_pin(row_address_C);
|
||||
|
||||
initialize_input_pin(data_address);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
44
FlippR-Driver/src/input/InputGPIOInterface.h
Normal file
44
FlippR-Driver/src/input/InputGPIOInterface.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* InputGPIOInterface.h
|
||||
*
|
||||
* Created on: May 31, 2018
|
||||
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
|
||||
*/
|
||||
|
||||
#ifndef SRC_UTILITIES_INPUTGPIOINTERFACE_H_
|
||||
#define SRC_UTILITIES_INPUTGPIOINTERFACE_H_
|
||||
|
||||
#include <exception>
|
||||
#include "IInputGPIOInterface.h"
|
||||
#include "GPIOInterface.h"
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace utility
|
||||
{
|
||||
|
||||
class InputGPIOInterface : public IInputGPIOInterface, GPIOInterface
|
||||
{
|
||||
public:
|
||||
InputGPIOInterface(std::istream &input_config);
|
||||
bool read_data(char pin);
|
||||
|
||||
private:
|
||||
void init_members(std::istream &input_config_stream);
|
||||
void init_pins();
|
||||
void write_row(char data);
|
||||
void write_col(char data);
|
||||
|
||||
private:
|
||||
char row_address_A;
|
||||
char row_address_B;
|
||||
char row_address_C;
|
||||
char col_address_A;
|
||||
char col_address_B;
|
||||
char col_address_C;
|
||||
char data_address;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user