change button scan mode

This commit is contained in:
Vector Von 2022-06-26 14:23:33 +08:00
parent 5a9c93d329
commit f938884ef5
4 changed files with 27 additions and 13 deletions

View File

@ -1,11 +1,12 @@
#include <Arduino.h>
#include <Ticker.h>
class FuncButton
{
private:
uint8_t pressedTime;
Ticker scanner;
public:
FuncButton();
void Scan();
};

View File

@ -16,7 +16,6 @@ ClientNetwork::ClientNetwork()
while (WiFi.status() != WL_CONNECTED)
{
delay(1000);
funcButton->Scan();
}
statusLed->SetBlinkRate(StatusBlink::BlinkRate::RateAlwaysOff);
url = "http://iot.vvzero.com/topuino/getdata?SN=";

View File

@ -6,22 +6,35 @@
extern UserData* userdataManager;
FuncButton::FuncButton()
{
pinMode(FUNC_BTN, INPUT);
pressedTime = 0;
}
static int pressedTime;
void FuncButton::Scan()
static void Scan()
{
if (digitalRead(FUNC_BTN) == PRESSED_STATUS) {
pressedTime++;
} else {
pressedTime = 0;
return;
}
if (pressedTime > 5) {
int count = pressedTime;
pressedTime = 0;
if (count >= 10) {
// Factory reset
userdataManager->EraseData();
delay(1000);
ESP.restart();
return;
}
}
if (count >= 2) {
return;
}
}
FuncButton::FuncButton()
{
pinMode(FUNC_BTN, INPUT);
pressedTime = 0;
scanner.attach(1.0, Scan);
}

View File

@ -16,6 +16,8 @@ FuncButton* funcButton;
void setup()
{
Serial.begin(115200);
statusLed = new StatusBlink();
userdataManager = new UserData();
displayPanel = new DisplayPanel();
@ -32,7 +34,6 @@ void setup()
void loop()
{
delay(1000);
funcButton->Scan();
if (netClient->FetchNewData() == OK) {
displayPanel->DisplayCpuPercent(netClient->GetPercent(CPU_PERCENT));