feat: works

master
Flinner Yuu 2 weeks ago
parent 8ea6b47708
commit f056ffda67
Signed by: flinner
GPG Key ID: 95CE0DA7F0E58CA6
  1. 1
      platformio.ini
  2. 113
      src/main.cpp

@ -12,6 +12,7 @@
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200
lib_deps = neu-rah/ArduinoMenu library@^4.21.4
olikraus/U8g2@^2.35.17
; build_flags = -Ilib -Isrc

@ -1,4 +1,5 @@
#include "esp32-hal-gpio.h"
#include "esp32-hal.h"
#include "menuBase.h"
#include <Arduino.h>
@ -30,7 +31,8 @@ mcu: nano328p
using namespace Menu;
#define LEDPIN 9
#define LEDPIN 2
#define LOCKPIN LEDPIN
#define BTN_SEL 33
#define BTN_UP 32
#define BTN_DOWN 25
@ -95,6 +97,8 @@ const colorDef<uint8_t> colors[6] MEMMODE = {
};
result doAlert(eventMask e, prompt &item);
result doLockScreen(menuOut &o, idleEvent e);
void decrement_timer();
int test = 55;
@ -139,38 +143,48 @@ CHOOSE(chooseTest, chooseMenu, "Choose", doNothing, noEvent, noStyle,
// }
// };
MENU(subMenu, "Sub-Menu", doNothing, noEvent, noStyle,
OP("Sub1", doNothing, noEvent)
// ,altOP(altPrompt,"",doNothing,noEvent)
,
char *constMEM hexDigit MEMMODE = "0123456789ABCDEF";
char *constMEM hexNr[] MEMMODE = {"0", "x", hexDigit, hexDigit};
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"));
uint16_t hrs = 0;
uint16_t mins = 0;
uint16_t secs = 10;
// define a pad style menu (single line menu)
// here with a set of fields to enter a date in YYYY/MM/DD format
altMENU(menu, timeMenu, "Time", doNothing, noEvent, noStyle,
(systemStyles)(_asPad | Menu::_menuData | Menu::_canNav | _parentDraw),
FIELD(hrs, "", ":", 0, 11, 1, 0, doNothing, noEvent, noStyle),
FIELD(mins, "", "", 0, 59, 10, 1, doNothing, noEvent, wrapStyle));
char *constMEM hexDigit MEMMODE = "0123456789ABCDEF";
char *constMEM hexNr[] MEMMODE = {"0", "x", hexDigit, hexDigit};
char buf1[] = "0x11";
FIELD(mins, "", ":", 0, 59, 10, 1, doNothing, noEvent, wrapStyle),
FIELD(secs, "", "", 0, 59, 10, 1, doNothing, noEvent, wrapStyle));
MENU(mainMenu, "Main menu", doNothing, noEvent, wrapStyle,
OP("Op1", doNothing, noEvent),
OP("Op2", doNothing, noEvent)
SUBMENU(lockMenu), //
//,FIELD(test,"Test","%",0,100,10,1,doNothing,noEvent,wrapStyle)
,
SUBMENU(timeMenu), SUBMENU(subMenu), SUBMENU(setLed),
OP("LED On", myLedOn, enterEvent), OP("LED Off", myLedOff, enterEvent),
SUBMENU(selMenu), SUBMENU(chooseMenu),
OP("Alert test", doAlert, enterEvent),
EDIT("Hex", buf1, hexNr, doNothing, noEvent, noStyle), EXIT("<Exit"));
SUBMENU(timeMenu), //
SUBMENU(subMenu), //
EXIT("<Exit"));
#define MAX_DEPTH 2
#define MAX_DEPTH 3
// encoderIn<encA,encB> encoder;//simple quad encoder driver
// encoderInStream<encA,encB> encStream(encoder,4);// simple quad encoder fake
@ -211,13 +225,52 @@ result alert(menuOut &o, idleEvent e) {
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) {
Serial.println("doAlert()");
nav.idleOn(alert);
return proceed;
}
// when menu is suspended
result idle(menuOut &o, idleEvent e) {
Serial.println("idle()");
o.clear();
switch (e) {
case idleStart:
@ -262,8 +315,9 @@ void setup() {
// u8g2.setBitmapMode(0);
// disable second option
mainMenu[1].enabled = disabledStatus;
// mainMenu[1].enabled = disabledStatus;
nav.idleTask = idle; // point a function to be used when menu is suspended
options->invertFieldKeys = true;
Serial.println("setup done.");
Serial.flush();
}
@ -280,3 +334,22 @@ void loop() {
}
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…
Cancel
Save