From 281e07c30ab753daea8d72e9602951aab5bca91e Mon Sep 17 00:00:00 2001 From: anschrammh Date: Wed, 9 Dec 2020 22:40:00 +0100 Subject: [PATCH] Removed the old way to change the current view and added the EventHandler way to do it --- src/app/app.ino | 52 +++++++++++++++---------------------------------- 1 file changed, 16 insertions(+), 36 deletions(-) diff --git a/src/app/app.ino b/src/app/app.ino index af6b0b9..95b6f14 100644 --- a/src/app/app.ino +++ b/src/app/app.ino @@ -5,13 +5,15 @@ #include "tasks.h" #include "CFGDictionary.h" #include "CFGParameterValue.h" +#include "EventHandler.h" #define DEBUG SAB sab; +EventHandler evHan; +EventHandler::Event evt; -unsigned long currentMs = 0, buttonDownMs(0), buttonUpMs(0); +unsigned long currentMs = 0; volatile boolean ioStateChange(false); -boolean buttonPushSampled(false); View1Packet v1p = {sab.getRtcManager().getDateTime(), sab.getSdCardManager().getSize(GBYTE), sab.getPowerManager().getPowerInfo(),0, sab.getSoftVersion(), &sab}; ViewAPPacket vap = {sab.getConnectivityManager().softAPmacAddress(), sab.getConnectivityManager().softAPSSID(), sab.getConnectivityManager().softAPIP(), sab.getConnectivityManager().softAPgetStationNum(), sab.getConnectivityManager().isAPEnabled()}; ViewSTAPacket vstap = {sab.getConnectivityManager().macAddress(), sab.getConnectivityManager().localIP(), sab.getConnectivityManager().RSSI(), sab.getConnectivityManager().isSTAEnabled()}; @@ -115,48 +117,26 @@ void loop() } } - /*if(digitalRead(GPIO_0) == 0 && millis() - buttonMs > 500) + evt = evHan.getEvent(); + switch(evt) { - buttonMs = millis(); - sab.getScreenManager().displayNextView(); - #ifdef DEBUG - Serial.println("Changing view"); - Serial.print("Selected view is : ");Serial.println(sab.getScreenManager().getCurrentViewUID()); - #endif - }*/ - - if(digitalRead(GPIO_0) == 0 && !buttonPushSampled) - { - buttonPushSampled = true; - buttonDownMs = millis(); - } - - if(digitalRead(GPIO_0) == 1 && buttonPushSampled) - { - buttonPushSampled = false; - buttonUpMs = millis(); - - if(buttonUpMs - buttonDownMs < 700 && buttonUpMs - buttonDownMs > 200)//Short press - { + case EventHandler::Event::FLASH_BUTTON_PRESS: sab.getScreenManager().displayNextView(); #ifdef DEBUG Serial.printf("Changing view\nSelected view is : %d\n",sab.getScreenManager().getCurrentViewUID()); #endif - } + break; + case EventHandler::Event::FLASH_BUTTON_LONG_PRESS: + sab.getScreenManager().displayPreviousView(); + #ifdef DEBUG + Serial.printf("Changing view\nSelected view is : %d\n",sab.getScreenManager().getCurrentViewUID()); + #endif + break; } - - if(digitalRead(GPIO_0) == 0 && buttonPushSampled && millis() - buttonDownMs > 700) - { - buttonPushSampled = false; - - sab.getScreenManager().displayPreviousView(); - #ifdef DEBUG - Serial.printf("Changing view\nSelected view is : %d\n",sab.getScreenManager().getCurrentViewUID()); - #endif - } - + //Run the different services sab.run(); + evHan.run(); } ICACHE_RAM_ATTR void ioISR()