-
Notifications
You must be signed in to change notification settings - Fork 40
/
Gpio.cpp
47 lines (40 loc) · 1.1 KB
/
Gpio.cpp
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
#include <esp32-hal.h>
#include "Gpio.h"
#include "Arduino.h"
#include "Pins.h"
#include "Logger.h"
Gpio* Gpio::_inst = nullptr;
NukiWrapper* Gpio::_nuki = nullptr;
unsigned long Gpio::_lockedTs = 0;
const uint Gpio::_debounceTime = 1000;
void Gpio::init(NukiWrapper* nuki)
{
_nuki = nuki;
pinMode(TRIGGER_LOCK_PIN, INPUT_PULLUP);
pinMode(TRIGGER_UNLOCK_PIN, INPUT_PULLUP);
pinMode(TRIGGER_UNLATCH_PIN, INPUT_PULLUP);
attachInterrupt(TRIGGER_LOCK_PIN, isrLock, FALLING);
attachInterrupt(TRIGGER_UNLOCK_PIN, isrUnlock, FALLING);
attachInterrupt(TRIGGER_UNLATCH_PIN, isrUnlatch, FALLING);
}
void Gpio::isrLock()
{
if(millis() < _lockedTs) return;
_nuki->lock();
_lockedTs = millis() + _debounceTime;
Log->println(F("Lock via GPIO"));;
}
void Gpio::isrUnlock()
{
if(millis() < _lockedTs) return;
_nuki->unlock();
_lockedTs = millis() + _debounceTime;
Log->println(F("Unlock via GPIO"));;
}
void Gpio::isrUnlatch()
{
if(millis() < _lockedTs) return;
_nuki->unlatch();
_lockedTs = millis() + _debounceTime;
Log->println(F("Unlatch via GPIO"));;
}