#include <TFT_eSPI.h>
#include <SPI.h> // this is needed for display
// The display also uses hardware SPI, plus #9 & #10
#define TFT_CS 15
#define TFT_DC 2
#define TFT_RST 4
#define TFT_MOSI 23
#define TFT_SCLK 18
#include <menu.h>
#include <menuIO/serialIO.h>
#include <menuIO/TFT_eSPIOut.h>
// #include <menuIO/chainStream.h>
#include <menuIO/esp8266Out.h>//must include this even if not doing web output...
using namespace Menu;
TFT_eSPI gfx;
result doAlert(eventMask e, prompt &item);
int test=55;
int ledCtrl=LOW;
result myLedOn() {
ledCtrl=HIGH;
return proceed;
}
result myLedOff() {
ledCtrl=LOW;
return proceed;
}
TOGGLE(ledCtrl,setLed,"Led: ",doNothing,noEvent,noStyle//,doExit,enterEvent,noStyle
,VALUE("On",HIGH,doNothing,noEvent)
,VALUE("Off",LOW,doNothing,noEvent)
);
int selTest=1;
SELECT(selTest,selMenu,"Select",doNothing,noEvent,noStyle
,VALUE("Zero",0,doNothing,noEvent)
,VALUE("One",1,doNothing,noEvent)
,VALUE("Two",2,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
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) override {
return out.printRaw(F("special prompt!"),len);;
}
};
MENU(subMenu,"Sub-Menu",doNothing,noEvent,noStyle
,altOP(altPrompt,"",doNothing,noEvent)
,OP("Op",doNothing,noEvent)
,EXIT("<Back")
);
const char* constMEM hexDigit MEMMODE="0123456789ABCDEF";
const char* constMEM hexNr[] MEMMODE={"0","x",hexDigit,hexDigit};
char buf1[]="0x11";
MENU(mainMenu,"Main menu",doNothing,noEvent,wrapStyle
,OP("Op1",doNothing,noEvent)
,OP("Op2",doNothing,noEvent)
,FIELD(test,"Test","%",0,100,10,1,doNothing,noEvent,noStyle)
,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("<Back")
);
// define menu colors --------------------------------------------------------
// {{disabled normal,disabled selected},{enabled normal,enabled selected, enabled editing}}
//monochromatic color table
#define Black RGB565(0,0,0)
#define Red RGB565(255,0,0)
#define Green RGB565(0,255,0)
#define Blue RGB565(0,0,255)
#define Gray RGB565(128,128,128)
#define LighterRed RGB565(255,150,150)
#define LighterGreen RGB565(150,255,150)
#define LighterBlue RGB565(150,150,255)
#define DarkerRed RGB565(150,0,0)
#define DarkerGreen RGB565(0,150,0)
#define DarkerBlue RGB565(0,0,150)
#define Cyan RGB565(0,255,255)
#define Magenta RGB565(255,0,255)
#define Yellow RGB565(255,255,0)
#define White RGB565(255,255,255)
const colorDef<uint16_t> colors[6] MEMMODE={
{{(uint16_t)DarkerGreen,(uint16_t)DarkerRed}, {(uint16_t)Black, (uint16_t)LighterBlue, (uint16_t)Blue}},//bgColor
{{(uint16_t)Gray, (uint16_t)LighterRed}, {(uint16_t)White, (uint16_t)White, (uint16_t)White}},//fgColor
{{(uint16_t)White,(uint16_t)Black}, {(uint16_t)Yellow,(uint16_t)Yellow,(uint16_t)Red}},//valColor
{{(uint16_t)White,(uint16_t)Black}, {(uint16_t)White, (uint16_t)Yellow,(uint16_t)Yellow}},//unitColor
{{(uint16_t)White,(uint16_t)Gray}, {(uint16_t)Black, (uint16_t)Blue, (uint16_t)White}},//cursorColor, i.e. the box outline(?)
{{(uint16_t)White,(uint16_t)Yellow},{(uint16_t)Blue, (uint16_t)White, (uint16_t)Red}},//titleColor
};
#define MAX_DEPTH 4
serialIn serial(Serial);
//MENU_INPUTS(in,&serial);its single, no need to `chainStream`
//define serial output device
idx_t serialTops[MAX_DEPTH]={0};
serialOut outSerial(Serial,serialTops);
// #define GFX_WIDTH 128
// #define GFX_HEIGHT 64
// #define fontW 6
// #define fontH 9
#define GFX_WIDTH 240
#define GFX_HEIGHT 320
#define fontW 6*2
#define fontH 9*2
const panel panels[] MEMMODE = {{0, 0, GFX_WIDTH / fontW, GFX_HEIGHT / fontH}};
navNode* nodes[sizeof(panels) / sizeof(panel)]; //navNodes to store navigation status
panelsList pList(panels, nodes, 1); //a list of panels and nodes
idx_t eSpiTops[MAX_DEPTH]={0};
TFT_eSPIOut eSpiOut(gfx,colors,eSpiTops,pList,fontW,fontH+1);
menuOut* constMEM outputs[] MEMMODE={&outSerial,&eSpiOut};//list of output devices
outputsList out(outputs,sizeof(outputs)/sizeof(menuOut*));//outputs list controller
NAVROOT(nav,mainMenu,MAX_DEPTH,serial,out);
//when menu is suspended
result idle(menuOut& o,idleEvent e) {
if (e==idling) {
o.println(F("suspended..."));
o.println(F("press [select]"));
o.println(F("to continue"));
}
return proceed;
}
//config myOptions('*','-',defaultNavCodes,false);
void setup() {
//options=&myOptions;//can customize options
// pinMode(LEDPIN,OUTPUT);
Serial.begin(115200);
while(!Serial);
Serial.println("menu 4.x test");
Serial.flush();
nav.idleTask=idle;//point a function to be used when menu is suspended
mainMenu[1].disable();
//outGfx.usePreview=true;//reserve one panel for preview?
//nav.showTitle=false;//show menu title?
SPI.begin();
gfx.init();
// gfx.setRotation(3);
gfx.setTextSize(2);//test scalling
gfx.setTextWrap(false);
gfx.fillScreen(Black);
gfx.setTextColor(Red,Black);
gfx.println("Menu 4.x test on GFX");
delay(1000);
}
void loop() {
nav.poll();//this device only draws when needed
// digitalWrite(LEDPIN, ledCtrl);
delay(100);//simulate a delay when other tasks are done
}
result doAlert(eventMask e, prompt &item) {
Serial.println("Event Alert!");
return proceed;
}