gpio.h
Go to the documentation of this file.
1 
5 #pragma once
6 
7 #include <string>
8 #include <iostream>
9 #include <map>
10 #include "files.h"
11 
12 #include <boost/system/error_code.hpp>
13 
14 #ifdef TESTING
15 #include "gtest/gtest.h"
16 #endif
17 
18 namespace dpyUtilsGpio {
19 
20 #define EXPORT_GPIO_PATH "/sys/class/gpio/export"
21 #define UNEXPORT_GPIO_PATH "/sys/class/gpio/unexport"
22 #define GPIO_PATH "/sys/class/gpio/gpio"
23 
26 enum DIRECTION
27 {
30 };
31 
35 enum VALUE
36 {
37  PIN_OFF = 0,
38  PIN_ON = 1
39 };
40 
44 enum EDGE
45 {
46  NONE,
50 };
51 
56 {
57  DO0,
58  DO1,
59  DO2,
60  DI0,
61  DI1,
62  DI2
63 };
64 
68 struct Edge
69 {
70  std::string sEdge;
71  enum EDGE edge;
72 };
73 
74 }
75 static std::map<int, dpyUtilsGpio::Edge> s_mapEdge;
76 
80 static std::map<dpyUtilsGpio::Functionality, std::string> EP100GpioNumMap = { {dpyUtilsGpio::DO0, "115"}, {dpyUtilsGpio::DO1, "121"}, {dpyUtilsGpio::DO2, "122"}, {dpyUtilsGpio::DI0, "65"}, {dpyUtilsGpio::DI1, "66"}, {dpyUtilsGpio::DI2, "67"}};
81 
89 class Gpio
90 {
91 protected:
92  std::string gpionum;
94 private:
95  void createEdgeMap();
96  std::string getGpioNum();
97 
98 public:
99  explicit Gpio(std::string gnum);
100  explicit Gpio(enum dpyUtilsGpio::Functionality);
101  Gpio();
106  Gpio(const Gpio& b);
107  virtual ~Gpio();
108  bool switchGpioOptions(boost::system::error_code& ec, const enum dpyUtilsGpio::DIRECTION dir, const enum dpyUtilsGpio::VALUE value);
109  bool createGpio(boost::system::error_code& ec);
110  bool deleteGpio(boost::system::error_code& ec);
111 #ifdef TESTING
112  virtual bool setDirectionGpio(boost::system::error_code& ec, const enum dpyUtilsGpio::DIRECTION dir);
113  virtual bool getDirectionGpio(boost::system::error_code& ec, enum dpyUtilsGpio::DIRECTION& dir);
114  virtual bool setValueGpio(boost::system::error_code& ec, const dpyUtilsGpio::VALUE value);
115  virtual bool getValueGpio(boost::system::error_code& ec, enum dpyUtilsGpio::VALUE& value);
116  virtual bool getEdgeGpio(boost::system::error_code& ec, enum dpyUtilsGpio::EDGE& edge);
117 #else
118  bool setDirectionGpio(boost::system::error_code& ec, const enum dpyUtilsGpio::DIRECTION dir);
119  bool getDirectionGpio(boost::system::error_code& ec, enum dpyUtilsGpio::DIRECTION& dir);
120  bool setValueGpio(boost::system::error_code& ec, const dpyUtilsGpio::VALUE value);
121  bool getValueGpio(boost::system::error_code& ec, enum dpyUtilsGpio::VALUE& value);
122  bool getEdgeGpio(boost::system::error_code& ec, enum dpyUtilsGpio::EDGE& edge);
123 #endif
124  bool setEdgeGpio(boost::system::error_code& ec, const enum dpyUtilsGpio::EDGE edge);
125 
126 #ifdef TESTING
127 public:
128  FRIEND_TEST(Basic_gpio_tests, create_GPIO_OK);
129  FRIEND_TEST(Basic_gpio_tests, create_GPIO_IO_ERROR);
130  FRIEND_TEST(Basic_gpio_tests, create_GPIO_NO_EFFECT);
131  FRIEND_TEST(Basic_gpio_tests, delete_GPIO_OK);
132  FRIEND_TEST(Basic_gpio_tests, delete_GPIO_IO_ERROR);
133  FRIEND_TEST(Basic_gpio_tests, delete_GPIO_ERROR);
134  FRIEND_TEST(Basic_gpio_tests, get_dir_INPUT_OK);
135  FRIEND_TEST(Basic_gpio_tests, get_dir_OUTPUT_OK);
136  FRIEND_TEST(Basic_gpio_tests, get_dir_ERROR);
137  FRIEND_TEST(Basic_gpio_tests, get_dir_BAD_PARAMETER);
138  FRIEND_TEST(Basic_gpio_tests, set_edge_OK);
139  FRIEND_TEST(Basic_gpio_tests, get_edge_OK);
140  FRIEND_TEST(Basic_gpio_tests, get_val_OK);
141  FRIEND_TEST(Basic_gpio_tests, get_val_ERROR);
142  FRIEND_TEST(Basic_gpio_tests, get_val_BAD_PARAMETER);
143  FRIEND_TEST(Basic_gpio_tests, get_edge_OK);
144  FRIEND_TEST(Basic_gpio_tests, get_edge_ERROR);
145  FRIEND_TEST(Basic_gpio_tests, get_edge_BAD_PARAMETER);
146  FRIEND_TEST(Advanced_gpio_tests, set_dir_OK_NO_EFFECT);
147  FRIEND_TEST(Advanced_gpio_tests, set_dir_NOT_OBTAIN_VALUE);
148  FRIEND_TEST(Advanced_gpio_tests, set_dir_NOT_OBTAIN_VALUE_2);
149  FRIEND_TEST(Advanced_gpio_tests, set_dir_BAD_PARAMETER);
150  FRIEND_TEST(Advanced_gpio_tests, set_dir_NOT_PERMITTED);
151  FRIEND_TEST(Advanced_gpio_tests, set_val_OK_0);
152  FRIEND_TEST(Advanced_gpio_tests, set_val_OK_1);
153  FRIEND_TEST(Advanced_gpio_tests, set_val_BAD_PARAMETER);
154  FRIEND_TEST(Advanced_gpio_tests, set_val_IO_ERROR);
155  FRIEND_TEST(Advanced_gpio_tests, set_val_NOT_OBTAIN_VALUE);
156  FRIEND_TEST(Advanced_gpio_tests, set_val_NOT_PERMITTED);
157  FRIEND_TEST(Advanced_gpio_tests, set_val_NOT_PERMITTED_2);
158  FRIEND_TEST(Advanced_gpio_tests, set_edge_OK);
159  FRIEND_TEST(Advanced_gpio_tests, set_edge_NOT_PERMITTED);
160  FRIEND_TEST(Advanced_gpio_tests, set_edge_BAD_PARAMETER);
161  FRIEND_TEST(Advanced_gpio_tests, set_edge_NOT_OBTAIN_VALUE);
162  FRIEND_TEST(Advanced_gpio_tests_2, switch_options_OK_1);
163  FRIEND_TEST(Advanced_gpio_tests_2, switch_options_OK_2);
164  FRIEND_TEST(Advanced_gpio_tests_2, switch_options_ERROR_1);
165  FRIEND_TEST(Advanced_gpio_tests_2, switch_options_ERROR_2);
166 
167 #endif
168 
169 };
This class implementes the read/write operations to work with text files stored in the file sytem...
Definition: files.h:43
DI2.
Definition: gpio.h:62
The value of the edge and its string.
Definition: gpio.h:68
DO1.
Definition: gpio.h:58
Low to High edge.
Definition: gpio.h:47
High to low edge.
Definition: gpio.h:48
DI1.
Definition: gpio.h:61
As an output.
Definition: gpio.h:29
As an input.
Definition: gpio.h:28
Low voltage.
Definition: gpio.h:37
Each object instantiated from this class will control a GPIO pin. The GPIO pin number must be defined...
Definition: gpio.h:89
Both edges-.
Definition: gpio.h:49
std::string gpionum
The gpio number that is wanted to configure.
Definition: gpio.h:92
Files * file
File Object to use GPIOs.
Definition: gpio.h:93
High voltage.
Definition: gpio.h:38
std::string sEdge
The default property configuration value.
Definition: gpio.h:70
enum EDGE edge
A string register name of the configuration property.
Definition: gpio.h:71
DIRECTION
An enum definition of the direction of the port.
Definition: gpio.h:26
DO2.
Definition: gpio.h:59
DI0.
Definition: gpio.h:60
EDGE
The edge definition for the hardware interrupts.
Definition: gpio.h:44
A common files library.
VALUE
The value of the port.
Definition: gpio.h:35
Definition: gpio.h:18
Functionality
Digital outputs or inputs available for application users.
Definition: gpio.h:55
DO0.
Definition: gpio.h:57