Skip to content

Commit b34c419

Browse files
committed
Example moved to turbo
1 parent 1c4b23a commit b34c419

12 files changed

Lines changed: 538 additions & 483 deletions

examples/arduino32/r4UnoButtonsTft/DiscoTime.cpp renamed to examples/arduino32/UnoR4Disco/DiscoTime.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
* schedule very frequently and use an AdaFruit_GFX GFXCanvas1 to represent the 12x8 display, and with that you can
44
* draw anything onto it that is possible with Adafruit_GFX. Feel free to make it better!
55
*
6-
* This also shows how to create custom messages, we have two custom "disco messages" that the Java API can receive and
7-
* you can easily create additional protocol handlers to process them.
6+
* This also shows how to create custom messages, we have two custom "disco messages" that the Java API can receive, and
7+
* you can create additional protocol handlers to process them.
88
*/
99

1010
#include "DiscoTime.h"

examples/arduino32/r4UnoButtonsTft/DiscoTime.h renamed to examples/arduino32/UnoR4Disco/DiscoTime.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#ifndef TCLIBRARYDEV_DISCOTIME_H
33
#define TCLIBRARYDEV_DISCOTIME_H
44

5-
#include "r4UnoButtonsTft_menu.h"
5+
#include "../r4UnoButtonsTft/r4UnoButtonsTft_menu.h"
66
#include <Adafruit_GFX.h>
77
#include <tcUnicodeAdaGFX.h>
88

examples/arduino32/r4UnoButtonsTft/ThemeCoolBlueTraditionalBuilder.h renamed to examples/arduino32/UnoR4Disco/ThemeCoolBlueTraditionalBuilder.h

File renamed without changes.

examples/arduino32/r4UnoButtonsTft/r4UnoButtonsTft.emf renamed to examples/arduino32/UnoR4Disco/UnoR4Disco.emf

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"version": "1.00",
3-
"projectName": "Project description",
4-
"author": "dave",
3+
"projectName": "Uno R4 disco project that has buttons and TFT",
4+
"author": "root",
55
"items": [
66
{
77
"parentId": 0,
@@ -12,6 +12,7 @@
1212
"variableName": "Disco",
1313
"id": 1,
1414
"eepromAddress": -1,
15+
"functionName": "",
1516
"readOnly": false,
1617
"localOnly": false,
1718
"visible": true,
@@ -32,6 +33,7 @@
3233
"variableName": "DiscoSpeed",
3334
"id": 2,
3435
"eepromAddress": -1,
36+
"functionName": "",
3537
"readOnly": false,
3638
"localOnly": false,
3739
"visible": true,
@@ -62,6 +64,7 @@
6264
"variableName": "ScrollText",
6365
"id": 4,
6466
"eepromAddress": -1,
67+
"functionName": "",
6568
"readOnly": false,
6669
"localOnly": false,
6770
"visible": true,
@@ -79,6 +82,7 @@
7982
"variableName": "ScrollTextText",
8083
"id": 6,
8184
"eepromAddress": -1,
85+
"functionName": "",
8286
"readOnly": false,
8387
"localOnly": false,
8488
"visible": true,
@@ -109,6 +113,7 @@
109113
"variableName": "ShowXbmp",
110114
"id": 7,
111115
"eepromAddress": -1,
116+
"functionName": "",
112117
"readOnly": false,
113118
"localOnly": false,
114119
"visible": true,
@@ -128,6 +133,7 @@
128133
"variableName": "ShowXbmpXbmp",
129134
"id": 8,
130135
"eepromAddress": -1,
136+
"functionName": "",
131137
"readOnly": false,
132138
"localOnly": false,
133139
"visible": true,
@@ -158,6 +164,7 @@
158164
"variableName": "Analog",
159165
"id": 12,
160166
"eepromAddress": -1,
167+
"functionName": "",
161168
"readOnly": false,
162169
"localOnly": false,
163170
"visible": true,
@@ -190,11 +197,12 @@
190197
"type": "floatItem",
191198
"defaultValue": "0.0",
192199
"item": {
193-
"numDecimalPlaces": 3,
200+
"numDecimalPlaces": 1,
194201
"name": "A1 Value",
195202
"variableName": "AnalogA1Value",
196203
"id": 14,
197204
"eepromAddress": -1,
205+
"functionName": "",
198206
"readOnly": false,
199207
"localOnly": false,
200208
"visible": true,
@@ -210,6 +218,7 @@
210218
"variableName": "WiFi",
211219
"id": 15,
212220
"eepromAddress": -1,
221+
"functionName": "",
213222
"readOnly": false,
214223
"localOnly": false,
215224
"visible": true,
@@ -227,6 +236,7 @@
227236
"variableName": "WiFiIPAddress",
228237
"id": 16,
229238
"eepromAddress": -1,
239+
"functionName": "",
230240
"readOnly": false,
231241
"localOnly": false,
232242
"visible": true,
@@ -243,6 +253,7 @@
243253
"variableName": "WiFiConnected",
244254
"id": 17,
245255
"eepromAddress": -1,
256+
"functionName": "",
246257
"readOnly": false,
247258
"localOnly": false,
248259
"visible": true,
@@ -259,7 +270,7 @@
259270
],
260271
"lastThemeUuid": "57945787-0A04-447B-BBA2-6461FC505397",
261272
"applicationUUID": "4f60a98f-ca51-4c80-acbd-78bfd1e90c8d",
262-
"applicationName": "R4 Disco",
273+
"applicationName": "Uno R4 Disco",
263274
"lastProperties": [
264275
{
265276
"name": "DISPLAY_VARIABLE",
@@ -420,22 +431,42 @@
420431
"name": "NEED_EDITING_ICONS",
421432
"latestValue": "true",
422433
"subsystem": "THEME"
434+
},
435+
{
436+
"name": "DISPLAY_SEPARATOR_DISP",
437+
"latestValue": "",
438+
"subsystem": "DISPLAY"
439+
},
440+
{
441+
"name": "PINS_SEPARATOR_DISP",
442+
"latestValue": "",
443+
"subsystem": "DISPLAY"
444+
},
445+
{
446+
"name": "OTHER_SEPARATOR_DISP",
447+
"latestValue": "",
448+
"subsystem": "DISPLAY"
449+
},
450+
{
451+
"name": "DISPLAY_CUSTOM_SPI_NAME",
452+
"latestValue": "SPI",
453+
"subsystem": "DISPLAY"
423454
}
424455
],
425456
"namingRecursive": true,
426457
"useCppMain": false,
427-
"saveLocation": "ALL_TO_CURRENT",
458+
"saveLocation": "ONE_SINGLE_FILE_MENU_MAIN",
459+
"useDynamicMenus": true,
428460
"usingSizedEEPROMStorage": true,
461+
"eepromSaveMode": "WRITE_BY_POSITION_WITH_SIZE",
429462
"eepromDefinition": "",
430463
"authenticatorDefinition": "",
431464
"projectIoExpanders": [
432465
"deviceIO:"
433466
],
434467
"menuInMenuCollection": {
435468
"menuDefinitions": []
436-
},
437-
"packageNamespace": "",
438-
"appIsModular": false
469+
}
439470
},
440471
"stringLists": []
441472
}

examples/arduino32/r4UnoButtonsTft/r4UnoButtonsTft.ino renamed to examples/arduino32/UnoR4Disco/UnoR4Disco.ino

Lines changed: 60 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* An example sketch for the Arduino Uno R4 Wifi board that includes support for a TFT screen and keypad input. It
2+
* An example sketch for the Arduino Uno R4 Wifi board that includes support for a TFT screen and keypad input. It
33
* also has remote connectivity in the form of the inbuilt Wi-Fi module. The sketch controls the LED Matrix on the R4
44
* WiFi version somewhat akin to a disco.
55
*
@@ -10,12 +10,12 @@
1010
* and for the keypad
1111
* UP - 5, DOWN - 4, LEFT - 6, RIGHT - 7
1212
*/
13-
#include "r4UnoButtonsTft_menu.h"
13+
14+
#include "UnoR4Disco_menu.h"
1415
#include "xbmpImages.h"
1516
#include "IoAbstraction.h"
1617
#include <graphics/TcThemeBuilder.h>
1718
#include <stockIcons/wifiAndConnectionIcons16x12.h>
18-
#include <tcMenuVersion.h>
1919
#include <WiFi.h>
2020
#include "DiscoTime.h"
2121

@@ -26,7 +26,7 @@ TitleWidget connectedWidget(iconsConnection, 2, 16, 12);
2626

2727
DiscoTime discoTime;
2828

29-
// At the moment the Wi-Fi on this board has an issue with TagVal.
29+
// At the moment the Wi-Fi on this board has a latency issue with non-blocking IO.
3030
// We do not recommend using the Wi-Fi yet.
3131
#define R4_START_WIFI false
3232

@@ -46,36 +46,63 @@ void tryAndStartWifi() {
4646
#endif
4747
}
4848

49+
50+
void buildMenu(TcMenuBuilder& builder) {
51+
builder .subMenu(MENU_DISCO_ID, "Disco", NoMenuFlags, nullptr)
52+
.analogBuilder(MENU_DISCO_SPEED_ID, "Speed", DONT_SAVE, NoMenuFlags, 2, nullptr)
53+
.offset(0).divisor(1).step(1).maxValue(10).unit("").endItem()
54+
.actionItem(MENU_ZOOM_TEXT_START_ZOOM_ID, "Start Disco", NoMenuFlags, onStartDisco)
55+
.endSub()
56+
.subMenu(MENU_SCROLL_TEXT_ID, "Scroll Text", NoMenuFlags, nullptr)
57+
.textItem(MENU_SCROLL_TEXT_TEXT_ID, "Text", DONT_SAVE, 16, NoMenuFlags, "TcMenu", nullptr)
58+
.actionItem(MENU_SCROLL_TEXT_START_SCROLL_ID, "Start Scroll", NoMenuFlags, onStartScroll)
59+
.endSub()
60+
.subMenu(MENU_SHOW_XBMP_ID, "Show Xbmp", NoMenuFlags, nullptr)
61+
.scrollChoiceBuilder(MENU_SHOW_XBMP_XBMP_ID, "Xbmp", DONT_SAVE, NoMenuFlags, 0, nullptr).ofCustomRtFunction(fnShowXbmpXbmpRtCall, 0).endItem()
62+
.actionItem(MENU_SHOW_XBMP_SHOW_IMAGE_ID, "Show Image", NoMenuFlags, onShowXbmp)
63+
.endSub()
64+
.subMenu(MENU_ANALOG_ID, "Analog", NoMenuFlags, nullptr)
65+
.analogBuilder(MENU_ANALOG_A0_D_A_C_ID, "A0 DAC", DONT_SAVE, NoMenuFlags, 0, onAnalogDacChange)
66+
.offset(0).divisor(1).step(1).maxValue(100).unit("%").endItem()
67+
.floatItem(MENU_ANALOG_A1_VALUE_ID, "A1 Value", DONT_SAVE, 1, NoMenuFlags, 0.0, nullptr)
68+
.endSub()
69+
.subMenu(MENU_WI_FI_ID, "WiFi", NoMenuFlags, nullptr)
70+
.ipAddressItem(MENU_WI_FI_I_P_ADDRESS_ID, "IP Address", DONT_SAVE, NoMenuFlags, IpAddressStorage(127, 0, 0, 1), nullptr)
71+
.boolItem(MENU_WI_FI_CONNECTED_ID, "Connected", DONT_SAVE, NAMING_YES_NO, NoMenuFlags, false, nullptr)
72+
.endSub();
73+
}
74+
75+
76+
4977
void setup() {
78+
// start the serial port so that we can log
5079
Serial.begin(115200);
5180

81+
// set up the DAC and analog input.
5282
internalAnalogDevice().initPin(DAC, DIR_OUT);
5383
internalAnalogDevice().initPin(A1, DIR_IN);
5484
internalAnalogDevice().setCurrentValue(DAC, 0);
5585

5686
setupMenu();
5787

58-
menuShowXbmpXbmp.setNumberOfRows(2);
88+
getMenuXbmp().setNumberOfRows(2);
5989

60-
taskManager.schedule(repeatMillis(1500), [] {
61-
menuAnalogA1Value.setFloatValue(internalAnalogDevice().getCurrentFloat(A1) * analogReference());
90+
taskManager.schedule(repeatSeconds(1), [] {
91+
getMenuA1Value().setFloatValue(internalAnalogDevice().getCurrentFloat(A1) * analogReference());
6292
if(!wifiFailed) {
6393
wifiWidget.setCurrentState(fromWiFiRSSITo4StateIndicator(WiFi.RSSI()));
6494
}
6595
});
6696

97+
// here we set up the Wi-Fi and prepare a title widget that represents the Wi-Fi status.
6798
if (WiFi.status() == WL_NO_MODULE) {
6899
serlogF(SER_ERROR, "WiFi module failure");
69100
wifiFailed = true;
70101
wifiWidget.setCurrentState(0);
71-
menuWiFiConnected.setBoolean(false);
102+
getMenuConnected().setBoolean(false);
72103
}
73104

74105
if(!wifiFailed) {
75-
String fv = WiFi.firmwareVersion();
76-
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
77-
serlogF(SER_WARNING, "Please upgrade the firmware");
78-
}
79106
taskManager.schedule(onceMillis(100), tryAndStartWifi);
80107
}
81108

@@ -96,42 +123,49 @@ void setup() {
96123

97124
void loop() {
98125
taskManager.runLoop();
126+
99127
}
100128

101-
// In this case we show the image descriptions for the Xbitmap menu. We only need override the value callback. For each
102-
// time the scroll choice needs the value for an index, it calls back here.
103-
//
104129
// This callback needs to be implemented by you, see the below docs:
105130
// 1. List Docs - https://www.thecoderscorner.com/products/arduino-libraries/tc-menu/menu-item-types/list-menu-item/
106131
// 2. ScrollChoice Docs - https://www.thecoderscorner.com/products/arduino-libraries/tc-menu/menu-item-types/scrollchoice-menu-item/
107132
int CALLBACK_FUNCTION fnShowXbmpXbmpRtCall(RuntimeMenuItem* item, uint8_t row, RenderFnMode mode, char* buffer, int bufferSize) {
108133
switch(mode) {
109-
case RENDERFN_VALUE:
110-
strncpy(buffer, imageWithDescription[row].getName(), bufferSize);
111-
return true;
112-
default:
113-
return defaultRtListCallback(item, row, mode, buffer, bufferSize);
134+
case RENDERFN_VALUE:
135+
strncpy(buffer, imageWithDescription[row].getName(), bufferSize);
136+
return true;
137+
default:
138+
return defaultRtListCallback(item, row, mode, buffer, bufferSize);
114139
}
115140
}
116141

117-
void CALLBACK_FUNCTION onAnalogDacChange(int id) {
118-
internalAnalogDevice().setCurrentFloat(DAC, menuAnalogA0DAC.getCurrentValue() / 100.0F);
142+
143+
void CALLBACK_FUNCTION onStartDisco(int id) {
144+
// called when the start disco action is clicked. We start the disco!
145+
discoTime.start(getMenuSpeed().getCurrentValue() * 20);
119146
}
120147

148+
121149
void CALLBACK_FUNCTION onShowXbmp(int id) {
150+
// called whenever the start xbitmap is called, it shows how to convert
151+
// an XBitmap onto the LEDs.
122152
GFXcanvas1 canvas(12, 8);
123-
auto imgIdx = menuShowXbmpXbmp.getCurrentValue();
153+
auto imgIdx = getMenuXbmp().getCurrentValue();
124154
if(imgIdx < 0 || imgIdx >= NUMBER_OF_XBMPS) return;
125155

126156
discoTime.picture(imageWithDescription[imgIdx].getData());
127157
}
128158

129-
void CALLBACK_FUNCTION onStartDisco(int id) {
130-
discoTime.start(menuDiscoSpeed.getCurrentValue() * 20);
159+
160+
void CALLBACK_FUNCTION onAnalogDacChange(int id) {
161+
// here we take the current value of the DAC menu item and put it onto the dac.
162+
internalAnalogDevice().setCurrentFloat(DAC, getMenuA0DAC().getCurrentValue() / 100.0F);
131163
}
132164

165+
133166
void CALLBACK_FUNCTION onStartScroll(int id) {
167+
// here we start scrolling through text a word at a time when the start scroll item is clicked
134168
char sz[20];
135-
menuScrollTextText.copyValue(sz, sizeof sz);
169+
getMenuScrollText().copyValue(sz, sizeof sz);
136170
discoTime.text(sz);
137171
}

0 commit comments

Comments
 (0)