Skip to content

Commit b557047

Browse files
committed
examples rebuilt on latest code
1 parent b62583e commit b557047

20 files changed

+1014
-167
lines changed

examples/analogDfRobot/analogDfRobot.emf

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"lastEdited": {
3-
"seconds": 1599491778,
3+
"seconds": 1603018679,
44
"nanos": 0
55
},
66
"codeOptions": {
@@ -12,6 +12,7 @@
1212
"embeddedPlatform": "ARDUINO_UNO",
1313
"namingRecursive": false,
1414
"saveToSrc": false,
15+
"useCppMain": false,
1516
"lastProperties": []
1617
},
1718
"projectName": "Uses the DF Robot shield for both input and display",
@@ -104,6 +105,23 @@
104105
"textLength": 6
105106
}
106107
},
108+
{
109+
"parentId": 0,
110+
"type": "scrollItem",
111+
"item": {
112+
"name": "Choose Item",
113+
"eepromAddress": 18,
114+
"id": 8,
115+
"readOnly": false,
116+
"localOnly": false,
117+
"visible": true,
118+
"itemWidth": 10,
119+
"numEntries": 20,
120+
"variable": null,
121+
"eepromOffset": 0,
122+
"choiceMode": "CUSTOM_RENDERFN"
123+
}
124+
},
107125
{
108126
"parentId": 0,
109127
"type": "analogItem",

examples/analogDfRobot/analogDfRobot.ino

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,25 @@ void CALLBACK_FUNCTION onLed2(int id) {
4343
// Called whenever you change the LED2 menu item..
4444
}
4545

46+
47+
// When dealing with custom rendering, either using lists or custom choices, we have to do everything from scratch. We need
48+
// to handle the EEPROM storage location, the item name, the value etc.
49+
// see tcMenu list documentation on thecoderscorner.com
50+
int CALLBACK_FUNCTION fnChooseItemRtCall(RuntimeMenuItem * item, uint8_t row, RenderFnMode mode, char * buffer, int bufferSize) {
51+
switch(mode) {
52+
case RENDERFN_INVOKE:
53+
// we don't want to do anything on a selection, ignore it.
54+
return true;
55+
case RENDERFN_NAME:
56+
// here we return the name for the scroll item
57+
strcpy(buffer, "Choose");
58+
return true;
59+
case RENDERFN_VALUE:
60+
// here we define the text value for each possible setting, we just set it to V followed by the row
61+
buffer[0] = 'V'; buffer[1]=0;
62+
fastltoa(buffer, row, 3, NOT_PADDED, bufferSize);
63+
return true;
64+
case RENDERFN_EEPROM_POS: return 18; // Choices are saved to rom, we copy the value from the designer.
65+
default: return false;
66+
}
67+
}

examples/analogDfRobot/analogDfRobot_menu.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ LiquidCrystalRenderer renderer(lcd, 16, 2);
2222

2323
const AnalogMenuInfo PROGMEM minfoCommits = { "Commits", 7, 0xFFFF, 65000, NO_CALLBACK, 0, 0, "" };
2424
AnalogMenuItem menuCommits(&minfoCommits, 0, NULL);
25+
ScrollChoiceMenuItem menuChooseItem(8, fnChooseItemRtCall, 0, 20, &menuCommits);
2526
RENDERING_CALLBACK_NAME_INVOKE(fnTextRtCall, textItemRenderFn, "Text", 4, NO_CALLBACK)
26-
TextMenuItem menuText(fnTextRtCall, 6, 6, &menuCommits);
27+
TextMenuItem menuText(fnTextRtCall, 6, 6, &menuChooseItem);
2728
RENDERING_CALLBACK_NAME_INVOKE(fnLgeNumRtCall, largeNumItemRenderFn, "LgeNum", 10, NO_CALLBACK)
2829
EditableLargeNumberMenuItem menuLgeNum(fnLgeNumRtCall, 5, 8, 4, &menuText);
2930
const BooleanMenuInfo PROGMEM minfoLED2 = { "LED 2", 4, 3, 1, onLed2, NAMING_ON_OFF };

examples/analogDfRobot/analogDfRobot_menu.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <LiquidCrystalIO.h>
1818
#include "tcMenuLiquidCrystal.h"
1919
#include <DfRobotInputAbstraction.h>
20+
#include <ScrollChoiceMenuItem.h>
2021
#include <EditableLargeNumberMenuItem.h>
2122

2223
void setupMenu(); // forward reference of the menu setup function.
@@ -33,6 +34,8 @@ extern LiquidCrystalRenderer renderer;
3334
// Global Menu Item exports
3435

3536
extern AnalogMenuItem menuCommits;
37+
int fnChooseItemRtCall(RuntimeMenuItem * item, uint8_t row, RenderFnMode mode, char * buffer, int bufferSize);
38+
extern ScrollChoiceMenuItem menuChooseItem;
3639
extern TextMenuItem menuText;
3740
extern EditableLargeNumberMenuItem menuLgeNum;
3841
void CALLBACK_FUNCTION onLed2(int id);

examples/analogDfRobot/tcMenuLiquidCrystal.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*/
1414

1515
#include "tcMenuLiquidCrystal.h"
16+
#include "tcUtil.h"
1617

1718
extern const ConnectorLocalInfo applicationInfo;
1819

@@ -35,7 +36,7 @@ void LiquidCrystalRenderer::initialise() {
3536
serdebugF2("Title widget present max=", wid->getMaxValue());
3637
for(int i = 0; i < wid->getMaxValue(); i++) {
3738
serdebugF2("Creating char ", charNo);
38-
lcd->createCharPgm((byte)charNo, wid->getIcon(i));
39+
lcd->createCharPgm((uint8_t)charNo, wid->getIcon(i));
3940
charNo++;
4041
}
4142
wid = wid->getNext();
@@ -81,7 +82,7 @@ void LiquidCrystalRenderer::renderTitle(bool forceDraw) {
8182
strcpy_P(buffer, applicationInfo.name);
8283
serdebugF2("print app name", buffer);
8384
uint8_t bufSz = bufferSize;
84-
uint8_t last = min(bufSz, strlen(buffer));
85+
uint8_t last = min(bufSz, (uint8_t)strlen(buffer));
8586
for(uint8_t i = last; i < bufSz; i++) {
8687
buffer[i] = ' ';
8788
}

examples/esp8266WifiOled/Greenhouse.emf

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"lastEdited": {
3-
"seconds": 1601464775,
3+
"seconds": 1603022031,
44
"nanos": 0
55
},
66
"codeOptions": {
@@ -229,6 +229,37 @@
229229
"naming": "TRUE_FALSE"
230230
}
231231
},
232+
{
233+
"parentId": 5,
234+
"type": "scrollItem",
235+
"item": {
236+
"name": "File",
237+
"eepromAddress": -1,
238+
"id": 14,
239+
"readOnly": false,
240+
"localOnly": false,
241+
"visible": true,
242+
"functionName": "onFileChoice",
243+
"itemWidth": 10,
244+
"numEntries": 1,
245+
"variable": "fileChoicesArray",
246+
"eepromOffset": 200,
247+
"choiceMode": "ARRAY_IN_RAM"
248+
}
249+
},
250+
{
251+
"parentId": 5,
252+
"type": "actionMenu",
253+
"item": {
254+
"name": "Load Files",
255+
"eepromAddress": -1,
256+
"id": 15,
257+
"readOnly": false,
258+
"localOnly": false,
259+
"visible": true,
260+
"functionName": "onLoadFiles"
261+
}
262+
},
232263
{
233264
"parentId": 0,
234265
"type": "subMenu",

examples/esp8266WifiOled/esp8266WifiOled.ino

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
// contains the graphical widget title components.
2525
#include "stockIcons/wifiAndConnectionIcons16x12.h"
2626

27+
char fileChoicesArray[255]{};
2728

2829
// here we define the heater and window pins on the PCF8574
2930
// 0, 1 are A and B from encoder, 2 is OK button.
@@ -286,22 +287,19 @@ void CALLBACK_FUNCTION onSaveAll(int id) {
286287

287288
}
288289

290+
void CALLBACK_FUNCTION onFileChoice(int id) {
291+
Serial.print("file chosen: ");
292+
auto entryNum = menuFile.getCurrentValue();
293+
char sz[12];
294+
menuFile.valueAtPosition(sz, sizeof(sz), entryNum);
295+
Serial.println(sz);
296+
}
289297

290-
291-
292-
293-
294-
295-
296-
297-
298-
299-
300-
301-
302-
303-
304-
305-
306-
307-
298+
void CALLBACK_FUNCTION onLoadFiles(int id) {
299+
strcpy(fileChoicesArray, "MyDocument");
300+
strcpy(&fileChoicesArray[10], "SecretFile");
301+
strcpy(&fileChoicesArray[20], "AnotherFle");
302+
strcpy(&fileChoicesArray[30], "MenuItem");
303+
strcpy(&fileChoicesArray[40], "MyDocument");
304+
menuFile.setNumberOfRows(5);
305+
}

examples/esp8266WifiOled/esp8266WifiOled_menu.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,13 @@ const SubMenuInfo PROGMEM minfoConnectivity = { "Connectivity", 9, 0xFFFF, 0, NO
3232
RENDERING_CALLBACK_NAME_INVOKE(fnConnectivityRtCall, backSubItemRenderFn, "Connectivity", -1, NO_CALLBACK)
3333
BackMenuItem menuBackConnectivity(fnConnectivityRtCall, &menuSSID);
3434
SubMenuItem menuConnectivity(&minfoConnectivity, &menuBackConnectivity, NULL);
35+
const AnyMenuInfo PROGMEM minfoLoadFiles = { "Load Files", 15, 0xFFFF, 0, onLoadFiles };
36+
ActionMenuItem menuLoadFiles(&minfoLoadFiles, NULL);
37+
extern const char* fileChoicesArray;
38+
RENDERING_CALLBACK_NAME_INVOKE(fnFileRtCall, enumItemRenderFn, "File", -1, onFileChoice)
39+
ScrollChoiceMenuItem menuFile(14, fnFileRtCall, 0, fileChoicesArray, 10, 1, &menuLoadFiles);
3540
const BooleanMenuInfo PROGMEM minfoSecretEntry = { "Secret Entry", 13, 0xFFFF, 1, NO_CALLBACK, NAMING_TRUE_FALSE };
36-
BooleanMenuItem menuSecretEntry(&minfoSecretEntry, false, NULL);
41+
BooleanMenuItem menuSecretEntry(&minfoSecretEntry, false, &menuFile);
3742
const AnyMenuInfo PROGMEM minfoSaveAll = { "Save All", 8, 0xFFFF, 0, onSaveAll };
3843
ActionMenuItem menuSaveAll(&minfoSaveAll, &menuSecretEntry);
3944
const char enumStrWinOpening_0[] PROGMEM = "NARROW";

examples/esp8266WifiOled/esp8266WifiOled_menu.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "tcMenuU8g2.h"
1818
#include "EthernetTransport.h"
1919
#include <RemoteConnector.h>
20+
#include <ScrollChoiceMenuItem.h>
2021

2122
void setupMenu(); // forward reference of the menu setup function.
2223
extern const PROGMEM ConnectorLocalInfo applicationInfo; // defines the app info to the linker.
@@ -37,6 +38,10 @@ extern IpAddressMenuItem menuIpAddress;
3738
extern TextMenuItem menuPwd;
3839
extern TextMenuItem menuSSID;
3940
extern SubMenuItem menuConnectivity;
41+
void CALLBACK_FUNCTION onLoadFiles(int id);
42+
extern ActionMenuItem menuLoadFiles;
43+
void CALLBACK_FUNCTION onFileChoice(int id);
44+
extern ScrollChoiceMenuItem menuFile;
4045
extern BooleanMenuItem menuSecretEntry;
4146
void CALLBACK_FUNCTION onSaveAll(int id);
4247
extern ActionMenuItem menuSaveAll;

0 commit comments

Comments
 (0)