Skip to content

Commit baf28f4

Browse files
committed
Merge branch 'bad_sd_template'
2 parents e171a27 + b9dd09b commit baf28f4

File tree

11 files changed

+348
-32
lines changed

11 files changed

+348
-32
lines changed

README.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void loop() {
9797
Some applications using ArduinoMenu, (current and older versions).
9898
Do you have another? please let me know on gitter or email me.
9999
100-
**ServoBox** Servo tester & monitor
100+
**ServoBox** Servo tester & monitor
101101
https://github.com/jarkman/ServoBox
102102
103103
**PANOBOT** A Panorama robot
@@ -190,6 +190,14 @@ https://github.com/greiman/SSD1306Ascii
190190
191191
- OLED Screens based on SSD1306 controller
192192
193+
**TFT_eSPI**
194+
195+
An Arduino IDE compatible graphics and fonts library for ESP8266 and ESP32
196+
https://github.com/Bodmer/TFT_eSPI
197+
198+
- ILI9341, ILI9163, ST7735, S6D02A1, ILI9481, ILI9486, ILI9488, HX8357D, ST7789, ILI9486
199+
- Waveshare 2 and 3 colour SPI ePaper displays
200+
193201
**TFT_HX8357 driver**
194202
195203
https://github.com/Bodmer/TFT_HX8357

examples/SDCard/SDCard/SDCard.ino

+7-7
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,25 @@ using namespace Menu;
1818

1919
//function to handle file select
2020
// declared here and implemented bellow because we need
21-
// to give it as event handler for `sdFolder`
22-
// and we also need to refer to `sdFolder` inside the function
21+
// to give it as event handler for `sdFolderMenu`
22+
// and we also need to refer to `sdFolderMenu` inside the function
2323
result sdFolder(eventMask event, navNode& nav, prompt &item);
2424

2525
SDMenu sdFolderMenu("SD Card","/",sdFolder,enterEvent);
2626

2727
//implementing the handler here after sdFolder is defined...
2828
result sdFolder(eventMask event, navNode& nav, prompt &item) {
29-
switch(event) {
30-
case enterCmd:
31-
if (nav.root->navFocus==&sdFolderMenu) {
29+
// switch(event) {//for now events are filtered only for enter, so we dont need this checking
30+
// case enterCmd:
31+
if (nav.root->navFocus==(navTarget*)&sdFolderMenu) {
3232
Serial.println();
3333
Serial.print("selected file:");
3434
Serial.println(sdFolderMenu.selectedFile);
3535
Serial.print("from folder:");
3636
Serial.println(sdFolderMenu.folderName);
3737
}
38-
break;
39-
}
38+
// break;
39+
// }
4040
return proceed;
4141
}
4242

examples/SSD1306Ascii/SSD1306Ascii/SSD1306Ascii.ino

+3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434

3535
#include <Arduino.h>
3636

37+
constexpr int OLED_SDA=4;
38+
constexpr int OLED_SDC=5;
39+
3740
#define I2C_ADDRESS 0x3C
3841
// #include <Wire.h>
3942
#include "SSD1306Ascii.h"

examples/SSD1306Ascii/platformio.ini

+9-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
; http://docs.platformio.org/page/projectconf.html
1010

1111
[platformio]
12-
src_dir=Button_Navigation
13-
;src_dir=SSD1306Ascii
12+
; src_dir=Button_Navigation
13+
src_dir=SSD1306Ascii
1414

1515
[env:nanoatmega328]
1616
platform = atmelavr
@@ -34,3 +34,10 @@ src_build_flags = !echo "-Wno-write-strings -Wno-reorder -fno-strict-aliasing -D
3434
; framework = arduino
3535
; upload_speed=921600
3636
; build_flags = -lstdc++ -DDEBUG
37+
38+
; [env:wemos]
39+
; platform = espressif8266
40+
; board = d1_mini_pro
41+
; framework = arduino
42+
; ; upload_speed=1500000
43+
; upload_speed=921600
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
#include <Arduino.h>
2+
3+
/********************
4+
Sept. 2014 ~ Jan 2019 Rui Azevedo - ruihfazevedo(@rrob@)gmail.com
5+
6+
TFT_eSPI example
7+
output: TFT_eSPI + Serial
8+
input: Serial
9+
www.r-site.net
10+
***/
11+
12+
#include <TFT_eSPI.h>
13+
14+
#include <menu.h>
15+
#include <menuIO/serialIO.h>
16+
#include <menuIO/TFT_eSPIOut.h>
17+
// #include <menuIO/chainStream.h>
18+
19+
using namespace Menu;
20+
21+
TFT_eSPI gfx;
22+
23+
result doAlert(eventMask e, prompt &item);
24+
25+
int test=55;
26+
27+
int ledCtrl=LOW;
28+
29+
result myLedOn() {
30+
ledCtrl=HIGH;
31+
return proceed;
32+
}
33+
result myLedOff() {
34+
ledCtrl=LOW;
35+
return proceed;
36+
}
37+
38+
TOGGLE(ledCtrl,setLed,"Led: ",doNothing,noEvent,noStyle//,doExit,enterEvent,noStyle
39+
,VALUE("On",HIGH,doNothing,noEvent)
40+
,VALUE("Off",LOW,doNothing,noEvent)
41+
);
42+
43+
int selTest=0;
44+
SELECT(selTest,selMenu,"Select",doNothing,noEvent,noStyle
45+
,VALUE("Zero",0,doNothing,noEvent)
46+
,VALUE("One",1,doNothing,noEvent)
47+
,VALUE("Two",2,doNothing,noEvent)
48+
);
49+
50+
int chooseTest=-1;
51+
CHOOSE(chooseTest,chooseMenu,"Choose",doNothing,noEvent,noStyle
52+
,VALUE("First",1,doNothing,noEvent)
53+
,VALUE("Second",2,doNothing,noEvent)
54+
,VALUE("Third",3,doNothing,noEvent)
55+
,VALUE("Last",-1,doNothing,noEvent)
56+
);
57+
58+
//customizing a prompt look!
59+
//by extending the prompt class
60+
class altPrompt:public prompt {
61+
public:
62+
altPrompt(constMEM promptShadow& p):prompt(p) {}
63+
Used printTo(navRoot &root,bool sel,menuOut& out, idx_t idx,idx_t len,idx_t) override {
64+
return out.printRaw(F("special prompt!"),len);;
65+
}
66+
};
67+
68+
MENU(subMenu,"Sub-Menu",doNothing,noEvent,noStyle
69+
,altOP(altPrompt,"",doNothing,noEvent)
70+
,OP("Op",doNothing,noEvent)
71+
,EXIT("<Back")
72+
);
73+
74+
char* constMEM hexDigit MEMMODE="0123456789ABCDEF";
75+
char* constMEM hexNr[] MEMMODE={"0","x",hexDigit,hexDigit};
76+
char buf1[]="0x11";
77+
78+
MENU(mainMenu,"Main menu",doNothing,noEvent,wrapStyle
79+
,OP("Op1",doNothing,noEvent)
80+
,OP("Op2",doNothing,noEvent)
81+
// ,FIELD(test,"Test","%",0,100,10,1,doNothing,noEvent,wrapStyle)
82+
,SUBMENU(subMenu)
83+
,SUBMENU(setLed)
84+
,OP("LED On",myLedOn,enterEvent)
85+
,OP("LED Off",myLedOff,enterEvent)
86+
,SUBMENU(selMenu)
87+
,SUBMENU(chooseMenu)
88+
//,OP("Alert test",doAlert,enterEvent)
89+
,EDIT("Hex",buf1,hexNr,doNothing,noEvent,noStyle)
90+
,EXIT("<Back")
91+
);
92+
93+
// define menu colors --------------------------------------------------------
94+
// {{disabled normal,disabled selected},{enabled normal,enabled selected, enabled editing}}
95+
//monochromatic color table
96+
97+
98+
#define Black RGB565(0,0,0)
99+
#define Red RGB565(255,0,0)
100+
#define Green RGB565(0,255,0)
101+
#define Blue RGB565(0,0,255)
102+
#define Gray RGB565(128,128,128)
103+
#define LighterRed RGB565(255,150,150)
104+
#define LighterGreen RGB565(150,255,150)
105+
#define LighterBlue RGB565(150,150,255)
106+
#define DarkerRed RGB565(150,0,0)
107+
#define DarkerGreen RGB565(0,150,0)
108+
#define DarkerBlue RGB565(0,0,150)
109+
#define Cyan RGB565(0,255,255)
110+
#define Magenta RGB565(255,0,255)
111+
#define Yellow RGB565(255,255,0)
112+
#define White RGB565(255,255,255)
113+
114+
const colorDef<uint16_t> colors[] MEMMODE={
115+
{{(uint16_t)Black,(uint16_t)Black}, {(uint16_t)Black, (uint16_t)Blue, (uint16_t)Blue}},//bgColor
116+
{{(uint16_t)Gray, (uint16_t)Gray}, {(uint16_t)White, (uint16_t)White, (uint16_t)White}},//fgColor
117+
{{(uint16_t)White,(uint16_t)Black}, {(uint16_t)Yellow,(uint16_t)Yellow,(uint16_t)Red}},//valColor
118+
{{(uint16_t)White,(uint16_t)Black}, {(uint16_t)White, (uint16_t)Yellow,(uint16_t)Yellow}},//unitColor
119+
{{(uint16_t)White,(uint16_t)Gray}, {(uint16_t)Black, (uint16_t)Blue, (uint16_t)White}},//cursorColor
120+
{{(uint16_t)White,(uint16_t)Yellow},{(uint16_t)Blue, (uint16_t)Red, (uint16_t)Red}},//titleColor
121+
};
122+
123+
#define MAX_DEPTH 4
124+
125+
serialIn serial(Serial);
126+
127+
//MENU_INPUTS(in,&serial);its single, no need to `chainStream`
128+
129+
//define serial output device
130+
idx_t serialTops[MAX_DEPTH]={0};
131+
serialOut outSerial(Serial,serialTops);
132+
133+
#define GFX_WIDTH 128
134+
#define GFX_HEIGHT 64
135+
#define fontW 6
136+
#define fontH 9
137+
138+
constMEM panel panels[] MEMMODE = {{0, 0, GFX_WIDTH / fontW, GFX_HEIGHT / fontH}};
139+
navNode* nodes[sizeof(panels) / sizeof(panel)]; //navNodes to store navigation status
140+
panelsList pList(panels, nodes, 1); //a list of panels and nodes
141+
idx_t eSpiTops[MAX_DEPTH]={0};
142+
TFT_eSPIOut eSpiOut(gfx,colors,eSpiTops,pList,fontW,fontH+1);
143+
menuOut* constMEM outputs[] MEMMODE={&outSerial,&eSpiOut};//list of output devices
144+
outputsList out(outputs,sizeof(outputs)/sizeof(menuOut*));//outputs list controller
145+
146+
NAVROOT(nav,mainMenu,MAX_DEPTH,serial,out);
147+
148+
//when menu is suspended
149+
result idle(menuOut& o,idleEvent e) {
150+
if (e==idling) {
151+
o.println(F("suspended..."));
152+
o.println(F("press [select]"));
153+
o.println(F("to continue"));
154+
}
155+
return proceed;
156+
}
157+
158+
//config myOptions('*','-',defaultNavCodes,false);
159+
160+
void setup() {
161+
//options=&myOptions;//can customize options
162+
// pinMode(LEDPIN,OUTPUT);
163+
Serial.begin(115200);
164+
while(!Serial);
165+
Serial.println("menu 4.x test");
166+
Serial.flush();
167+
nav.idleTask=idle;//point a function to be used when menu is suspended
168+
mainMenu[1].disable();
169+
//outGfx.usePreview=true;//reserve one panel for preview?
170+
//nav.showTitle=false;//show menu title?
171+
172+
SPI.begin();
173+
// gfx.initR(INITR_BLACKTAB);
174+
gfx.setRotation(3);
175+
// gfx.setTextSize(textScale);//test scalling
176+
gfx.setTextWrap(false);
177+
gfx.fillScreen(Black);
178+
gfx.setTextColor(Red,Black);
179+
gfx.println("Menu 4.x test on GFX");
180+
delay(1000);
181+
}
182+
183+
void loop() {
184+
nav.poll();//this device only draws when needed
185+
// digitalWrite(LEDPIN, ledCtrl);
186+
delay(100);//simulate a delay when other tasks are done
187+
}

library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=ArduinoMenu library
2-
version=4.16.0
2+
version=4.17.0
33
author=Rui Azevedo, [email protected]
44
maintainer=neu-rah, [email protected]
55
sentence=Generic menu/interactivity system

src/menu.h

+3
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,8 @@ warranty, express or implied, as to its usefulness for any purpose.
1313
#pragma once
1414

1515
#include "menuDefs.h"
16+
#ifdef ESP8266
17+
#include "menuIO/esp8266Out.h"
18+
#endif
1619

1720
#include "itemsTemplates.cpp"

src/menuIO/TFT_eSPIOut.h

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/* -*- C++ -*- */
2+
/********************
3+
by:
4+
https://github.com/fa1ke5 (Jan. 2019)
5+
posted here: https://github.com/neu-rah/ArduinoMenu/issues/225 (thank you)
6+
based on:
7+
Rui Azevedo - ruihfazevedo(@rrob@)gmail.com (Sept. 2014)
8+
9+
Use graphics screens (adafruit library based) as menu output
10+
www.r-site.net
11+
12+
***/
13+
#pragma once
14+
15+
#ifndef RSITE_ARDUINOP_MENU_TFT_ESPI
16+
#define RSITE_ARDUINOP_MENU_TFT_ESPI
17+
#include <TFT_eSPI.h>
18+
#include "../menuDefs.h"
19+
20+
// usage:
21+
// #include <TFT_eSPI.h>
22+
// TFT_eSPI gfx = TFT_eSPI();
23+
// #include <menu.h>
24+
// #include <menuIO/TFT_eSPIOut.h>
25+
// T_eSPI gfx = TFT_eSPI();
26+
27+
namespace Menu {
28+
29+
#define RGB565(r,g,b) ((((r>>3)<<11) | ((g>>2)<<5) | (b>>3)))
30+
31+
class TFT_eSPIOut:public gfxOut {
32+
public:
33+
TFT_eSPI& gfx;
34+
const colorDef<uint16_t> (&colors)[nColors];
35+
TFT_eSPIOut(TFT_eSPI& gfx,const colorDef<uint16_t> (&c)[nColors],idx_t* t,panelsList &p,idx_t resX=6,idx_t resY=9)
36+
:gfxOut(resX,resY,t,p),gfx(gfx),colors(c) {}
37+
//:gfxOut(gfx.width()/resX,gfx.height()/resY,resX,resY,false),colors(c),gfx(gfx) {}
38+
39+
size_t write(uint8_t ch) override {return gfx.write(ch);}
40+
41+
inline uint16_t getColor(colorDefs color=bgColor,bool selected=false,status stat=enabledStatus,bool edit=false) const {
42+
return memWord(&(stat==enabledStatus?colors[color].enabled[selected+edit]:colors[color].disabled[selected]));
43+
}
44+
45+
void setColor(colorDefs c,bool selected=false,status s=enabledStatus,bool e=false) override {
46+
gfx.setTextColor(getColor(c,selected,s,e));
47+
}
48+
49+
void clearLine(idx_t ln,idx_t panelNr=0,colorDefs color=bgColor,bool selected=false,status stat=enabledStatus,bool edit=false) override {
50+
const panel p=panels[panelNr];
51+
gfx.fillRect(p.x*resX,(p.y+ln)*resY,p.maxX()*resX,resY,getColor(color,selected,stat,edit));
52+
//setCursor(0,ln);
53+
}
54+
void clear() override {
55+
panels.reset();
56+
gfx.fillScreen(getColor(bgColor,false,enabledStatus,false));
57+
setCursor(0,0);
58+
setColor(fgColor);
59+
}
60+
61+
void box(idx_t panelNr,idx_t x,idx_t y,idx_t w=1,idx_t h=1,colorDefs c=bgColor,bool selected=false,status stat=enabledStatus,bool edit=false) override {
62+
const panel p=panels[panelNr];
63+
gfx.drawRect((p.x+x)*resX,(p.y+y)*resY,w*resX,h*resY,getColor(c,selected,stat,edit));
64+
}
65+
66+
void rect(idx_t panelNr,idx_t x,idx_t y,idx_t w=1,idx_t h=1,colorDefs c=bgColor,bool selected=false,status stat=enabledStatus,bool edit=false) override {
67+
const panel p=panels[panelNr];
68+
gfx.fillRect((p.x+x)*resX,(p.y+y)*resY,w*resX,h*resY,getColor(c,selected,stat,edit));
69+
}
70+
71+
void clear(idx_t panelNr) override {
72+
const panel p=panels[panelNr];
73+
gfx.fillRect(p.x*resX,p.y*resY,p.w*resX,p.h*resY,getColor(bgColor,false,enabledStatus,false));
74+
panels.nodes[panelNr]=NULL;
75+
}
76+
77+
void setCursor(idx_t x,idx_t y,idx_t panelNr=0) override {
78+
const panel p=panels[panelNr];
79+
gfx.setCursor((p.x+x)*resX,(p.y+y)*resY+fontMarginY);
80+
}
81+
82+
void drawCursor(idx_t ln,bool selected,status stat,bool edit=false,idx_t panelNr=0) override {
83+
const panel p=panels[panelNr];
84+
// gfxOut::drawCursor(ln,selected,stat);
85+
gfx.drawRect(p.x*resX,(p.y+ln)*resY,maxX()*resX,resY,getColor(cursorColor,selected,enabledStatus,false));
86+
}
87+
};
88+
89+
};
90+
#endif

src/menuIO/esp8266Out.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
#ifndef RSITE_ARDUINO_MENU_ESP8266OUT
44
#define RSITE_ARDUINO_MENU_ESP8266OUT
55
#include "../menuDefs.h"
6-
#include <ESP8266WiFi.h>
6+
// #include <ESP8266WiFi.h>
77
// based on WebServer:
88
// https://github.com/esp8266/Arduino/tree/master/libraries/ESP8266WebServer
99
// https://github.com/Links2004/arduinoWebSockets
10-
#include <WebSocketsServer.h>
10+
// #include <WebSocketsServer.h>
1111
#include <ESP8266WebServer.h>
1212
#include <vector>
1313
#include "xmlFmt.h"

0 commit comments

Comments
 (0)