feat: works
This commit is contained in:
parent
8ea6b47708
commit
f056ffda67
|
@ -12,6 +12,7 @@
|
||||||
platform = espressif32
|
platform = espressif32
|
||||||
board = esp32dev
|
board = esp32dev
|
||||||
framework = arduino
|
framework = arduino
|
||||||
|
monitor_speed = 115200
|
||||||
lib_deps = neu-rah/ArduinoMenu library@^4.21.4
|
lib_deps = neu-rah/ArduinoMenu library@^4.21.4
|
||||||
olikraus/U8g2@^2.35.17
|
olikraus/U8g2@^2.35.17
|
||||||
; build_flags = -Ilib -Isrc
|
; build_flags = -Ilib -Isrc
|
||||||
|
|
113
src/main.cpp
113
src/main.cpp
|
@ -1,4 +1,5 @@
|
||||||
#include "esp32-hal-gpio.h"
|
#include "esp32-hal-gpio.h"
|
||||||
|
#include "esp32-hal.h"
|
||||||
#include "menuBase.h"
|
#include "menuBase.h"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
@ -30,7 +31,8 @@ mcu: nano328p
|
||||||
|
|
||||||
using namespace Menu;
|
using namespace Menu;
|
||||||
|
|
||||||
#define LEDPIN 9
|
#define LEDPIN 2
|
||||||
|
#define LOCKPIN LEDPIN
|
||||||
#define BTN_SEL 33
|
#define BTN_SEL 33
|
||||||
#define BTN_UP 32
|
#define BTN_UP 32
|
||||||
#define BTN_DOWN 25
|
#define BTN_DOWN 25
|
||||||
|
@ -95,6 +97,8 @@ 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);
|
||||||
|
void decrement_timer();
|
||||||
|
|
||||||
int test = 55;
|
int test = 55;
|
||||||
|
|
||||||
|
@ -139,38 +143,48 @@ CHOOSE(chooseTest, chooseMenu, "Choose", doNothing, noEvent, noStyle,
|
||||||
// }
|
// }
|
||||||
// };
|
// };
|
||||||
|
|
||||||
MENU(subMenu, "Sub-Menu", doNothing, noEvent, noStyle,
|
char *constMEM hexDigit MEMMODE = "0123456789ABCDEF";
|
||||||
OP("Sub1", doNothing, noEvent)
|
char *constMEM hexNr[] MEMMODE = {"0", "x", hexDigit, hexDigit};
|
||||||
// ,altOP(altPrompt,"",doNothing,noEvent)
|
char buf1[] = "0x11";
|
||||||
,
|
|
||||||
|
// char lockTimeBuf[] = "HH:MM:SS";
|
||||||
|
|
||||||
|
MENU(lockMenu, "Lock Now!", doNothing, noEvent, noStyle,
|
||||||
|
EXIT("Cancel"), //
|
||||||
|
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), //
|
||||||
EXIT("<Back"));
|
EXIT("<Back"));
|
||||||
|
|
||||||
uint16_t hrs = 0;
|
uint16_t hrs = 0;
|
||||||
uint16_t mins = 0;
|
uint16_t mins = 0;
|
||||||
|
uint16_t secs = 10;
|
||||||
|
|
||||||
// define a pad style menu (single line menu)
|
// define a pad style menu (single line menu)
|
||||||
// here with a set of fields to enter a date in YYYY/MM/DD format
|
// here with a set of fields to enter a date in YYYY/MM/DD format
|
||||||
altMENU(menu, timeMenu, "Time", doNothing, noEvent, noStyle,
|
altMENU(menu, timeMenu, "Time", doNothing, noEvent, noStyle,
|
||||||
(systemStyles)(_asPad | Menu::_menuData | Menu::_canNav | _parentDraw),
|
(systemStyles)(_asPad | Menu::_menuData | Menu::_canNav | _parentDraw),
|
||||||
FIELD(hrs, "", ":", 0, 11, 1, 0, doNothing, noEvent, noStyle),
|
FIELD(hrs, "", ":", 0, 11, 1, 0, doNothing, noEvent, noStyle),
|
||||||
FIELD(mins, "", "", 0, 59, 10, 1, doNothing, noEvent, wrapStyle));
|
FIELD(mins, "", ":", 0, 59, 10, 1, doNothing, noEvent, wrapStyle),
|
||||||
|
FIELD(secs, "", "", 0, 59, 10, 1, doNothing, noEvent, wrapStyle));
|
||||||
char *constMEM hexDigit MEMMODE = "0123456789ABCDEF";
|
|
||||||
char *constMEM hexNr[] MEMMODE = {"0", "x", hexDigit, hexDigit};
|
|
||||||
char buf1[] = "0x11";
|
|
||||||
|
|
||||||
MENU(mainMenu, "Main menu", doNothing, noEvent, wrapStyle,
|
MENU(mainMenu, "Main menu", doNothing, noEvent, wrapStyle,
|
||||||
OP("Op1", doNothing, noEvent),
|
SUBMENU(lockMenu), //
|
||||||
OP("Op2", doNothing, noEvent)
|
|
||||||
//,FIELD(test,"Test","%",0,100,10,1,doNothing,noEvent,wrapStyle)
|
//,FIELD(test,"Test","%",0,100,10,1,doNothing,noEvent,wrapStyle)
|
||||||
,
|
SUBMENU(timeMenu), //
|
||||||
SUBMENU(timeMenu), SUBMENU(subMenu), SUBMENU(setLed),
|
SUBMENU(subMenu), //
|
||||||
OP("LED On", myLedOn, enterEvent), OP("LED Off", myLedOff, enterEvent),
|
EXIT("<Exit"));
|
||||||
SUBMENU(selMenu), SUBMENU(chooseMenu),
|
|
||||||
OP("Alert test", doAlert, enterEvent),
|
|
||||||
EDIT("Hex", buf1, hexNr, doNothing, noEvent, noStyle), EXIT("<Exit"));
|
|
||||||
|
|
||||||
#define MAX_DEPTH 2
|
#define MAX_DEPTH 3
|
||||||
|
|
||||||
// encoderIn<encA,encB> encoder;//simple quad encoder driver
|
// encoderIn<encA,encB> encoder;//simple quad encoder driver
|
||||||
// encoderInStream<encA,encB> encStream(encoder,4);// simple quad encoder fake
|
// encoderInStream<encA,encB> encStream(encoder,4);// simple quad encoder fake
|
||||||
|
@ -211,13 +225,52 @@ result alert(menuOut &o, idleEvent e) {
|
||||||
return proceed;
|
return proceed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned long time_s = 0;
|
||||||
|
|
||||||
|
void activateLock() {
|
||||||
|
ledCtrl = HIGH; // for demo
|
||||||
|
digitalWrite(LOCKPIN, HIGH);
|
||||||
|
}
|
||||||
|
void deactivateLock() {
|
||||||
|
ledCtrl = LOW; // for demo
|
||||||
|
digitalWrite(LOCKPIN, LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
result lockScreen(menuOut &o, idleEvent e) {
|
||||||
|
Serial.println("lockScreen()");
|
||||||
|
activateLock();
|
||||||
|
while (time_s > 0) {
|
||||||
|
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();
|
||||||
|
} while (u8g2.nextPage());
|
||||||
|
}
|
||||||
|
return proceed;
|
||||||
|
}
|
||||||
|
|
||||||
|
result doLockScreen(menuOut &o, idleEvent e) {
|
||||||
|
Serial.println("doLockScreen()");
|
||||||
|
time_s = secs + (mins * 60) + (hrs * 3600);
|
||||||
|
nav.idleOn(lockScreen);
|
||||||
|
nav.idleOff();
|
||||||
|
return proceed;
|
||||||
|
}
|
||||||
|
|
||||||
result doAlert(eventMask e, prompt &item) {
|
result doAlert(eventMask e, prompt &item) {
|
||||||
|
Serial.println("doAlert()");
|
||||||
nav.idleOn(alert);
|
nav.idleOn(alert);
|
||||||
return proceed;
|
return proceed;
|
||||||
}
|
}
|
||||||
|
|
||||||
// when menu is suspended
|
// when menu is suspended
|
||||||
result idle(menuOut &o, idleEvent e) {
|
result idle(menuOut &o, idleEvent e) {
|
||||||
|
Serial.println("idle()");
|
||||||
o.clear();
|
o.clear();
|
||||||
switch (e) {
|
switch (e) {
|
||||||
case idleStart:
|
case idleStart:
|
||||||
|
@ -262,8 +315,9 @@ void setup() {
|
||||||
// u8g2.setBitmapMode(0);
|
// u8g2.setBitmapMode(0);
|
||||||
|
|
||||||
// disable second option
|
// disable second option
|
||||||
mainMenu[1].enabled = disabledStatus;
|
// mainMenu[1].enabled = disabledStatus;
|
||||||
nav.idleTask = idle; // point a function to be used when menu is suspended
|
nav.idleTask = idle; // point a function to be used when menu is suspended
|
||||||
|
options->invertFieldKeys = true;
|
||||||
Serial.println("setup done.");
|
Serial.println("setup done.");
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
}
|
}
|
||||||
|
@ -280,3 +334,22 @@ void loop() {
|
||||||
}
|
}
|
||||||
delay(100); // simulate other tasks delay
|
delay(100); // simulate other tasks delay
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void decrement_timer() {
|
||||||
|
unsigned long timer_interval = 1000; // decrement rate
|
||||||
|
static unsigned long timer_previousMillis =
|
||||||
|
0; // Variable to store the last time the decrement occurred
|
||||||
|
unsigned long currentMillis =
|
||||||
|
millis(); // Get the current time in milliseconds
|
||||||
|
|
||||||
|
// Check if it's time to decrement
|
||||||
|
if (currentMillis - timer_previousMillis >= timer_interval) {
|
||||||
|
|
||||||
|
// Update the previous time
|
||||||
|
timer_previousMillis = currentMillis;
|
||||||
|
|
||||||
|
// Decrement the variable
|
||||||
|
if (time_s > 0)
|
||||||
|
time_s--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue