From 7d3b89912397ff4af8e64e4ab97c98dd5ea64c16 Mon Sep 17 00:00:00 2001 From: SQFMI Date: Wed, 24 Mar 2021 17:00:05 -0400 Subject: [PATCH] experimental fast menu --- src/Watchy.cpp | 109 +++++++++++++++++++++++++++++++++++++++++++++++-- src/Watchy.h | 1 + 2 files changed, 107 insertions(+), 3 deletions(-) diff --git a/src/Watchy.cpp b/src/Watchy.cpp index b97efaf..57a7556 100644 --- a/src/Watchy.cpp +++ b/src/Watchy.cpp @@ -150,7 +150,82 @@ void Watchy::handleButtonPress(){ } showMenu(menuIndex, true); } - } + } + + /***************** fast menu *****************/ + bool timeout = false; + long lastTimeout = millis(); + pinMode(MENU_BTN_PIN, INPUT); + pinMode(BACK_BTN_PIN, INPUT); + pinMode(UP_BTN_PIN, INPUT); + pinMode(DOWN_BTN_PIN, INPUT); + while(!timeout){ + if(millis() - lastTimeout > 5000){ + timeout = true; + }else{ + if(digitalRead(MENU_BTN_PIN) == 1){ + lastTimeout = millis(); + if(guiState == MAIN_MENU_STATE){//if already in menu, then select menu item + switch(menuIndex) + { + case 0: + showBattery(); + break; + case 1: + showBuzz(); + break; + case 2: + showAccelerometer(); + break; + case 3: + setTime(); + break; + case 4: + setupWifi(); + break; + case 5: + showUpdateFW(); + break; + default: + break; + } + }else if(guiState == FW_UPDATE_STATE){ + updateFWBegin(); + } + }else if(digitalRead(BACK_BTN_PIN) == 1){ + lastTimeout = millis(); + if(guiState == MAIN_MENU_STATE){//exit to watch face if already in menu + RTC.alarm(ALARM_2); //resets the alarm flag in the RTC + RTC.read(currentTime); + showWatchFace(false); + break; //leave loop + }else if(guiState == APP_STATE){ + showMenu(menuIndex, false);//exit to menu if already in app + }else if(guiState == FW_UPDATE_STATE){ + showMenu(menuIndex, false);//exit to menu if already in app + } + }else if(digitalRead(UP_BTN_PIN) == 1){ + lastTimeout = millis(); + if(guiState == MAIN_MENU_STATE){//increment menu index + menuIndex--; + if(menuIndex < 0){ + menuIndex = MENU_LENGTH - 1; + } + showFastMenu(menuIndex); + } + }else if(digitalRead(DOWN_BTN_PIN) == 1){ + lastTimeout = millis(); + if(guiState == MAIN_MENU_STATE){//decrement menu index + menuIndex++; + if(menuIndex > MENU_LENGTH - 1){ + menuIndex = 0; + } + showFastMenu(menuIndex); + } + } + } + } + display.hibernate(); } void Watchy::showMenu(byte menuIndex, bool partialRefresh){ @@ -179,7 +254,36 @@ void Watchy::showMenu(byte menuIndex, bool partialRefresh){ } display.display(partialRefresh); - display.hibernate(); + //display.hibernate(); + + guiState = MAIN_MENU_STATE; +} + +void Watchy::showFastMenu(byte menuIndex){ + display.setFullWindow(); + display.fillScreen(GxEPD_BLACK); + display.setFont(&FreeMonoBold9pt7b); + + int16_t x1, y1; + uint16_t w, h; + int16_t yPos; + + const char *menuItems[] = {"Check Battery", "Vibrate Motor", "Show Accelerometer", "Set Time", "Setup WiFi", "Update Firmware"}; + for(int i=0; i