-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrpi_gpio.hpp
75 lines (68 loc) · 1.79 KB
/
rpi_gpio.hpp
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#pragma once
#include <vector>
#include <thread>
#include <atomic>
#include <mutex>
#define GPIO_COUNT 28
#define GPIO0 0
#define GPIO1 1
#define GPIO2 2
#define GPIO3 3
#define GPIO4 4
#define GPIO5 5
#define GPIO6 6
#define GPIO7 7
#define GPIO8 8
#define GPIO9 9
#define GPIO10 10
#define GPIO11 11
#define GPIO12 12
#define GPIO13 13
#define GPIO14 14
#define GPIO15 15
#define GPIO16 16
#define GPIO17 17
#define GPIO18 18
#define GPIO19 19
#define GPIO20 20
#define GPIO21 21
#define GPIO22 22
#define GPIO23 23
#define GPIO24 24
#define GPIO25 25
#define GPIO26 26
#define GPIO27 27
namespace GPIO {
struct Event {
unsigned long long time;
unsigned number;
bool high;
};
enum class Mode { In, Out };
enum class Resistor { PullUp, PullDown, Off };
class Controller
{
public:
virtual ~Controller();
Controller(const Controller &) = delete;
Controller(Controller &&) = delete;
Controller &operator=(const Controller &) = delete;
static Controller &GetInstance();
void SetMode(unsigned number, Mode mode);
void SetResistor(unsigned number, Resistor resistor);
void Set(unsigned number, bool active);
bool Get(unsigned number);
std::vector<Event> GetEvents();
void SetSchedule(std::vector<Event> events, unsigned long long interval = 0);
void Reset();
private:
Controller();
static void EventThread(Controller *instance);
std::thread eventThread;
std::atomic_bool enabled, reset;
std::vector<Event> events;
std::mutex eventsAccess;
std::atomic<std::pair<std::vector<Event>, unsigned long long> *> schedule;
void *io;
};
}