feat: =)
This commit is contained in:
parent
f056ffda67
commit
3a171cd639
125
src/main.cpp
125
src/main.cpp
|
@ -37,6 +37,11 @@ using namespace Menu;
|
||||||
#define BTN_UP 32
|
#define BTN_UP 32
|
||||||
#define BTN_DOWN 25
|
#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_PCD8544
|
||||||
#define USE_SSD1306
|
#define USE_SSD1306
|
||||||
|
|
||||||
|
@ -98,11 +103,13 @@ const colorDef<uint8_t> colors[6] MEMMODE = {
|
||||||
|
|
||||||
result doAlert(eventMask e, prompt &item);
|
result doAlert(eventMask e, prompt &item);
|
||||||
result doLockScreen(menuOut &o, idleEvent e);
|
result doLockScreen(menuOut &o, idleEvent e);
|
||||||
|
result activateLock();
|
||||||
|
result deactivateLock();
|
||||||
void decrement_timer();
|
void decrement_timer();
|
||||||
|
|
||||||
int test = 55;
|
int battery = 55;
|
||||||
|
|
||||||
int ledCtrl = HIGH;
|
int ledCtrl = LOW;
|
||||||
|
|
||||||
result myLedOn() {
|
result myLedOn() {
|
||||||
ledCtrl = HIGH;
|
ledCtrl = HIGH;
|
||||||
|
@ -119,18 +126,19 @@ TOGGLE(ledCtrl, setLed, "Led: ", doNothing, noEvent,
|
||||||
VALUE("On", HIGH, doNothing, noEvent),
|
VALUE("On", HIGH, doNothing, noEvent),
|
||||||
VALUE("Off", LOW, doNothing, noEvent));
|
VALUE("Off", LOW, doNothing, noEvent));
|
||||||
|
|
||||||
int selTest = 0;
|
enum theme { PROGRESS_BAR_THEME, TIMER_THEME, NOTHING_THEME };
|
||||||
SELECT(selTest, selMenu, "Select", doNothing, noEvent, noStyle,
|
enum theme selectedTheme = PROGRESS_BAR_THEME;
|
||||||
VALUE("Zero", 0, doNothing, noEvent),
|
CHOOSE(selectedTheme, selTheme, "Theme:", doNothing, noEvent, noStyle,
|
||||||
VALUE("One", 1, doNothing, noEvent),
|
VALUE("Progress Bar", PROGRESS_BAR_THEME, doNothing, noEvent),
|
||||||
VALUE("Two", 2, doNothing, noEvent));
|
VALUE("Timer", TIMER_THEME, doNothing, noEvent),
|
||||||
|
VALUE("Nothing...", NOTHING_THEME, doNothing, noEvent));
|
||||||
|
|
||||||
int chooseTest = -1;
|
// int chooseTest = -1;
|
||||||
CHOOSE(chooseTest, chooseMenu, "Choose", doNothing, noEvent, noStyle,
|
// CHOOSE(chooseTest, chooseMenu, "Choose", doNothing, noEvent, noStyle,
|
||||||
VALUE("First", 1, doNothing, noEvent),
|
// VALUE("First", 1, doNothing, noEvent),
|
||||||
VALUE("Second", 2, doNothing, noEvent),
|
// VALUE("Second", 2, doNothing, noEvent),
|
||||||
VALUE("Third", 3, doNothing, noEvent),
|
// VALUE("Third", 3, doNothing, noEvent),
|
||||||
VALUE("Last", -1, doNothing, noEvent));
|
// VALUE("Last", -1, doNothing, noEvent));
|
||||||
|
|
||||||
// //customizing a prompt look!
|
// //customizing a prompt look!
|
||||||
// //by extending the prompt class
|
// //by extending the prompt class
|
||||||
|
@ -143,9 +151,9 @@ CHOOSE(chooseTest, chooseMenu, "Choose", doNothing, noEvent, noStyle,
|
||||||
// }
|
// }
|
||||||
// };
|
// };
|
||||||
|
|
||||||
char *constMEM hexDigit MEMMODE = "0123456789ABCDEF";
|
// char *constMEM hexDigit MEMMODE = "0123456789ABCDEF";
|
||||||
char *constMEM hexNr[] MEMMODE = {"0", "x", hexDigit, hexDigit};
|
// char *constMEM hexNr[] MEMMODE = {"0", "x", hexDigit, hexDigit};
|
||||||
char buf1[] = "0x11";
|
// char buf1[] = "0x11";
|
||||||
|
|
||||||
// char lockTimeBuf[] = "HH:MM:SS";
|
// char lockTimeBuf[] = "HH:MM:SS";
|
||||||
|
|
||||||
|
@ -154,15 +162,16 @@ MENU(lockMenu, "Lock Now!", doNothing, noEvent, noStyle,
|
||||||
OP("Confirm", doLockScreen, enterEvent));
|
OP("Confirm", doLockScreen, enterEvent));
|
||||||
|
|
||||||
MENU(subMenu, "Settings", doNothing, noEvent, noStyle,
|
MENU(subMenu, "Settings", doNothing, noEvent, noStyle,
|
||||||
OP("Sub1", doNothing, noEvent),
|
|
||||||
// altOP(altPrompt, "", doNothing, noEvent) SUBMENU(setLed), //
|
// altOP(altPrompt, "", doNothing, noEvent) SUBMENU(setLed), //
|
||||||
OP("LED On", myLedOn, enterEvent), //
|
// OP("LED On", myLedOn, enterEvent), //
|
||||||
OP("LED Off", myLedOff, enterEvent), //
|
// OP("LED Off", myLedOff, enterEvent), //
|
||||||
|
FIELD(battery, "Battery", "%", 0, 100, 0, 0, doNothing, noEvent, noStyle),
|
||||||
SUBMENU(setLed), //
|
SUBMENU(setLed), //
|
||||||
SUBMENU(selMenu), //
|
SUBMENU(selTheme), //
|
||||||
SUBMENU(chooseMenu), //
|
|
||||||
OP("Alert test", doAlert, enterEvent), //
|
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"));
|
EXIT("<Back"));
|
||||||
|
|
||||||
uint16_t hrs = 0;
|
uint16_t hrs = 0;
|
||||||
|
@ -225,30 +234,70 @@ result alert(menuOut &o, idleEvent e) {
|
||||||
return proceed;
|
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
|
ledCtrl = HIGH; // for demo
|
||||||
digitalWrite(LOCKPIN, HIGH);
|
digitalWrite(LOCKPIN, HIGH);
|
||||||
|
return proceed;
|
||||||
}
|
}
|
||||||
void deactivateLock() {
|
result deactivateLock() {
|
||||||
ledCtrl = LOW; // for demo
|
ledCtrl = LOW; // for demo
|
||||||
digitalWrite(LOCKPIN, LOW);
|
digitalWrite(LOCKPIN, LOW);
|
||||||
|
return proceed;
|
||||||
}
|
}
|
||||||
|
|
||||||
result lockScreen(menuOut &o, idleEvent e) {
|
result lockScreen(menuOut &o, idleEvent e) {
|
||||||
Serial.println("lockScreen()");
|
Serial.println("lockScreen()");
|
||||||
activateLock();
|
activateLock();
|
||||||
while (time_s > 0) {
|
int progress;
|
||||||
|
|
||||||
|
while (lock_timer_s > 0) {
|
||||||
|
set_time_string();
|
||||||
u8g2.firstPage();
|
u8g2.firstPage();
|
||||||
do {
|
do {
|
||||||
o.setCursor(0, 0);
|
if (millis() - lock_hold_start <=
|
||||||
o.print("Locking");
|
/* LOCK_ICON_DURATION + */ LOCK_HOLD_DURATION) {
|
||||||
o.setCursor(0, 1);
|
// u8g.drawBox(0, 0, 15, 15);
|
||||||
o.print("press [select]");
|
u8g2.drawStr(25, 50, "LOCKING ...");
|
||||||
o.setCursor(0, 2);
|
// u8g2.drawXBMP((128 - 26) / 2, 1, 26, 38, epd_bitmap_lock);
|
||||||
o.print(time_s);
|
} 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();
|
decrement_timer();
|
||||||
|
}
|
||||||
|
|
||||||
} while (u8g2.nextPage());
|
} while (u8g2.nextPage());
|
||||||
}
|
}
|
||||||
return proceed;
|
return proceed;
|
||||||
|
@ -256,9 +305,13 @@ result lockScreen(menuOut &o, idleEvent e) {
|
||||||
|
|
||||||
result doLockScreen(menuOut &o, idleEvent e) {
|
result doLockScreen(menuOut &o, idleEvent e) {
|
||||||
Serial.println("doLockScreen()");
|
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.idleOn(lockScreen);
|
||||||
nav.idleOff();
|
nav.idleOff();
|
||||||
|
deactivateLock();
|
||||||
|
nav.exit();
|
||||||
return proceed;
|
return proceed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -332,7 +385,7 @@ void loop() {
|
||||||
nav.doOutput();
|
nav.doOutput();
|
||||||
while (u8g2.nextPage());
|
while (u8g2.nextPage());
|
||||||
}
|
}
|
||||||
delay(100); // simulate other tasks delay
|
// delay(100); // simulate other tasks delay
|
||||||
}
|
}
|
||||||
|
|
||||||
void decrement_timer() {
|
void decrement_timer() {
|
||||||
|
@ -349,7 +402,7 @@ void decrement_timer() {
|
||||||
timer_previousMillis = currentMillis;
|
timer_previousMillis = currentMillis;
|
||||||
|
|
||||||
// Decrement the variable
|
// Decrement the variable
|
||||||
if (time_s > 0)
|
if (lock_timer_s > 0)
|
||||||
time_s--;
|
lock_timer_s--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue