-
Notifications
You must be signed in to change notification settings - Fork 2
/
gpio.h
64 lines (55 loc) · 1.41 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
57
58
59
60
61
62
63
64
#ifndef __NS_STD
#define __NS_STD
using namespace std;
#endif
#ifndef __PC_GPIO_INC
#define __PC_GPIO_INC
#include <string>
#include <vector>
#include <mutex>
#include <fstream>
#include <iostream> // debug
#define INPUT 0
#define OUTPUT 1
namespace gpio
{
enum LedColor { LedOff, Red, Green };
enum LedBlink { Solid, BlinkOnce, Blink };
class Pin
{
private:
fstream fs;
uint pin_num;
public:
string activeText;
string inactiveText;
inline bool read() { fs.seekg(0); return fs.get() == '1'; }
inline string read_str() { return read() ? activeText : inactiveText; }
inline void set(bool val) { fs << (int)val; fs.flush(); }
Pin(int, int);
~Pin();
};
class Led
{
private:
Pin* greenPin;
Pin* redPin;
bool biColor;
LedColor color;
LedColor blinkColor;
LedBlink blink;
bool blinkState;
void setPins(LedColor);
mutex m;
public:
void update();
void set(LedColor, LedBlink = Solid, LedColor = LedOff);
inline bool isBicolor() { return biColor; }
inline LedColor getColor() { return color; };
Led(int, int);
~Led();
};
extern vector<Led*> leds;
void* gpio_thread(void*);
};
#endif