-
Notifications
You must be signed in to change notification settings - Fork 1
/
gpio.h
executable file
·56 lines (45 loc) · 1.1 KB
/
gpio.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#ifndef GPIO_H
#define GPIO_H
#include <QString>
#include <QFile>
#include <QTextStream>
enum GpioDir {
GPIO_DIR_INPUT,
GPIO_DIR_OUTPUT,
GPIO_DIR_ERROR
};
enum GpioState {
GPIO_STATE_HIGH,
GPIO_STATE_LOW,
GPIO_STATE_ERROR, // inicates an error reading GPIO state
};
class Gpio
{
private:
bool _ready;
GpioDir _dir;
int _number;
QString * _sys_gpio;
QString * _sys_gpio_value;
QFile * _value_file;
QTextStream * _value_stream;
bool _export_gpio();
public:
// constructor
Gpio(int gpio_number, GpioDir direction);
// destructor
~Gpio();
// initialize GPIO, return false if failed
// this function opens up the file handle to the device
// and verifies the direction is set correctly
bool init();
// get current gpio_direction
GpioDir get_direction();
// set gpio direction
bool set_direction(GpioDir direction);
// get current gpio state
GpioState get_state();
// set current gpio state
bool set_state(GpioState state);
};
#endif // GPIO_H