This commit is contained in:
Flinner Yuu 2024-04-22 06:46:50 +03:00
parent f056ffda67
commit 3a171cd639
Signed by: flinner
GPG Key ID: 95CE0DA7F0E58CA6
1 changed files with 92 additions and 39 deletions

View File

@ -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<uint8_t> 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), //
// OP("LED On", myLedOn, enterEvent), //
// OP("LED Off", myLedOff, enterEvent), //
FIELD(battery, "Battery", "%", 0, 100, 0, 0, doNothing, noEvent, noStyle),
SUBMENU(setLed), //
SUBMENU(selMenu), //
SUBMENU(chooseMenu), //
SUBMENU(selTheme), //
OP("Alert test", doAlert, enterEvent), //
EDIT("Hex", buf1, hexNr, doNothing, noEvent, noStyle), //
OP("Lock test", activateLock, enterEvent), //
OP("Unlock test", deactivateLock, enterEvent), //
// EDIT("Hex", buf1, hexNr, doNothing, noEvent, noStyle), //
EXIT("<Back"));
uint16_t hrs = 0;
@ -225,30 +234,70 @@ result alert(menuOut &o, idleEvent e) {
return proceed;
}
unsigned long time_s = 0;
unsigned long lock_timer_s = 0; // this decrements
unsigned long lock_time_s = 0; // this doesn't
void activateLock() {
///////////////////////
// TIME STRING LOGIC //
///////////////////////
char time_string[20];
unsigned get_seconds(unsigned long time) { return time % 60; }
unsigned get_minutes(unsigned long time) { return (time % 3600) / 60; }
unsigned get_hrs(unsigned long time) { return (time / 3600); }
void set_time_string() {
sprintf(time_string, "%02u:%02u:%02u", get_hrs(lock_timer_s),
get_minutes(lock_timer_s), get_seconds(lock_timer_s));
}
////////////////////
// LOCKING LOGIC! //
////////////////////
unsigned long lock_hold_start;
result activateLock() {
ledCtrl = HIGH; // for demo
digitalWrite(LOCKPIN, HIGH);
return proceed;
}
void deactivateLock() {
result deactivateLock() {
ledCtrl = LOW; // for demo
digitalWrite(LOCKPIN, LOW);
return proceed;
}
result lockScreen(menuOut &o, idleEvent e) {
Serial.println("lockScreen()");
activateLock();
while (time_s > 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);
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--;
}
}