-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathGpio.h
112 lines (93 loc) · 2.98 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#pragma once
#include <functional>
#include <Preferences.h>
#include <vector>
enum class PinRole
{
Disabled,
InputLock,
InputUnlock,
InputUnlatch,
InputElectricStrikeActuation,
InputActivateRTO,
InputActivateCM,
InputDeactivateRtoCm,
OutputHighLocked,
OutputHighUnlocked,
OutputHighMotorBlocked,
OutputHighRtoActive,
OutputHighCmActive,
OutputHighRtoOrCmActive,
GeneralOutput,
GeneralInputPullDown,
GeneralInputPullUp
};
enum class GpioAction
{
Lock,
Unlock,
Unlatch,
ElectricStrikeActuation,
ActivateRTO,
ActivateCM,
DeactivateRtoCm,
GeneralInput
};
struct PinEntry
{
uint8_t pin = 0;
PinRole role = PinRole::Disabled;
};
class Gpio
{
public:
Gpio(Preferences* preferences);
static void init();
void migrateObsoleteSetting();
void addCallback(std::function<void(const GpioAction&, const int&)> callback);
void loadPinConfiguration();
void savePinConfiguration(const std::vector<PinEntry>& pinConfiguration);
const std::vector<uint8_t>& availablePins() const;
const std::vector<PinEntry>& pinConfiguration() const;
const PinRole getPinRole(const int& pin) const;
String getRoleDescription(PinRole role) const;
void getConfigurationText(String& text, const std::vector<PinEntry>& pinConfiguration, const String& linebreak = "\n") const;
const std::vector<PinRole>& getAllRoles() const;
void setPinOutput(const uint8_t& pin, const uint8_t& state);
private:
void IRAM_ATTR notify(const GpioAction& action, const int& pin);
static void inputCallback(const int & pin);
const std::vector<uint8_t> _availablePins = { 2, 4, 5, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 32, 33 };
const std::vector<PinRole> _allRoles =
{
PinRole::Disabled,
PinRole::InputLock,
PinRole::InputUnlock,
PinRole::InputUnlatch,
PinRole::InputElectricStrikeActuation,
PinRole::InputActivateRTO,
PinRole::InputActivateCM,
PinRole::InputDeactivateRtoCm,
PinRole::OutputHighLocked,
PinRole::OutputHighUnlocked,
PinRole::OutputHighRtoActive,
PinRole::OutputHighCmActive,
PinRole::OutputHighRtoOrCmActive,
PinRole::GeneralInputPullDown,
PinRole::GeneralInputPullUp,
PinRole::GeneralOutput
};
std::vector<PinEntry> _pinConfiguration;
static const uint _debounceTime;
static void IRAM_ATTR isrLock();
static void IRAM_ATTR isrUnlock();
static void IRAM_ATTR isrUnlatch();
static void IRAM_ATTR isrElectricStrikeActuation();
static void IRAM_ATTR isrActivateRTO();
static void IRAM_ATTR isrActivateCM();
static void IRAM_ATTR isrDeactivateRtoCm();
std::vector<std::function<void(const GpioAction&, const int&)>> _callbacks;
static Gpio* _inst;
static unsigned long _debounceTs;
Preferences* _preferences = nullptr;
};