Skip to content

Commit 87f92f5

Browse files
author
dave
committed
Update examples ready for TcMenu 1.7
1 parent 20f1fd3 commit 87f92f5

13 files changed

+299
-84
lines changed

examples/colorTftEthernet32/colorTftEthernet.emf

Lines changed: 85 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"lastEdited": {
3-
"seconds": 1602516900,
3+
"seconds": 1603533153,
44
"nanos": 0
55
},
66
"codeOptions": {
@@ -96,7 +96,7 @@
9696
},
9797
{
9898
"name": "DISPLAY_ROTATION",
99-
"latestValue": "0",
99+
"latestValue": "1",
100100
"subsystem": "DISPLAY"
101101
},
102102
{
@@ -257,58 +257,17 @@
257257
}
258258
},
259259
{
260-
"parentId": 4,
261-
"type": "",
262-
"item": null
263-
},
264-
{
265-
"parentId": 4,
266-
"type": "",
267-
"item": null
268-
},
269-
{
270-
"parentId": 4,
271-
"type": "subMenu",
272-
"item": {
273-
"name": "Rom Values",
274-
"eepromAddress": -1,
275-
"id": 20,
276-
"readOnly": false,
277-
"localOnly": false,
278-
"visible": true,
279-
"secured": false
280-
}
281-
},
282-
{
283-
"parentId": 20,
284-
"type": "",
285-
"item": null
286-
},
287-
{
288-
"parentId": 20,
289-
"type": "textItem",
290-
"item": {
291-
"name": "Item Text",
292-
"eepromAddress": -1,
293-
"id": 21,
294-
"readOnly": false,
295-
"localOnly": false,
296-
"visible": true,
297-
"itemType": "PLAIN_TEXT",
298-
"textLength": 10
299-
}
300-
},
301-
{
302-
"parentId": 20,
303-
"type": "actionMenu",
260+
"parentId": 11,
261+
"type": "rgbItem",
304262
"item": {
305-
"name": "Save item",
306-
"eepromAddress": -1,
307-
"id": 23,
263+
"name": "RGB",
264+
"eepromAddress": 16,
265+
"id": 26,
308266
"readOnly": false,
309267
"localOnly": false,
310268
"visible": true,
311-
"functionName": "onSaveItem"
269+
"functionName": "onRgbChanged",
270+
"includeAlphaChannel": false
312271
}
313272
},
314273
{
@@ -377,6 +336,82 @@
377336
"textLength": 20
378337
}
379338
},
339+
{
340+
"parentId": 0,
341+
"type": "subMenu",
342+
"item": {
343+
"name": "Rom Values",
344+
"eepromAddress": -1,
345+
"id": 20,
346+
"readOnly": false,
347+
"localOnly": false,
348+
"visible": true,
349+
"functionName": "",
350+
"secured": false
351+
}
352+
},
353+
{
354+
"parentId": 20,
355+
"type": "scrollItem",
356+
"item": {
357+
"name": "Rom Choice",
358+
"eepromAddress": 14,
359+
"id": 25,
360+
"readOnly": false,
361+
"localOnly": false,
362+
"visible": true,
363+
"itemWidth": 10,
364+
"numEntries": 10,
365+
"variable": null,
366+
"eepromOffset": 1024,
367+
"choiceMode": "ARRAY_IN_EEPROM"
368+
}
369+
},
370+
{
371+
"parentId": 20,
372+
"type": "scrollItem",
373+
"item": {
374+
"name": "Rom Location",
375+
"eepromAddress": -1,
376+
"id": 24,
377+
"readOnly": false,
378+
"localOnly": false,
379+
"visible": true,
380+
"functionName": "",
381+
"itemWidth": 10,
382+
"numEntries": 10,
383+
"variable": null,
384+
"eepromOffset": 0,
385+
"choiceMode": "CUSTOM_RENDERFN"
386+
}
387+
},
388+
{
389+
"parentId": 20,
390+
"type": "textItem",
391+
"item": {
392+
"name": "Rom Text",
393+
"eepromAddress": -1,
394+
"id": 21,
395+
"readOnly": false,
396+
"localOnly": false,
397+
"visible": true,
398+
"itemType": "PLAIN_TEXT",
399+
"textLength": 10
400+
}
401+
},
402+
{
403+
"parentId": 20,
404+
"type": "actionMenu",
405+
"item": {
406+
"name": "Save item",
407+
"eepromAddress": -1,
408+
"id": 23,
409+
"readOnly": false,
410+
"localOnly": false,
411+
"visible": true,
412+
"functionName": "onSaveItem"
413+
}
414+
},
380415
{
381416
"parentId": 0,
382417
"type": "actionMenu",

examples/colorTftEthernet32/colorTftEthernet32.ino

Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
#include <Fonts/FreeSans9pt7b.h>
88
#include <Ethernet.h>
99
#include <SPI.h>
10+
#include <IoLogging.h>
1011

1112
// contains the graphical widget title components.
1213
#include "stockIcons/wifiAndConnectionIcons16x12.h"
1314

1415
/*
15-
* Shows how to use adagraphics with a TFT panel and an ethernet module.
16+
* Shows how to use adafruit graphics with a TFT panel and an ethernet module.
1617
* This is a 32 bit example, which by default targets 32 bit devices.
1718
* Assumed board for this is a SAMD based MKR board.
1819
*
@@ -44,7 +45,7 @@ IoAbstractionRef io8574 = ioFrom8574(0x20, 0); // on addr 0x20 and interrupt pin
4445
ArduinoAnalogDevice analogDevice(12, 10);
4546

4647
// Here we create two additional menus, that will be added manually to handle the connectivity
47-
// status and authentication keys. In a future version these will be added to th desinger.
48+
// status and authentication keys. In a future version these will be added to th designer.
4849
RemoteMenuItem menuRemoteMonitor(1001, 2);
4950
EepromAuthenicationInfoMenuItem menuAuthKeyMgr(1002, &authManager, &menuRemoteMonitor);
5051

@@ -87,7 +88,7 @@ void prepareCustomConfiguration() {
8788
//colorConfig.editIcon = myEditIcon;
8889
//colorConfig.activeIcon = myActiveIcon;
8990
//colorConfig.editIconWidth = myEditWidth;
90-
//colorConfig.editIconHeight = myEditheight;
91+
//colorConfig.editIconHeight = myEditHeight;
9192
colorConfig.editIcon = NULL;
9293
colorConfig.activeIcon = NULL;
9394
}
@@ -105,6 +106,9 @@ void setup() {
105106
// we used an i2c device (io8574) so must initialise wire too
106107
Wire.begin();
107108

109+
// We should set the eeprom that menu manager will use as early as possible
110+
menuMgr.setEepromRef(&eeprom);
111+
108112
// now we enable authentication using EEPROM authentication. Where the EEPROM is
109113
// queried for authentication requests, and any additional pairs are stored there too.
110114
// first we initialise the authManager, then pass it to the class.
@@ -140,7 +144,7 @@ void setup() {
140144
setupMenu();
141145

142146
// and then load back the previous state
143-
menuMgr.load(eeprom);
147+
menuMgr.load();
144148

145149
// spin up the Ethernet library
146150
byte* rawIp = menuIpAddress.getIpAddress();
@@ -152,7 +156,6 @@ void setup() {
152156
Serial.print("Ethernet available on ");Serial.println(sz);
153157

154158
taskManager.scheduleFixedRate(2250, [] {
155-
Serial.print(".");
156159
float a1Value = analogDevice.getCurrentFloat(A1);
157160
menuVoltA1.setFloatValue(a1Value * 3.3);
158161
});
@@ -185,11 +188,13 @@ void CALLBACK_FUNCTION onLimitMode(int /*id*/) {
185188

186189
void CALLBACK_FUNCTION onSaveRom(int /*id*/) {
187190
// save out the state, in a real system we could detect power down for this.
188-
menuMgr.save(eeprom);
191+
menuMgr.save();
189192
}
190193

191194
bool starting = true;
192195

196+
const char pgmHeaderSavedItem[] PROGMEM = "Rom Item Saved";
197+
193198
void myRenderCallback(unsigned int encoderVal, RenderPressMode pressType) {
194199
if(pressType == RPRESS_HELD)
195200
{
@@ -219,15 +224,57 @@ void myRenderCallback(unsigned int encoderVal, RenderPressMode pressType) {
219224
}
220225
}
221226

222-
void CALLBACK_FUNCTION onTakeDisplay(int id) {
227+
void CALLBACK_FUNCTION onTakeDisplay(int /*id*/) {
223228
starting = true;
224229
renderer.takeOverDisplay(myRenderCallback);
225230
}
226231

227-
void CALLBACK_FUNCTION onRgbChanged(int id) {
228-
// TODO - your menu change code
232+
void CALLBACK_FUNCTION onRgbChanged(int /*id*/) {
233+
auto colorData = menuRGB.getColorData();
234+
serdebugF4("RGB changed: ", colorData.red, colorData.green, colorData.blue);
229235
}
230236

231-
void CALLBACK_FUNCTION onSaveItem(int id) {
232-
// TODO - your menu change code
237+
void CALLBACK_FUNCTION onSaveItem(int /*id*/) {
238+
auto itemNo = menuRomLocation.getCurrentValue();
239+
auto itemSize = menuRomChoice.getItemWidth();
240+
auto position = menuRomChoice.getEepromStart() + (itemNo * itemSize);
241+
eeprom.writeArrayToRom(position, (const uint8_t*)menuRomText.getTextValue(), 10);
242+
243+
if(renderer.getDialog()->isInUse()) return;
244+
renderer.getDialog()->setButtons(BTNTYPE_NONE, BTNTYPE_OK);
245+
renderer.getDialog()->show(pgmHeaderSavedItem, true);
246+
renderer.getDialog()->copyIntoBuffer(menuRomText.getTextValue());
247+
}
248+
249+
void CALLBACK_FUNCTION onRomLocationChange(int /*id*/) {
250+
auto itemNo = menuRomLocation.getCurrentValue();
251+
char sz[12];
252+
auto itemSize = menuRomChoice.getItemWidth();
253+
eeprom.readIntoMemArray((uint8_t*)sz, menuRomChoice.getEepromStart() + (itemNo * itemSize), 10);
254+
menuRomText.setTextValue(sz);
255+
serdebugF2("Rom data was ", sz)
256+
}
257+
258+
//
259+
// Here we handle the custom rendering for the runtime list menu item that just counts. We basically get called back
260+
// every time it needs more data. For example when the name is required, when any index value is required or when
261+
// it will be saved to EEPROM or invoked.
262+
//
263+
int CALLBACK_FUNCTION fnRomLocationRtCall(RuntimeMenuItem * item, uint8_t row, RenderFnMode mode, char * buffer, int bufferSize) {
264+
switch(mode) {
265+
case RENDERFN_INVOKE:
266+
onRomLocationChange(item->getId());
267+
return true;
268+
case RENDERFN_NAME:
269+
// TODO - each row has it's own name - 0xff is the parent item
270+
strncpy(buffer, "Rom Location", bufferSize);
271+
return true;
272+
case RENDERFN_VALUE:
273+
// TODO - each row can has its own value - 0xff is the parent item
274+
strncpy(buffer, "Item ", bufferSize);
275+
fastltoa(buffer, row, 3, NOT_PADDED, bufferSize);
276+
return true;
277+
case RENDERFN_EEPROM_POS: return 0xFFFF; // lists are generally not saved to EEPROM
278+
default: return false;
279+
}
233280
}

examples/colorTftEthernet32/colorTftEthernet32.ino.backup

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,19 @@ void CALLBACK_FUNCTION onTakeDisplay(int id) {
223223
starting = true;
224224
renderer.takeOverDisplay(myRenderCallback);
225225
}
226+
227+
void CALLBACK_FUNCTION onRgbChanged(int id) {
228+
// TODO - your menu change code
229+
}
230+
231+
void CALLBACK_FUNCTION onRomValuesSubOpen(int id) {
232+
// TODO - your menu change code
233+
}
234+
235+
void CALLBACK_FUNCTION onSaveItem(int id) {
236+
// TODO - your menu change code
237+
}
238+
239+
void CALLBACK_FUNCTION onRomLocationChange(int id) {
240+
}
241+

examples/colorTftEthernet32/colorTftEthernet32_menu.cpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,23 @@ EthernetServer server(3333);
2323

2424
const AnyMenuInfo minfoTakeDisplay = { "Take display", 17, 0xFFFF, 0, onTakeDisplay };
2525
ActionMenuItem menuTakeDisplay(&minfoTakeDisplay, NULL);
26+
const AnyMenuInfo minfoSaveItem = { "Save item", 23, 0xFFFF, 0, onSaveItem };
27+
ActionMenuItem menuSaveItem(&minfoSaveItem, NULL);
28+
RENDERING_CALLBACK_NAME_INVOKE(fnRomTextRtCall, textItemRenderFn, "Rom Text", -1, NO_CALLBACK)
29+
TextMenuItem menuRomText(fnRomTextRtCall, 21, 10, &menuSaveItem);
30+
ScrollChoiceMenuItem menuRomLocation(24, fnRomLocationRtCall, 0, 10, &menuRomText);
31+
RENDERING_CALLBACK_NAME_INVOKE(fnRomChoiceRtCall, enumItemRenderFn, "Rom Choice", 14, NO_CALLBACK)
32+
ScrollChoiceMenuItem menuRomChoice(25, fnRomChoiceRtCall, 0, 1024, 10, 10, &menuRomLocation);
33+
const SubMenuInfo minfoRomValues = { "Rom Values", 20, 0xFFFF, 0, NO_CALLBACK };
34+
RENDERING_CALLBACK_NAME_INVOKE(fnRomValuesRtCall, backSubItemRenderFn, "Rom Values", -1, NO_CALLBACK)
35+
BackMenuItem menuBackRomValues(fnRomValuesRtCall, &menuRomChoice);
36+
SubMenuItem menuRomValues(&minfoRomValues, &menuBackRomValues, &menuTakeDisplay);
2637
RENDERING_CALLBACK_NAME_INVOKE(fnIpAddressRtCall, ipAddressRenderFn, "Ip Address", 10, NO_CALLBACK)
2738
IpAddressMenuItem menuIpAddress(fnIpAddressRtCall, 15, NULL);
2839
const SubMenuInfo minfoConnectivity = { "Connectivity", 14, 0xFFFF, 0, NO_CALLBACK };
2940
RENDERING_CALLBACK_NAME_INVOKE(fnConnectivityRtCall, backSubItemRenderFn, "Connectivity", -1, NO_CALLBACK)
3041
BackMenuItem menuBackConnectivity(fnConnectivityRtCall, &menuIpAddress);
31-
SubMenuItem menuConnectivity(&minfoConnectivity, &menuBackConnectivity, &menuTakeDisplay);
42+
SubMenuItem menuConnectivity(&minfoConnectivity, &menuBackConnectivity, &menuRomValues);
3243
const FloatMenuInfo minfoVoltA1 = { "Volt A1", 9, 0xFFFF, 2, NO_CALLBACK };
3344
FloatMenuItem menuVoltA1(&minfoVoltA1, NULL);
3445
const FloatMenuInfo minfoVoltA0 = { "Volt A0", 8, 0xFFFF, 2, NO_CALLBACK };
@@ -37,24 +48,18 @@ const SubMenuInfo minfoStatus = { "Status", 7, 0xFFFF, 0, NO_CALLBACK };
3748
RENDERING_CALLBACK_NAME_INVOKE(fnStatusRtCall, backSubItemRenderFn, "Status", -1, NO_CALLBACK)
3849
BackMenuItem menuBackStatus(fnStatusRtCall, &menuVoltA0);
3950
SubMenuItem menuStatus(&minfoStatus, &menuBackStatus, &menuConnectivity);
40-
const AnyMenuInfo minfoSaveItem = { "Save item", 23, 0xFFFF, 0, onSaveItem };
41-
ActionMenuItem menuSaveItem(&minfoSaveItem, NULL);
42-
RENDERING_CALLBACK_NAME_INVOKE(fnItemTextRtCall, textItemRenderFn, "Item Text", -1, NO_CALLBACK)
43-
TextMenuItem menuItemText(fnItemTextRtCall, 21, 10, &menuSaveItem);
44-
const SubMenuInfo minfoRomValues = { "Rom Values", 20, 0xFFFF, 0, NO_CALLBACK };
45-
RENDERING_CALLBACK_NAME_INVOKE(fnRomValuesRtCall, backSubItemRenderFn, "Rom Values", -1, NO_CALLBACK)
46-
BackMenuItem menuBackRomValues(fnRomValuesRtCall, &menuItemNo);
47-
SubMenuItem menuRomValues(&minfoRomValues, &menuBackRomValues, NULL);
51+
RENDERING_CALLBACK_NAME_INVOKE(fnRGBRtCall, rgbAlphaItemRenderFn, "RGB", 16, onRgbChanged)
52+
Rgb32MenuItem menuRGB(26, fnRGBRtCall, false,NULL);
4853
const BooleanMenuInfo minfoTempCheck = { "Temp Check", 13, 9, 1, NO_CALLBACK, NAMING_ON_OFF };
49-
BooleanMenuItem menuTempCheck(&minfoTempCheck, false, NULL);
54+
BooleanMenuItem menuTempCheck(&minfoTempCheck, false, &menuRGB);
5055
const AnyMenuInfo minfoHiddenItem = { "Hidden item", 16, 0xFFFF, 0, NO_CALLBACK };
5156
ActionMenuItem menuHiddenItem(&minfoHiddenItem, &menuTempCheck);
5257
const BooleanMenuInfo minfoSCircuitProtect = { "S-Circuit Protect", 12, 8, 1, NO_CALLBACK, NAMING_ON_OFF };
5358
BooleanMenuItem menuSCircuitProtect(&minfoSCircuitProtect, false, &menuHiddenItem);
5459
const SubMenuInfo minfoAdvanced = { "Advanced", 11, 0xFFFF, 0, NO_CALLBACK };
5560
RENDERING_CALLBACK_NAME_INVOKE(fnAdvancedRtCall, backSubItemRenderFn, "Advanced", -1, NO_CALLBACK)
5661
BackMenuItem menuBackAdvanced(fnAdvancedRtCall, &menuSCircuitProtect);
57-
SubMenuItem menuAdvanced(&minfoAdvanced, &menuBackAdvanced, &menuRGB);
62+
SubMenuItem menuAdvanced(&minfoAdvanced, &menuBackAdvanced, NULL);
5863
const AnyMenuInfo minfoSaveAll = { "Save all", 10, 0xFFFF, 0, onSaveRom };
5964
ActionMenuItem menuSaveAll(&minfoSaveAll, &menuAdvanced);
6065
const BooleanMenuInfo minfoPwrDelay = { "Pwr Delay", 5, 0xFFFF, 1, NO_CALLBACK, NAMING_YES_NO };
@@ -80,7 +85,7 @@ void setupMenu() {
8085

8186

8287
gfx.initR(INITR_BLACKTAB);
83-
gfx.setRotation(0);
88+
gfx.setRotation(1);
8489
renderer.setGraphicsDevice(&gfx, &colorConfig);
8590
switches.initialise(io8574, true);
8691
menuMgr.initForEncoder(&renderer, &menuVoltage, 7, 6, 5);

0 commit comments

Comments
 (0)