Skip to content

Commit b1a663a

Browse files
committed
#166 support for custom menu items, both runtime and info based items.
1 parent 9ff9bee commit b1a663a

17 files changed

+1523
-119
lines changed

examples/arduino32/piPicoTftEncoder/piPicoTftEncoder.emf

Lines changed: 75 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"functionName": "onVolumeChanged",
2121
"readOnly": false,
2222
"localOnly": false,
23-
"visible": true
23+
"visible": true,
24+
"staticDataInRAM": false
2425
}
2526
},
2627
{
@@ -40,7 +41,8 @@
4041
"eepromAddress": 5,
4142
"readOnly": false,
4243
"localOnly": false,
43-
"visible": true
44+
"visible": true,
45+
"staticDataInRAM": false
4446
}
4547
},
4648
{
@@ -55,7 +57,8 @@
5557
"eepromAddress": 4,
5658
"readOnly": false,
5759
"localOnly": false,
58-
"visible": true
60+
"visible": true,
61+
"staticDataInRAM": false
5962
}
6063
},
6164
{
@@ -69,7 +72,8 @@
6972
"eepromAddress": -1,
7073
"readOnly": false,
7174
"localOnly": false,
72-
"visible": true
75+
"visible": true,
76+
"staticDataInRAM": false
7377
}
7478
},
7579
{
@@ -88,7 +92,8 @@
8892
"eepromAddress": 7,
8993
"readOnly": false,
9094
"localOnly": false,
91-
"visible": true
95+
"visible": true,
96+
"staticDataInRAM": false
9297
}
9398
},
9499
{
@@ -103,7 +108,8 @@
103108
"eepromAddress": -1,
104109
"readOnly": false,
105110
"localOnly": false,
106-
"visible": true
111+
"visible": true,
112+
"staticDataInRAM": false
107113
}
108114
},
109115
{
@@ -119,7 +125,8 @@
119125
"eepromAddress": 9,
120126
"readOnly": false,
121127
"localOnly": false,
122-
"visible": true
128+
"visible": true,
129+
"staticDataInRAM": false
123130
}
124131
},
125132
{
@@ -135,7 +142,8 @@
135142
"eepromAddress": 19,
136143
"readOnly": false,
137144
"localOnly": false,
138-
"visible": true
145+
"visible": true,
146+
"staticDataInRAM": false
139147
}
140148
},
141149
{
@@ -150,7 +158,8 @@
150158
"eepromAddress": -1,
151159
"readOnly": false,
152160
"localOnly": false,
153-
"visible": true
161+
"visible": true,
162+
"staticDataInRAM": false
154163
}
155164
},
156165
{
@@ -167,7 +176,8 @@
167176
"eepromAddress": -1,
168177
"readOnly": false,
169178
"localOnly": false,
170-
"visible": true
179+
"visible": true,
180+
"staticDataInRAM": false
171181
}
172182
},
173183
{
@@ -184,7 +194,8 @@
184194
"eepromAddress": -1,
185195
"readOnly": false,
186196
"localOnly": false,
187-
"visible": true
197+
"visible": true,
198+
"staticDataInRAM": false
188199
}
189200
},
190201
{
@@ -198,7 +209,8 @@
198209
"eepromAddress": -1,
199210
"readOnly": false,
200211
"localOnly": false,
201-
"visible": true
212+
"visible": true,
213+
"staticDataInRAM": false
202214
}
203215
},
204216
{
@@ -219,7 +231,8 @@
219231
"eepromAddress": -1,
220232
"readOnly": false,
221233
"localOnly": false,
222-
"visible": true
234+
"visible": true,
235+
"staticDataInRAM": false
223236
}
224237
},
225238
{
@@ -234,7 +247,8 @@
234247
"eepromAddress": -1,
235248
"readOnly": false,
236249
"localOnly": false,
237-
"visible": true
250+
"visible": true,
251+
"staticDataInRAM": false
238252
}
239253
},
240254
{
@@ -249,7 +263,8 @@
249263
"eepromAddress": -1,
250264
"readOnly": false,
251265
"localOnly": false,
252-
"visible": true
266+
"visible": true,
267+
"staticDataInRAM": false
253268
}
254269
},
255270
{
@@ -263,7 +278,26 @@
263278
"functionName": "onRestart",
264279
"readOnly": false,
265280
"localOnly": false,
266-
"visible": true
281+
"visible": true,
282+
"staticDataInRAM": true
283+
}
284+
},
285+
{
286+
"parentId": 7,
287+
"type": "textItem",
288+
"defaultValue": "",
289+
"item": {
290+
"textLength": 5,
291+
"itemType": "PLAIN_TEXT",
292+
"name": "Info",
293+
"variableName": "StatusInfo",
294+
"id": 19,
295+
"eepromAddress": -1,
296+
"functionName": "infoRenderingRtCall",
297+
"readOnly": false,
298+
"localOnly": false,
299+
"visible": true,
300+
"staticDataInRAM": false
267301
}
268302
},
269303
{
@@ -277,7 +311,8 @@
277311
"functionName": "onShowDialogs",
278312
"readOnly": false,
279313
"localOnly": false,
280-
"visible": true
314+
"visible": true,
315+
"staticDataInRAM": false
281316
}
282317
},
283318
{
@@ -292,7 +327,8 @@
292327
"functionName": "",
293328
"readOnly": false,
294329
"localOnly": false,
295-
"visible": true
330+
"visible": true,
331+
"staticDataInRAM": false
296332
}
297333
}
298334
],
@@ -328,6 +364,26 @@
328364
"latestValue": "15",
329365
"subsystem": "DISPLAY"
330366
},
367+
{
368+
"name": "INCLUDE_TOUCH_INBUILT",
369+
"latestValue": "false",
370+
"subsystem": "DISPLAY"
371+
},
372+
{
373+
"name": "TOUCH_ROTATION",
374+
"latestValue": "PORTRAIT",
375+
"subsystem": "DISPLAY"
376+
},
377+
{
378+
"name": "TOUCH_CALIB_WIDTH",
379+
"latestValue": "320",
380+
"subsystem": "DISPLAY"
381+
},
382+
{
383+
"name": "TOUCH_CALIB_HEIGHT",
384+
"latestValue": "240",
385+
"subsystem": "DISPLAY"
386+
},
331387
{
332388
"name": "SW_POLLING_MODE",
333389
"latestValue": "SWITCHES_POLL_EVERYTHING",
@@ -412,6 +468,7 @@
412468
"namingRecursive": true,
413469
"saveToSrc": false,
414470
"useCppMain": false,
471+
"usingSizedEEPROMStorage": false,
415472
"eepromDefinition": "",
416473
"authenticatorDefinition": "",
417474
"projectIoExpanders": [

examples/arduino32/piPicoTftEncoder/piPicoTftEncoder.ino

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,9 @@ void loop() {
5454
taskManager.runLoop();
5555
}
5656

57-
58-
void CALLBACK_FUNCTION onRestart(int /*id*/) {
59-
serdebugF("Restart selected");
60-
}
61-
62-
57+
/**
58+
* An example callback that was registered in the designer UI and generated for us here.
59+
*/
6360
void CALLBACK_FUNCTION onVolumeChanged(int /*id*/) {
6461
serdebugF2("Volume changed ", menuVolume.getCurrentValue());
6562
}
@@ -191,3 +188,42 @@ int CALLBACK_FUNCTION fnRootListRtCall(RuntimeMenuItem* item, uint8_t row, Rende
191188
default: return false;
192189
}
193190
}
191+
192+
//
193+
// For Item: menuStatusInfo
194+
//
195+
// Here we present how to customize a runtime menu item such as a text item, RGB or Large number. You can take full
196+
// control of the callback, or just override a few of the features to customize it.
197+
//
198+
// In this case we just want to override the name at runtime so we can change the name to be a counter of the number of
199+
// times it is drawn.
200+
//
201+
// Steps
202+
// 1. In the Designer of a text item, select "edit" next to the function callback text field
203+
// 2. Select the "Runtime RenderFn override implementation" option
204+
// 3. Once code generation the function is generated (exactly as below)
205+
//
206+
int CALLBACK_FUNCTION infoRenderingRtCall(RuntimeMenuItem* item, uint8_t row, RenderFnMode mode, char* buffer, int bufferSize) {
207+
static int staticCounter = 0;
208+
// See https://www.thecoderscorner.com/products/arduino-libraries/tc-menu/menu-item-types/based-on-runtimemenuitem/
209+
210+
switch(mode) {
211+
case RENDERFN_NAME:
212+
strncpy(buffer, "Count ", bufferSize);
213+
fastltoa(buffer, staticCounter++, 7, NOT_PADDED, bufferSize);
214+
return true; // override title by returning true
215+
}
216+
return textItemRenderFn(item, row, mode, buffer, bufferSize);
217+
}
218+
219+
/**
220+
* How to change an item based on an Info block, such as Analog, Enum, Boolean, Float, Action and SubMenu.
221+
*
222+
* This is a standard callback function, it is attached in designer to the restart menu item. Here we show how to
223+
* rename a menu item that is based on a menu info block.
224+
*/
225+
void CALLBACK_FUNCTION onRestart(int /*id*/) {
226+
serdebugF("Restart selected");
227+
strncpy(minfoStatusRestart.name, "Restarting", NAME_SIZE_T);
228+
menuStatusRestart.setChanged(true);
229+
}

examples/arduino32/piPicoTftEncoder/piPicoTftEncoder_menu.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,26 @@ GraphicsDeviceRenderer renderer(30, applicationInfo.name, &gfxDrawable);
2424
// Global Menu Item declarations
2525
ListRuntimeMenuItem menuRootList(17, 0, fnRootListRtCall, NULL);
2626
const AnyMenuInfo minfoDialogs = { "Dialogs", 12, 0xffff, 0, onShowDialogs };
27-
ActionMenuItem menuDialogs(&minfoDialogs, &menuRootList);
28-
const AnyMenuInfo minfoStatusRestart = { "Restart", 11, 0xffff, 0, onRestart };
29-
ActionMenuItem menuStatusRestart(&minfoStatusRestart, NULL);
27+
ActionMenuItem menuDialogs(&minfoDialogs, &menuRootList, INFO_LOCATION_PGM);
28+
RENDERING_CALLBACK_NAME_OVERRIDDEN(fnStatusInfoRtCall, infoRenderingRtCall, "Info", -1)
29+
TextMenuItem menuStatusInfo(fnStatusInfoRtCall, "", 19, 5, NULL);
30+
AnyMenuInfo minfoStatusRestart = { "Restart", 11, 0xffff, 0, onRestart };
31+
ActionMenuItem menuStatusRestart(&minfoStatusRestart, &menuStatusInfo, INFO_LOCATION_RAM);
3032
const FloatMenuInfo minfoStatusLineVoltage = { "Line Voltage", 10, 0xffff, 2, NO_CALLBACK };
31-
FloatMenuItem menuStatusLineVoltage(&minfoStatusLineVoltage, 235.0, &menuStatusRestart);
33+
FloatMenuItem menuStatusLineVoltage(&minfoStatusLineVoltage, 235.0, &menuStatusRestart, INFO_LOCATION_PGM);
3234
const BooleanMenuInfo minfoStatusAmpPower = { "Amp Power", 9, 0xffff, 1, NO_CALLBACK, NAMING_ON_OFF };
33-
BooleanMenuItem menuStatusAmpPower(&minfoStatusAmpPower, false, &menuStatusLineVoltage);
35+
BooleanMenuItem menuStatusAmpPower(&minfoStatusAmpPower, false, &menuStatusLineVoltage, INFO_LOCATION_PGM);
3436
const char enumStrStatusAmpStatus_0[] = "Standby";
3537
const char enumStrStatusAmpStatus_1[] = "Warm up";
3638
const char enumStrStatusAmpStatus_2[] = "DC protect";
3739
const char enumStrStatusAmpStatus_3[] = "Overload";
3840
const char enumStrStatusAmpStatus_4[] = "Overheat";
3941
const char* const enumStrStatusAmpStatus[] = { enumStrStatusAmpStatus_0, enumStrStatusAmpStatus_1, enumStrStatusAmpStatus_2, enumStrStatusAmpStatus_3, enumStrStatusAmpStatus_4 };
4042
const EnumMenuInfo minfoStatusAmpStatus = { "Amp Status", 8, 0xffff, 4, NO_CALLBACK, enumStrStatusAmpStatus };
41-
EnumMenuItem menuStatusAmpStatus(&minfoStatusAmpStatus, 0, &menuStatusAmpPower);
42-
RENDERING_CALLBACK_NAME_INVOKE(fnStatusRtCall, backSubItemRenderFn, "Status", -1, NO_CALLBACK)
43+
EnumMenuItem menuStatusAmpStatus(&minfoStatusAmpStatus, 0, &menuStatusAmpPower, INFO_LOCATION_PGM);
4344
const SubMenuInfo minfoStatus = { "Status", 7, 0xffff, 0, NO_CALLBACK };
44-
BackMenuItem menuBackStatus(fnStatusRtCall, &menuStatusAmpStatus);
45-
SubMenuItem menuStatus(&minfoStatus, &menuBackStatus, &menuDialogs);
45+
BackMenuItem menuBackStatus(&minfoStatus, &menuStatusAmpStatus, INFO_LOCATION_PGM);
46+
SubMenuItem menuStatus(&minfoStatus, &menuBackStatus, &menuDialogs, INFO_LOCATION_PGM);
4647
RENDERING_CALLBACK_NAME_INVOKE(fnSettingsNlgeRtCall, largeNumItemRenderFn, "NLge", -1, NO_CALLBACK)
4748
EditableLargeNumberMenuItem menuSettingsNlge(fnSettingsNlgeRtCall, LargeFixedNumber(8, 0, 0U, 0U, false), 18, true, NULL);
4849
RENDERING_CALLBACK_NAME_INVOKE(fnSettingsLargeNumRtCall, largeNumItemRenderFn, "LargeNum", -1, NO_CALLBACK)
@@ -54,28 +55,27 @@ IpAddressMenuItem menuSettingsIP(fnSettingsIPRtCall, IpAddressStorage(192, 168,
5455
RENDERING_CALLBACK_NAME_INVOKE(fnSettingsTextRtCall, textItemRenderFn, "Text", 9, NO_CALLBACK)
5556
TextMenuItem menuSettingsText(fnSettingsTextRtCall, "hello", 13, 10, &menuSettingsIP);
5657
const BooleanMenuInfo minfoSettingsProtection = { "Protection", 6, 0xffff, 1, NO_CALLBACK, NAMING_ON_OFF };
57-
BooleanMenuItem menuSettingsProtection(&minfoSettingsProtection, false, &menuSettingsText);
58+
BooleanMenuItem menuSettingsProtection(&minfoSettingsProtection, false, &menuSettingsText, INFO_LOCATION_PGM);
5859
const AnalogMenuInfo minfoSettingsMaxOnVolume = { "Max On Volume", 5, 7, 255, NO_CALLBACK, -180, 2, "dB" };
59-
AnalogMenuItem menuSettingsMaxOnVolume(&minfoSettingsMaxOnVolume, 144, &menuSettingsProtection);
60-
RENDERING_CALLBACK_NAME_INVOKE(fnSettingsRtCall, backSubItemRenderFn, "Settings", -1, NO_CALLBACK)
60+
AnalogMenuItem menuSettingsMaxOnVolume(&minfoSettingsMaxOnVolume, 144, &menuSettingsProtection, INFO_LOCATION_PGM);
6161
const SubMenuInfo minfoSettings = { "Settings", 4, 0xffff, 0, NO_CALLBACK };
62-
BackMenuItem menuBackSettings(fnSettingsRtCall, &menuSettingsMaxOnVolume);
63-
SubMenuItem menuSettings(&minfoSettings, &menuBackSettings, &menuStatus);
62+
BackMenuItem menuBackSettings(&minfoSettings, &menuSettingsMaxOnVolume, INFO_LOCATION_PGM);
63+
SubMenuItem menuSettings(&minfoSettings, &menuBackSettings, &menuStatus, INFO_LOCATION_PGM);
6464
const BooleanMenuInfo minfoMute = { "Mute", 3, 4, 1, NO_CALLBACK, NAMING_TRUE_FALSE };
65-
BooleanMenuItem menuMute(&minfoMute, false, &menuSettings);
65+
BooleanMenuItem menuMute(&minfoMute, false, &menuSettings, INFO_LOCATION_PGM);
6666
const char enumStrInput_0[] = "CD Player";
6767
const char enumStrInput_1[] = "Computer USB";
6868
const char enumStrInput_2[] = "Turntable";
6969
const char enumStrInput_3[] = "Line 1";
7070
const char* const enumStrInput[] = { enumStrInput_0, enumStrInput_1, enumStrInput_2, enumStrInput_3 };
7171
const EnumMenuInfo minfoInput = { "Input", 2, 5, 3, NO_CALLBACK, enumStrInput };
72-
EnumMenuItem menuInput(&minfoInput, 2, &menuMute);
72+
EnumMenuItem menuInput(&minfoInput, 2, &menuMute, INFO_LOCATION_PGM);
7373
const AnalogMenuInfo minfoVolume = { "Volume", 1, 2, 255, onVolumeChanged, -180, 2, "dB" };
74-
AnalogMenuItem menuVolume(&minfoVolume, 80, &menuInput);
74+
AnalogMenuItem menuVolume(&minfoVolume, 80, &menuInput, INFO_LOCATION_PGM);
7575

7676
void setupMenu() {
7777
// First we set up eeprom and authentication (if needed).
78-
78+
setSizeBasedEEPROMStorageEnabled(false);
7979
// Code generated by plugins.
8080
gfx.begin();
8181
gfx.setRotation(1);

examples/arduino32/piPicoTftEncoder/piPicoTftEncoder_menu.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <EditableLargeNumberMenuItem.h>
2121
#include <ScrollChoiceMenuItem.h>
2222
#include <IoAbstraction.h>
23+
#include <EepromItemStorage.h>
2324

2425
// variables we declare that you may need to access
2526
extern const PROGMEM ConnectorLocalInfo applicationInfo;
@@ -35,6 +36,8 @@ extern const GFXfont RobotoMedium24;
3536
// Global Menu Item exports
3637
extern ListRuntimeMenuItem menuRootList;
3738
extern ActionMenuItem menuDialogs;
39+
extern TextMenuItem menuStatusInfo;
40+
extern AnyMenuInfo minfoStatusRestart;
3841
extern ActionMenuItem menuStatusRestart;
3942
extern FloatMenuItem menuStatusLineVoltage;
4043
extern BooleanMenuItem menuStatusAmpPower;
@@ -62,6 +65,7 @@ void setupMenu();
6265
#define CALLBACK_FUNCTION
6366

6467
int fnRootListRtCall(RuntimeMenuItem* item, uint8_t row, RenderFnMode mode, char* buffer, int bufferSize);
68+
int infoRenderingRtCall(RuntimeMenuItem* item, uint8_t row, RenderFnMode mode, char* buffer, int bufferSize);
6569
void CALLBACK_FUNCTION onRestart(int id);
6670
void CALLBACK_FUNCTION onShowDialogs(int id);
6771
void CALLBACK_FUNCTION onVolumeChanged(int id);

0 commit comments

Comments
 (0)