forked from telepath/BlynkProvisioning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ResetButton.h
51 lines (45 loc) · 1.21 KB
/
ResetButton.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
/**************************************************************
* This is a DEMO. You can use it only for development and testing.
*
* If you would like to add these features to your product,
* please contact Blynk for Business:
*
* http://www.blynk.io/
*
**************************************************************/
#ifndef RESETBUTTON_H
#define RESETBUTTON_H
volatile bool g_buttonPressed = false;
volatile uint32_t g_buttonPressTime = -1;
void button_action(void)
{
BlynkState::set(MODE_RESET_CONFIG);
}
void button_change(void)
{
#if BOARD_BUTTON_ACTIVE_LOW
g_buttonPressed = !digitalRead(BOARD_BUTTON_PIN);
#else
g_buttonPressed = digitalRead(BOARD_BUTTON_PIN);
#endif
if (g_buttonPressed) {
DEBUG_PRINT("Hold the button to reset configuration...");
g_buttonPressTime = millis();
} else {
uint32_t buttonHoldTime = millis() - g_buttonPressTime;
if (buttonHoldTime >= BUTTON_HOLD_TIME_ACTION) {
button_action();
}
g_buttonPressTime = -1;
}
}
void button_init()
{
#if BOARD_BUTTON_ACTIVE_LOW
pinMode(BOARD_BUTTON_PIN, INPUT_PULLUP);
#else
pinMode(BOARD_BUTTON_PIN, INPUT);
#endif
attachInterrupt(BOARD_BUTTON_PIN, button_change, CHANGE);
}
#endif