From 3a171cd639f0f4ce4a7af8ba912eeade5fc16179 Mon Sep 17 00:00:00 2001 From: Flinner Yuu Date: Mon, 22 Apr 2024 06:46:50 +0300 Subject: [PATCH] feat: =) --- src/main.cpp | 131 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 92 insertions(+), 39 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 3a6873d..4e74df3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -37,6 +37,11 @@ using namespace Menu; #define BTN_UP 32 #define BTN_DOWN 25 +#define LOCK_HOLD_DURATION 2000 // ms +#define UNLOCK_HOLD_DURATION 2000 // ms +// #define LOCK_ICON_DURATION 1000 // ms +#define SAFETY_HOLD_DURATION 5000 // ms + // #define USE_PCD8544 #define USE_SSD1306 @@ -98,11 +103,13 @@ const colorDef colors[6] MEMMODE = { result doAlert(eventMask e, prompt &item); result doLockScreen(menuOut &o, idleEvent e); +result activateLock(); +result deactivateLock(); void decrement_timer(); -int test = 55; +int battery = 55; -int ledCtrl = HIGH; +int ledCtrl = LOW; result myLedOn() { ledCtrl = HIGH; @@ -119,18 +126,19 @@ TOGGLE(ledCtrl, setLed, "Led: ", doNothing, noEvent, VALUE("On", HIGH, doNothing, noEvent), VALUE("Off", LOW, doNothing, noEvent)); -int selTest = 0; -SELECT(selTest, selMenu, "Select", doNothing, noEvent, noStyle, - VALUE("Zero", 0, doNothing, noEvent), - VALUE("One", 1, doNothing, noEvent), - VALUE("Two", 2, doNothing, noEvent)); +enum theme { PROGRESS_BAR_THEME, TIMER_THEME, NOTHING_THEME }; +enum theme selectedTheme = PROGRESS_BAR_THEME; +CHOOSE(selectedTheme, selTheme, "Theme:", doNothing, noEvent, noStyle, + VALUE("Progress Bar", PROGRESS_BAR_THEME, doNothing, noEvent), + VALUE("Timer", TIMER_THEME, doNothing, noEvent), + VALUE("Nothing...", NOTHING_THEME, doNothing, noEvent)); -int chooseTest = -1; -CHOOSE(chooseTest, chooseMenu, "Choose", doNothing, noEvent, noStyle, - VALUE("First", 1, doNothing, noEvent), - VALUE("Second", 2, doNothing, noEvent), - VALUE("Third", 3, doNothing, noEvent), - VALUE("Last", -1, doNothing, noEvent)); +// int chooseTest = -1; +// CHOOSE(chooseTest, chooseMenu, "Choose", doNothing, noEvent, noStyle, +// VALUE("First", 1, doNothing, noEvent), +// VALUE("Second", 2, doNothing, noEvent), +// VALUE("Third", 3, doNothing, noEvent), +// VALUE("Last", -1, doNothing, noEvent)); // //customizing a prompt look! // //by extending the prompt class @@ -143,9 +151,9 @@ CHOOSE(chooseTest, chooseMenu, "Choose", doNothing, noEvent, noStyle, // } // }; -char *constMEM hexDigit MEMMODE = "0123456789ABCDEF"; -char *constMEM hexNr[] MEMMODE = {"0", "x", hexDigit, hexDigit}; -char buf1[] = "0x11"; +// char *constMEM hexDigit MEMMODE = "0123456789ABCDEF"; +// char *constMEM hexNr[] MEMMODE = {"0", "x", hexDigit, hexDigit}; +// char buf1[] = "0x11"; // char lockTimeBuf[] = "HH:MM:SS"; @@ -154,15 +162,16 @@ MENU(lockMenu, "Lock Now!", doNothing, noEvent, noStyle, OP("Confirm", doLockScreen, enterEvent)); MENU(subMenu, "Settings", doNothing, noEvent, noStyle, - OP("Sub1", doNothing, noEvent), // altOP(altPrompt, "", doNothing, noEvent) SUBMENU(setLed), // - OP("LED On", myLedOn, enterEvent), // - OP("LED Off", myLedOff, enterEvent), // - SUBMENU(setLed), // - SUBMENU(selMenu), // - SUBMENU(chooseMenu), // - OP("Alert test", doAlert, enterEvent), // - EDIT("Hex", buf1, hexNr, doNothing, noEvent, noStyle), // + // OP("LED On", myLedOn, enterEvent), // + // OP("LED Off", myLedOff, enterEvent), // + FIELD(battery, "Battery", "%", 0, 100, 0, 0, doNothing, noEvent, noStyle), + SUBMENU(setLed), // + SUBMENU(selTheme), // + OP("Alert test", doAlert, enterEvent), // + OP("Lock test", activateLock, enterEvent), // + OP("Unlock test", deactivateLock, enterEvent), // + // EDIT("Hex", buf1, hexNr, doNothing, noEvent, noStyle), // EXIT(" 0) { + int progress; + + while (lock_timer_s > 0) { + set_time_string(); u8g2.firstPage(); do { - o.setCursor(0, 0); - o.print("Locking"); - o.setCursor(0, 1); - o.print("press [select]"); - o.setCursor(0, 2); - o.print(time_s); - decrement_timer(); + if (millis() - lock_hold_start <= + /* LOCK_ICON_DURATION + */ LOCK_HOLD_DURATION) { + // u8g.drawBox(0, 0, 15, 15); + u8g2.drawStr(25, 50, "LOCKING ..."); + // u8g2.drawXBMP((128 - 26) / 2, 1, 26, 38, epd_bitmap_lock); + } else { + switch (selectedTheme) { + case PROGRESS_BAR_THEME: + progress = map(lock_timer_s, 0, lock_time_s, 0, 108); + u8g2.drawBox(10, 15, progress, 10); + // print progress bar + u8g2.drawFrame(0, 10, 128, 20); + u8g2.drawStr(30, 50, time_string); + break; + case TIMER_THEME: + u8g2.drawStr(30, 50, time_string); + break; + case NOTHING_THEME: + break; + } + decrement_timer(); + } + } while (u8g2.nextPage()); } return proceed; @@ -256,9 +305,13 @@ result lockScreen(menuOut &o, idleEvent e) { result doLockScreen(menuOut &o, idleEvent e) { Serial.println("doLockScreen()"); - time_s = secs + (mins * 60) + (hrs * 3600); + lock_timer_s = secs + (mins * 60) + (hrs * 3600); + lock_hold_start = millis(); + lock_time_s = lock_timer_s; nav.idleOn(lockScreen); nav.idleOff(); + deactivateLock(); + nav.exit(); return proceed; } @@ -332,7 +385,7 @@ void loop() { nav.doOutput(); while (u8g2.nextPage()); } - delay(100); // simulate other tasks delay + // delay(100); // simulate other tasks delay } void decrement_timer() { @@ -349,7 +402,7 @@ void decrement_timer() { timer_previousMillis = currentMillis; // Decrement the variable - if (time_s > 0) - time_s--; + if (lock_timer_s > 0) + lock_timer_s--; } }