From 21565631be8731e4d52539aa5c17523771ffd88d Mon Sep 17 00:00:00 2001 From: Jonas Zeunert Date: Thu, 31 May 2018 15:46:41 +0200 Subject: [PATCH] dereviated gpiointerface --- FlippR-Driver/src/input/Detector.h | 3 +- FlippR-Driver/src/utilities/GPIOInterface.cpp | 48 ------------------- FlippR-Driver/src/utilities/GPIOInterface.h | 48 ------------------- FlippR-Driver/src/utilities/GPIOInterface.hpp | 46 ++++++++++++++++++ .../src/utilities/InputGPIOInterface.cpp | 32 +++++++++++++ .../src/utilities/InputGPIOInterface.h | 29 +++++++++++ .../src/utilities/OutputGPIOInterface.h | 19 ++++++++ 7 files changed, 127 insertions(+), 98 deletions(-) delete mode 100644 FlippR-Driver/src/utilities/GPIOInterface.cpp delete mode 100644 FlippR-Driver/src/utilities/GPIOInterface.h create mode 100644 FlippR-Driver/src/utilities/GPIOInterface.hpp create mode 100644 FlippR-Driver/src/utilities/InputGPIOInterface.cpp create mode 100644 FlippR-Driver/src/utilities/InputGPIOInterface.h create mode 100644 FlippR-Driver/src/utilities/OutputGPIOInterface.h diff --git a/FlippR-Driver/src/input/Detector.h b/FlippR-Driver/src/input/Detector.h index 00bcf11..7feec1a 100644 --- a/FlippR-Driver/src/input/Detector.h +++ b/FlippR-Driver/src/input/Detector.h @@ -17,8 +17,7 @@ #include #include -#include "../utilities/GPIOInterface.h" - +#include "../utilities/GPIOInterface.hpp" #include "InputEvent.h" #include "InputEventNotifier.h" diff --git a/FlippR-Driver/src/utilities/GPIOInterface.cpp b/FlippR-Driver/src/utilities/GPIOInterface.cpp deleted file mode 100644 index cd20e47..0000000 --- a/FlippR-Driver/src/utilities/GPIOInterface.cpp +++ /dev/null @@ -1,48 +0,0 @@ - -/* - * GPIOInterface.cpp - * - * Created on: May 17, 2018 - * Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert, Rafael Vinci, Dr. Franca Rupprecht - */ - -#include "GPIOInterface.h" - -#include "../lib/wiringPi/wiringPi.h" - -GPIOInterface::GPIOInterface(std::string config_path) -{ -} - -GPIOInterface::~GPIOInterface() -{ -} - -bool GPIOInterface::read_input_data() -{ - return read_input_pin(input_data_address); -} - -void GPIOInterface::write_input_row(char data) -{ - write_pin(input_row_address, data & 0b001); - write_pin(input_row_address, data & 0b010); - write_pin(input_row_address, data & 0b100); -} - -void GPIOInterface::write_input_col(char data) -{ - write_pin(input_col_address, data & 0b001); - write_pin(input_col_address, data & 0b010); - write_pin(input_col_address, data & 0b100); -} - -void GPIOInterface::write_pin(char address, bool data) -{ - digitalWrite(address, data); -} - -bool GPIOInterface::read_input_pin(char address) -{ - return digitalRead(address); -} diff --git a/FlippR-Driver/src/utilities/GPIOInterface.h b/FlippR-Driver/src/utilities/GPIOInterface.h deleted file mode 100644 index 0eba47b..0000000 --- a/FlippR-Driver/src/utilities/GPIOInterface.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * GPIOInterface.hpp - * - * Responsible for communicating with the actual GPIO hardware. - * - * Gets a JSON file with following style: - * TODO - * - * Created on: May 6, 2018 - * Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert, Rafael Vinci, Dr. Franca Rupprecht - */ - -#ifndef SRC_UTILITIES_GPIOINTERFACE_H_ -#define SRC_UTILITIES_GPIOINTERFACE_H_ - -#include - -#include "../lib/json/json.hpp" - -using namespace nlohmann; - -class GPIOInterface -{ -public: - GPIOInterface(std::string config_path); - ~GPIOInterface(); - - void write_input_row(char data); - void write_input_col(char data); - bool read_input_data(); - -private: - static void write_pin(char address, bool data); - static bool read_input_pin(char address); - -private: - json config; - - char input_row_address; - char input_col_address; - char input_data_address; - -}; - - - - -#endif /* SRC_UTILITIES_GPIOINTERFACE_H_ */ diff --git a/FlippR-Driver/src/utilities/GPIOInterface.hpp b/FlippR-Driver/src/utilities/GPIOInterface.hpp new file mode 100644 index 0000000..43db3e2 --- /dev/null +++ b/FlippR-Driver/src/utilities/GPIOInterface.hpp @@ -0,0 +1,46 @@ +/* + * GPIOInterface.hpp + * + * Responsible for communicating with the actual GPIO hardware. + * + * Gets a JSON file with following style: + * TODO + * + * Created on: May 6, 2018 + * Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert, Rafael Vinci, Dr. Franca Rupprecht + */ + +#ifndef SRC_UTILITIES_GPIOINTERFACE_HPP_ +#define SRC_UTILITIES_GPIOINTERFACE_HPP_ + +#include + +#include "../lib/json/json.hpp" +#include "../lib/wiringPi/wiringPi.h" + +using namespace nlohmann; + +class GPIOInterface +{ +public: + GPIOInterface(std::string config_path) = 0; + ~GPIOInterface(); + + static void write_pin(char address, char data) + { + digitalWrite(address, data); + } + + static bool read_pin(char address) + { + return digitalRead(address); + } + +protected: + json config; +}; + + + + +#endif /* SRC_UTILITIES_GPIOINTERFACE_HPP_ */ diff --git a/FlippR-Driver/src/utilities/InputGPIOInterface.cpp b/FlippR-Driver/src/utilities/InputGPIOInterface.cpp new file mode 100644 index 0000000..db57142 --- /dev/null +++ b/FlippR-Driver/src/utilities/InputGPIOInterface.cpp @@ -0,0 +1,32 @@ +/* + * InputGPIOInterface.cpp + * + * Created on: May 31, 2018 + * Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert, Rafael Vinci, Dr. Franca Rupprecht + */ +#include "InputGPIOInterface.h" + + +class InputGPIOInterface +{ + +bool InputGPIOInterface::read_input_data() +{ + return read_pin(this->input_data_address); +} + +void InputGPIOInterface::write_input_row(char data) +{ + write_pin(this->input_row_address, data & 0b001); + write_pin(this->input_row_address, data & 0b010); + write_pin(this->input_row_address, data & 0b100); +} + +void InputGPIOInterface::write_input_col(char data) +{ + write_pin(this->input_col_address, data & 0b001); + write_pin(this->input_col_address, data & 0b010); + write_pin(this->input_col_address, data & 0b100); +} + +}; diff --git a/FlippR-Driver/src/utilities/InputGPIOInterface.h b/FlippR-Driver/src/utilities/InputGPIOInterface.h new file mode 100644 index 0000000..0c8cabe --- /dev/null +++ b/FlippR-Driver/src/utilities/InputGPIOInterface.h @@ -0,0 +1,29 @@ +/* + * InputGPIOInterface.h + * + * Created on: May 31, 2018 + * Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert, Rafael Vinci, Dr. Franca Rupprecht + */ + +#ifndef SRC_UTILITIES_INPUTGPIOINTERFACE_H_ +#define SRC_UTILITIES_INPUTGPIOINTERFACE_H_ + +#include "GPIOInterface.hpp" + +class InputGPIOInterface : GPIOInterface +{ +public: + + void write_input_row(char data); + void write_input_col(char data); + bool read_input_data(); + +private: + char input_row_address; + char input_col_address; + char input_data_address; +}; + + + +#endif /* SRC_UTILITIES_INPUTGPIOINTERFACE_H_ */ diff --git a/FlippR-Driver/src/utilities/OutputGPIOInterface.h b/FlippR-Driver/src/utilities/OutputGPIOInterface.h new file mode 100644 index 0000000..3b64b6e --- /dev/null +++ b/FlippR-Driver/src/utilities/OutputGPIOInterface.h @@ -0,0 +1,19 @@ +/* + * OutputGPIOInterface.h + * + * Created on: May 31, 2018 + * Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert, Rafael Vinci, Dr. Franca Rupprecht + */ + +#ifndef SRC_UTILITIES_OUTPUTGPIOINTERFACE_H_ +#define SRC_UTILITIES_OUTPUTGPIOINTERFACE_H_ + +#include "GPIOInterface.hpp" + +class OutputGPIOInterface : GPIOInterface +{ + +}; + + +#endif /* SRC_UTILITIES_OUTPUTGPIOINTERFACE_H_ */