3
3
* are available. By default it is setup for an OLED screen and a rotary encoder, although it could be moved to use
4
4
* many other different display and input technologies.
5
5
*
6
+ * It demonstrates the use of the card menu layout, where items are shown one at a time as you scroll through them,
7
+ * configuring some items to use larger than usual fonts, and other items to render as icons. It also has an ethernet
8
+ * network remote included too.
9
+ *
6
10
* Getting started: https://www.thecoderscorner.com/products/arduino-libraries/tc-menu/tcmenu-overview-quick-start/
7
11
*/
8
12
@@ -49,12 +53,15 @@ const uint8_t standardNetMask[] = { 255, 255, 255, 0 };
49
53
// 2. https://tcmenu.github.io/documentation/arduino-libraries/tc-menu/themes/rendering-with-themes-icons-grids/
50
54
51
55
// here we provide two title widgets, for ethernet connection, and client connection
52
- TitleWidget widgetConnection (iconsConnection, 2 , 16 , 12 , nullptr );
53
- TitleWidget widgetEthernet (iconsEthernetConnection, 2 , 16 , 12 , &widgetConnection );
56
+ TitleWidget widgetConnection (iconsConnection, 2 , 16 , 12 );
57
+ TitleWidget widgetEthernet (iconsEthernetConnection, 2 , 16 , 12 );
54
58
55
59
color_t defaultCardPalette[] = {1 , 0 , 1 , 1 };
56
60
57
61
void overrideDrawingForMainMenu (TcThemeBuilder& themeBuilder) {
62
+ // now we make the two settings and status menus use icons instead of regular drawing, and the numbered menu items
63
+ // 33,45,78 to use a larger font so it takes the entire screen.
64
+
58
65
// we're going to use this a few times so declare once
59
66
const Coord iconSize (APPICONS_WIDTH, APPICONS_HEIGHT);
60
67
@@ -105,32 +112,44 @@ void overrideDrawingForMainMenu(TcThemeBuilder& themeBuilder) {
105
112
}
106
113
107
114
void overrideDrawingForCardMenu (TcThemeBuilder& themeBuilder) {
108
- // override every single item on the card menu to have larger font and different padding/justification
115
+ // override back button on the card menu to be the default 32x32 back icon
116
+ themeBuilder.menuItemOverride (menuBackStatusCards)
117
+ .withJustification (tcgfx::GridPosition::JUSTIFY_CENTER_WITH_VALUE)
118
+ .withPadding (MenuPadding (2 ))
119
+ .withPalette (defaultCardPalette)
120
+ .withImageXbmp (Coord (32 , 32 ), defaultBackIconBitmap)
121
+ .onRow (0 ) // <== if you prefer that the back item is not first, you can change its order here
122
+ .apply ();
123
+
124
+ // override every single item on the card sub menu to have larger font and different padding/justification
109
125
themeBuilder.submenuPropertiesActionOverride (menuStatusCards)
110
126
.withJustification (tcgfx::GridPosition::JUSTIFY_CENTER_NO_VALUE)
111
- .withNativeFont (u8g2_font_inr33_mn , 1 )
127
+ .withNativeFont (u8g2_font_inb16_mf , 1 )
112
128
.withPadding (MenuPadding (2 ))
113
129
.apply ();
114
130
}
115
131
116
- void setupGridLayoutForCardView () {
132
+ void setupCardLayoutAndWidgets () {
117
133
// create a theme builder to help us configure how to draw.
118
134
TcThemeBuilder themeBuilder (renderer);
119
135
120
136
// enable card layout providing the left and right icons. This enables for root menu
121
137
themeBuilder.enableCardLayoutWithXbmImages (Coord (11 , 22 ), ArrowHoriz11x22BitmapLeft, ArrowHoriz11x22BitmapRight, true )
122
138
.setMenuAsCard (menuStatusCards, true );
123
139
124
- // see the method above where we override drawing for all items that are in card layout.
140
+ // these two functions, defined directly above this one configure the icons and special text arrangements for
141
+ // the items in the card layouts.
125
142
overrideDrawingForMainMenu (themeBuilder);
126
143
overrideDrawingForCardMenu (themeBuilder);
127
144
128
- // now we make the two settings and status menus use icons instead of regular drawing.
145
+ themeBuilder.addingTitleWidget (widgetEthernet)
146
+ .addingTitleWidget (widgetConnection);
147
+
148
+ // You must always call apply after doing anything with theme builder.
129
149
themeBuilder.apply ();
130
150
131
151
// now we set the title widgets that appear on the top right, for the link status we check the ethernet library
132
152
// status every half second and update the widget to represent that status.
133
- renderer.setFirstWidget (&widgetEthernet);
134
153
taskManager.scheduleFixedRate (500 , [] {
135
154
widgetEthernet.setCurrentState (Ethernet.linkStatus () == LinkON ? 1 : 0 );
136
155
});
@@ -148,17 +167,18 @@ using namespace tcremote;
148
167
149
168
void setup () {
150
169
// This example logs using IoLogging, see the following guide to enable
151
- // https://www.thecoderscorner.com/products /arduino-libraries/io-abstraction/arduino-logging-with-io-logging/
170
+ // https://tcmenu.github.io/documentation /arduino-libraries/ /io-abstraction/arduino-logging-with-io-logging/
152
171
IOLOG_START_SERIAL
153
172
serEnableLevel (SER_NETWORK_DEBUG, true );
173
+ serEnableLevel (SER_TCMENU_DEBUG, true );
154
174
155
- // Start up serial and prepare the correct SPI, your pins may differ
175
+ // Start up serial and prepare the correct SPI, your pins or method of doing this may differ
156
176
SPI.setMISO (PB4);
157
177
SPI.setMOSI (PB5);
158
178
SPI.setSCLK (PB3);
159
179
160
- //
161
- // Here we start up the Stm32Ethernet library for STM32 boards/chips with built-in ethernet
180
+ // Here we start up the Stm32Ethernet library for STM32 boards/chips with built-in ethernet, again you could
181
+ // easily change this for your own boards network arrangements
162
182
Ethernet.begin ();
163
183
Serial.print (" My IP address is " );
164
184
Ethernet.localIP ().printTo (Serial);
@@ -167,13 +187,14 @@ void setup() {
167
187
// and then run the menu setup
168
188
setupMenu ();
169
189
170
- // now load back values from EEPROM, but only when we can read the confirmatory magic key, see EEPROM loading in the docs
190
+ // now load back values from EEPROM, but only when we can read the confirmatory magic key, see EEPROM docs:
191
+ // https://tcmenu.github.io/documentation/arduino-libraries/tc-menu/menu-eeprom-integrations/
171
192
menuMgr.load (0xd00d , [] {
172
193
// this gets called when the menu hasn't been saved before, to initialise the first time.
173
194
menuDecimal.setCurrentValue (4 );
174
195
});
175
196
176
- // here we register the custom drawing we created earlier with the renderer
197
+ // here we register the custom drawing created in `RawCustomDrawing.h`
177
198
myCustomDrawing.registerWithRenderer ();
178
199
179
200
// We can set a callback for when the title item is pressed on the main menu, here we just take over the display
@@ -185,7 +206,7 @@ void setup() {
185
206
menuRuntimesCustomList.setNumberOfRows (10 );
186
207
187
208
// now we set up the layouts to make the card view look right.
188
- setupGridLayoutForCardView ();
209
+ setupCardLayoutAndWidgets ();
189
210
}
190
211
191
212
void loop () {
0 commit comments