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 <Arduino.h>
#include <Ticker.h>
class FuncButton class FuncButton
{ {
private: private:
uint8_t pressedTime; uint8_t pressedTime;
Ticker scanner;
public: public:
FuncButton(); FuncButton();
void Scan();
}; };

View File

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

View File

@ -6,22 +6,35 @@
extern UserData* userdataManager; extern UserData* userdataManager;
FuncButton::FuncButton() static int pressedTime;
{
pinMode(FUNC_BTN, INPUT);
pressedTime = 0;
}
void FuncButton::Scan() static void Scan()
{ {
if (digitalRead(FUNC_BTN) == PRESSED_STATUS) { if (digitalRead(FUNC_BTN) == PRESSED_STATUS) {
pressedTime++; pressedTime++;
} else { return;
pressedTime = 0;
} }
if (pressedTime > 5) {
int count = pressedTime;
pressedTime = 0;
if (count >= 10) {
// Factory reset
userdataManager->EraseData(); userdataManager->EraseData();
delay(1000); delay(1000);
ESP.restart(); 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() void setup()
{ {
Serial.begin(115200);
statusLed = new StatusBlink(); statusLed = new StatusBlink();
userdataManager = new UserData(); userdataManager = new UserData();
displayPanel = new DisplayPanel(); displayPanel = new DisplayPanel();
@ -32,7 +34,6 @@ void setup()
void loop() void loop()
{ {
delay(1000); delay(1000);
funcButton->Scan();
if (netClient->FetchNewData() == OK) { if (netClient->FetchNewData() == OK) {
displayPanel->DisplayCpuPercent(netClient->GetPercent(CPU_PERCENT)); displayPanel->DisplayCpuPercent(netClient->GetPercent(CPU_PERCENT));