Topuino_Hardware/src/func_button.cpp

41 lines
649 B
C++
Raw Normal View History

2021-08-29 22:14:08 +08:00
#include "func_button.h"
#include "user_data.h"
#define FUNC_BTN 0
#define PRESSED_STATUS LOW
extern UserData* userdataManager;
2022-06-26 14:23:33 +08:00
static int pressedTime;
2021-08-29 22:14:08 +08:00
2022-06-26 14:23:33 +08:00
static void Scan()
2021-08-29 22:14:08 +08:00
{
if (digitalRead(FUNC_BTN) == PRESSED_STATUS) {
pressedTime++;
2022-06-26 14:23:33 +08:00
return;
2021-08-29 22:14:08 +08:00
}
2022-06-26 14:23:33 +08:00
int count = pressedTime;
pressedTime = 0;
if (count >= 10) {
// Factory reset
2021-08-29 22:14:08 +08:00
userdataManager->EraseData();
2022-03-29 22:27:51 +08:00
delay(1000);
2021-08-29 22:14:08 +08:00
ESP.restart();
2022-06-26 14:23:33 +08:00
return;
2021-08-29 22:14:08 +08:00
}
2022-06-26 14:23:33 +08:00
if (count >= 2) {
return;
}
}
FuncButton::FuncButton()
{
pinMode(FUNC_BTN, INPUT);
pressedTime = 0;
scanner.attach(1.0, Scan);
}