Skip to content

Commit aea20f3

Browse files
author
dave
committed
new example for ESP32 using a LCD screen
1 parent 84356d4 commit aea20f3

File tree

6 files changed

+548
-0
lines changed

6 files changed

+548
-0
lines changed

examples/esp32Lcd/Esp32Lcd.emf

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
{
2+
"version": "1.00",
3+
"projectName": "/Users/dave/Documents/Arduino/tcLibraryDev/lib/tcMenu/examples/esp32Lcd/Esp32Lcd.emf",
4+
"author": "dave",
5+
"items": [
6+
{
7+
"parentId": 0,
8+
"type": "analogItem",
9+
"item": {
10+
"maxValue": 100,
11+
"offset": 0,
12+
"divisor": 1,
13+
"unitName": "%",
14+
"name": "Percentage",
15+
"variableName": "Percentage",
16+
"id": 1,
17+
"eepromAddress": -1,
18+
"readOnly": false,
19+
"localOnly": false,
20+
"visible": true
21+
}
22+
},
23+
{
24+
"parentId": 0,
25+
"type": "enumItem",
26+
"item": {
27+
"enumEntries": [
28+
"Apples",
29+
"Bananas",
30+
"Oranges",
31+
"Grapes"
32+
],
33+
"name": "Foods",
34+
"variableName": "Foods",
35+
"id": 2,
36+
"eepromAddress": -1,
37+
"readOnly": false,
38+
"localOnly": false,
39+
"visible": true
40+
}
41+
},
42+
{
43+
"parentId": 0,
44+
"type": "boolItem",
45+
"item": {
46+
"naming": "ON_OFF",
47+
"name": "Power",
48+
"variableName": "Peeled",
49+
"id": 3,
50+
"eepromAddress": -1,
51+
"readOnly": false,
52+
"localOnly": false,
53+
"visible": true
54+
}
55+
},
56+
{
57+
"parentId": 0,
58+
"type": "runtimeList",
59+
"item": {
60+
"initialRows": 0,
61+
"name": "MyList",
62+
"variableName": "MyList",
63+
"id": 4,
64+
"eepromAddress": -1,
65+
"functionName": "",
66+
"readOnly": false,
67+
"localOnly": false,
68+
"visible": true
69+
}
70+
},
71+
{
72+
"parentId": 0,
73+
"type": "rgbItem",
74+
"item": {
75+
"includeAlphaChannel": false,
76+
"name": "RGB",
77+
"variableName": "RGB",
78+
"id": 5,
79+
"eepromAddress": -1,
80+
"readOnly": false,
81+
"localOnly": false,
82+
"visible": true
83+
}
84+
}
85+
],
86+
"codeOptions": {
87+
"embeddedPlatform": "ARDUINO_ESP32",
88+
"lastDisplayUuid": "d4c84106-fa87-4024-b91e-053e17a52b8f",
89+
"lastInputUuid": "6dd87e7d-e751-4912-a70d-91793b1d3d87",
90+
"lastRemoteUuid": "2c101fec-1f7d-4ff3-8d2b-992ad41e7fcb",
91+
"lastThemeUuid": "850dc0a3-f534-47c2-94d8-1e64ff368a54",
92+
"applicationUUID": "7833942f-2ef4-486f-9713-045552b747e8",
93+
"applicationName": "Esp32Lcd",
94+
"lastProperties": [
95+
{
96+
"name": "LCD_WIDTH",
97+
"latestValue": "20",
98+
"subsystem": "DISPLAY"
99+
},
100+
{
101+
"name": "LCD_HEIGHT",
102+
"latestValue": "4",
103+
"subsystem": "DISPLAY"
104+
},
105+
{
106+
"name": "I2C_ADDRESS",
107+
"latestValue": "0x27",
108+
"subsystem": "DISPLAY"
109+
},
110+
{
111+
"name": "PIN_LAYOUT",
112+
"latestValue": "RS_RW_EN",
113+
"subsystem": "DISPLAY"
114+
},
115+
{
116+
"name": "WIRE_VARIABLE",
117+
"latestValue": "Wire",
118+
"subsystem": "DISPLAY"
119+
},
120+
{
121+
"name": "UNO_OR_FULL",
122+
"latestValue": "fullLcd",
123+
"subsystem": "DISPLAY"
124+
},
125+
{
126+
"name": "UPDATES_PER_SEC",
127+
"latestValue": "2",
128+
"subsystem": "DISPLAY"
129+
},
130+
{
131+
"name": "PULLUP_LOGIC",
132+
"latestValue": "true",
133+
"subsystem": "INPUT"
134+
},
135+
{
136+
"name": "INTERRUPT_SWITCHES",
137+
"latestValue": "true",
138+
"subsystem": "INPUT"
139+
},
140+
{
141+
"name": "SWITCH_IODEVICE",
142+
"latestValue": "",
143+
"subsystem": "INPUT"
144+
},
145+
{
146+
"name": "ENCODER_PIN_A",
147+
"latestValue": "26",
148+
"subsystem": "INPUT"
149+
},
150+
{
151+
"name": "ENCODER_PIN_B",
152+
"latestValue": "36",
153+
"subsystem": "INPUT"
154+
},
155+
{
156+
"name": "ENCODER_PIN_OK",
157+
"latestValue": "21",
158+
"subsystem": "INPUT"
159+
},
160+
{
161+
"name": "ENCODER_BACK_PIN",
162+
"latestValue": "-1",
163+
"subsystem": "INPUT"
164+
},
165+
{
166+
"name": "ENCODER_NEXT_PIN",
167+
"latestValue": "-1",
168+
"subsystem": "INPUT"
169+
},
170+
{
171+
"name": "ENCODER_IS_QUARTER_CYCLE",
172+
"latestValue": "false",
173+
"subsystem": "INPUT"
174+
},
175+
{
176+
"name": "ITEM_FONT",
177+
"latestValue": "def:,1",
178+
"subsystem": "THEME"
179+
},
180+
{
181+
"name": "TITLE_FONT",
182+
"latestValue": "def:,1",
183+
"subsystem": "THEME"
184+
},
185+
{
186+
"name": "BORDER_FOR_ACTIONS",
187+
"latestValue": "0",
188+
"subsystem": "THEME"
189+
},
190+
{
191+
"name": "TITLE_SHOW_MODE",
192+
"latestValue": "TITLE_FIRST_ROW",
193+
"subsystem": "THEME"
194+
},
195+
{
196+
"name": "USE_SLIDER_ANALOG",
197+
"latestValue": "true",
198+
"subsystem": "THEME"
199+
},
200+
{
201+
"name": "NEED_EDITING_ICONS",
202+
"latestValue": "false",
203+
"subsystem": "THEME"
204+
}
205+
],
206+
"namingRecursive": true,
207+
"saveToSrc": false,
208+
"useCppMain": false
209+
}
210+
}

examples/esp32Lcd/esp32Lcd.ino

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include "esp32Lcd_menu.h"
2+
3+
void setup() {
4+
Serial.begin(115200);
5+
Wire.begin(4, 15);
6+
setupMenu();
7+
8+
}
9+
10+
void loop() {
11+
taskManager.runLoop();
12+
13+
}
14+
15+
16+
// see tcMenu list documentation on thecoderscorner.com
17+
int CALLBACK_FUNCTION fnMyListRtCall(RuntimeMenuItem* item, uint8_t row, RenderFnMode mode, char* buffer, int bufferSize) {
18+
switch(mode) {
19+
case RENDERFN_INVOKE:
20+
// TODO - your code to invoke goes here - row is the index of the item
21+
return true;
22+
case RENDERFN_NAME:
23+
// TODO - each row has it's own name - 0xff is the parent item
24+
ltoaClrBuff(buffer, row, 3, NOT_PADDED, bufferSize);
25+
return true;
26+
case RENDERFN_VALUE:
27+
// TODO - each row can has its own value - 0xff is the parent item
28+
buffer[0] = 'V'; buffer[1]=0;
29+
fastltoa(buffer, row, 3, NOT_PADDED, bufferSize);
30+
return true;
31+
case RENDERFN_EEPROM_POS: return 0xffff; // lists are generally not saved to EEPROM
32+
default: return false;
33+
}
34+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
The code in this file uses open source libraries provided by thecoderscorner
3+
4+
DO NOT EDIT THIS FILE, IT WILL BE GENERATED EVERY TIME YOU USE THE UI DESIGNER
5+
INSTEAD EITHER PUT CODE IN YOUR SKETCH OR CREATE ANOTHER SOURCE FILE.
6+
7+
All the variables you may need access to are marked extern in this file for easy
8+
use elsewhere.
9+
*/
10+
11+
#include <tcMenu.h>
12+
#include "esp32Lcd_menu.h"
13+
14+
// Global variable declarations
15+
16+
const PROGMEM ConnectorLocalInfo applicationInfo = { "Esp32Lcd", "7833942f-2ef4-486f-9713-045552b747e8" };
17+
LiquidCrystal lcd(0, 1, 2, 4, 5, 6, 7);
18+
LiquidCrystalRenderer renderer(lcd, 20, 4);
19+
20+
// Global Menu Item declarations
21+
22+
RENDERING_CALLBACK_NAME_INVOKE(fnRGBRtCall, rgbAlphaItemRenderFn, "RGB", -1, NO_CALLBACK)
23+
Rgb32MenuItem menuRGB(5, fnRGBRtCall, false, NULL);
24+
ListRuntimeMenuItem menuMyList(4, 0, fnMyListRtCall, &menuRGB);
25+
const PROGMEM BooleanMenuInfo minfoPeeled = { "Power", 3, 0xffff, 1, NO_CALLBACK, NAMING_ON_OFF };
26+
BooleanMenuItem menuPeeled(&minfoPeeled, false, &menuMyList);
27+
const char enumStrFoods_0[] PROGMEM = "Apples";
28+
const char enumStrFoods_1[] PROGMEM = "Bananas";
29+
const char enumStrFoods_2[] PROGMEM = "Oranges";
30+
const char enumStrFoods_3[] PROGMEM = "Grapes";
31+
const char* const enumStrFoods[] PROGMEM = { enumStrFoods_0, enumStrFoods_1, enumStrFoods_2, enumStrFoods_3 };
32+
const PROGMEM EnumMenuInfo minfoFoods = { "Foods", 2, 0xffff, 3, NO_CALLBACK, enumStrFoods };
33+
EnumMenuItem menuFoods(&minfoFoods, 0, &menuPeeled);
34+
const PROGMEM AnalogMenuInfo minfoPercentage = { "Percentage", 1, 0xffff, 100, NO_CALLBACK, 0, 1, "%" };
35+
AnalogMenuItem menuPercentage(&minfoPercentage, 0, &menuFoods);
36+
37+
// Set up code
38+
39+
void setupMenu() {
40+
Wire.begin();
41+
lcd.setIoAbstraction(ioFrom8574(0x27, 0xff, &Wire));
42+
lcd.begin(20, 4);
43+
renderer.setUpdatesPerSecond(2);
44+
lcd.configureBacklightPin(3);
45+
lcd.backlight();
46+
switches.initialiseInterrupt(internalDigitalIo(), true);
47+
menuMgr.initForEncoder(&renderer, &menuPercentage, 26, 36, 21);
48+
}
49+

examples/esp32Lcd/esp32Lcd_menu.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
The code in this file uses open source libraries provided by thecoderscorner
3+
4+
DO NOT EDIT THIS FILE, IT WILL BE GENERATED EVERY TIME YOU USE THE UI DESIGNER
5+
INSTEAD EITHER PUT CODE IN YOUR SKETCH OR CREATE ANOTHER SOURCE FILE.
6+
7+
All the variables you may need access to are marked extern in this file for easy
8+
use elsewhere.
9+
*/
10+
11+
#ifndef MENU_GENERATED_CODE_H
12+
#define MENU_GENERATED_CODE_H
13+
14+
#include <Arduino.h>
15+
#include <tcMenu.h>
16+
#include <Wire.h>
17+
#include <LiquidCrystalIO.h>
18+
#include <IoAbstractionWire.h>
19+
#include <ScrollChoiceMenuItem.h>
20+
#include <RuntimeMenuItem.h>
21+
#include "tcMenuLiquidCrystal.h"
22+
23+
void setupMenu(); // forward reference of the menu setup function.
24+
extern const PROGMEM ConnectorLocalInfo applicationInfo; // contains app name and ID
25+
26+
// Global variables that need exporting
27+
28+
extern LiquidCrystal lcd;
29+
extern LiquidCrystalRenderer renderer;
30+
31+
// Global Menu Item exports
32+
33+
extern Rgb32MenuItem menuRGB;
34+
extern ListRuntimeMenuItem menuMyList;
35+
extern BooleanMenuItem menuPeeled;
36+
extern EnumMenuItem menuFoods;
37+
extern AnalogMenuItem menuPercentage;
38+
39+
// Provide a wrapper to get hold of the root menu item
40+
inline MenuItem& rootMenuItem() { return menuPercentage; }
41+
42+
// Callback functions must always include CALLBACK_FUNCTION after the return type
43+
#define CALLBACK_FUNCTION
44+
45+
int fnMyListRtCall(RuntimeMenuItem* item, uint8_t row, RenderFnMode mode, char* buffer, int bufferSize);
46+
47+
#endif // MENU_GENERATED_CODE_H

0 commit comments

Comments
 (0)