#define MENU_ASYNC
#include <Arduino.h>
/********************
Arduino generic menu system
U8G2 menu example
U8G2: https://github.com/olikraus/u8g2
Oct. 2016 Stephen Denne https://github.com/datacute
Based on example from Rui Azevedo - ruihfazevedo(@rrob@)gmail.com
Original from: https://github.com/christophepersoz
menu on U8G2 device
output: Wemos D1 mini OLED Shield (SSD1306 64x48 I2C) + Serial
input: Serial + encoder
mcu: nano328p
*/
#include <menu.h>
#include <menuIO/u8g2Out.h>
// #include <menuIO/encoderIn.h>
// #include <menuIO/keyIn.h>
#include <menuIO/chainStream.h>
#include <menuIO/serialOut.h>
#include <menuIO/serialIn.h>
using namespace Menu;
#define LEDPIN LED_BUILTIN
// #define USE_PCD8544
#define USE_SSD1306
#include <Wire.h>
#define fontName u8g2_font_7x13_mf
#define fontX 7
#define fontY 16
#define offsetX 0
#define offsetY 3
#define U8_Width 128
#define U8_Height 64
#define USE_HWI2C
U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(U8G2_R1, U8X8_PIN_NONE, 4, 5);
int last = 0;
const colorDef<uint8_t> colors[6] MEMMODE={
{{0,0},{0,1,1}},//bgColor
{{1,1},{1,0,0}},//fgColor
{{1,1},{1,0,0}},//valColor
{{1,1},{1,0,0}},//unitColor
{{0,1},{0,0,1}},//cursorColor
{{1,1},{1,0,0}},//titleColor
};
// //customizing a prompt look!
// //by extending the prompt class
// class altPrompt:public prompt {
// public:
// altPrompt(constMEM promptShadow& p):prompt(p) {}
// Used printTo(navRoot &root,bool sel,menuOut& out, idx_t idx,idx_t len,idx_t panelNr) override {
// return out.printRaw(F("special prompt!"),len);;
// }
// };
MENU(settingsMenu,"Einst.",doNothing,noEvent,noStyle
,OP("speichen",doNothing,noEvent)
,OP("sauber-einst",doNothing,noEvent)
,EXIT("<zurück")
);
MENU(mainMenu,"Hauptmenü",doNothing,noEvent,wrapStyle
,OP("Saubern",doNothing,noEvent)
,SUBMENU(settingsMenu)
,EXIT("<zurück")
);
#define MAX_DEPTH 2
MENU_OUTPUTS(out,MAX_DEPTH
,U8G2_OUT(u8g2,colors,fontX,fontY,offsetX,offsetY,{0,0,U8_Width/fontX,U8_Height/fontY})
,SERIAL_OUT(Serial)
);
serialIn serial(Serial);
NAVROOT(nav,mainMenu,MAX_DEPTH,serialIn,out);
//when menu is suspended
result idle(menuOut& o,idleEvent e) {
o.clear();
switch(e) {
case idleStart:o.println("suspending menu!");break;
case idling:o.println("suspended...");break;
case idleEnd:o.println("resuming menu.");break;
}
return proceed;
}
int menuPos =0;
void nextStep(navRoot nav){
if (menuPos == 0){
nav.doInput('+');
menuPos++;
} else if (menuPos == 0){
nav.doInput('*');
menuPos++;
} else if (menuPos == 0){
nav.doInput('+');
menuPos++;
} else if (menuPos == 0){
nav.doInput('/');
menuPos=0;
}
}
void setup() {
Serial.begin(115200);
while(!Serial);
Serial.println("menu 4.x test");Serial.flush();
u8g2.setFont(fontName);
// u8g2.setBitmapMode(0);
// disable second option
// mainMenu[1].enabled=disabledStatus;
nav.idleTask=idle;//point a function to be used when menu is suspended
Serial.println("setup done.");Serial.flush();
last = 0;
}
void loop() {
nav.doInput();
// digitalWrite(LEDPIN, ledCtrl);
if (nav.changed(0)) {//only draw if menu changed for gfx device
//change checking leaves more time for other tasks
u8g2.firstPage();
do nav.doOutput(); while(u8g2.nextPage());
}
if (millis()%1000 < last){
nextStep(nav);
}
last = millis()%1000;
}