diff --git a/include/func_button.h b/include/func_button.h index e82cbc6..3bb6864 100644 --- a/include/func_button.h +++ b/include/func_button.h @@ -1,11 +1,12 @@ #include +#include class FuncButton { private: uint8_t pressedTime; + Ticker scanner; public: FuncButton(); - void Scan(); }; diff --git a/src/client_network.cpp b/src/client_network.cpp index de0cb40..d969993 100644 --- a/src/client_network.cpp +++ b/src/client_network.cpp @@ -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="; diff --git a/src/func_button.cpp b/src/func_button.cpp index 865a299..9dbc103 100644 --- a/src/func_button.cpp +++ b/src/func_button.cpp @@ -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; } -} \ No newline at end of file + + if (count >= 2) { + return; + } +} + +FuncButton::FuncButton() +{ + pinMode(FUNC_BTN, INPUT); + pressedTime = 0; + + scanner.attach(1.0, Scan); +} diff --git a/src/main.cpp b/src/main.cpp index 742b6f8..fa1726c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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));