Skip to content

Commit 59cb3c4

Browse files
author
dave
committed
Improved documentation
1 parent fcbb39c commit 59cb3c4

File tree

2 files changed

+36
-18
lines changed

2 files changed

+36
-18
lines changed

examples/arduino32/colorTftEthernet32/ColorEtherenetCustomDraw.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
#include <BaseRenderers.h>
1515
#include "colorTftEthernet32_menu.h"
1616

17+
// Here we implement the custom drawing capability of the renderer, it allows us to receive reset and custom drawing
18+
// requests. More info in the link below:
19+
// https://www.thecoderscorner.com/products/arduino-libraries/tc-menu/renderer-take-over-display/
1720
class ColorEthernetCustomDraw : public CustomDrawing {
1821
public:
1922
void reset() override {
@@ -23,6 +26,7 @@ class ColorEthernetCustomDraw : public CustomDrawing {
2326
}
2427

2528
void started(BaseMenuRenderer *currentRenderer) override {
29+
// this method is called by the renderer when the screen is first taken over
2630
// you need to handle the clearing and preparation of the display when first called.
2731
switches.getEncoder()->changePrecision(1000, 500);
2832
gfx.setCursor(0, 0);
@@ -34,6 +38,11 @@ class ColorEthernetCustomDraw : public CustomDrawing {
3438

3539

3640
void renderLoop(unsigned int currentValue, RenderPressMode pressType) override {
41+
// this method is called by the renderer when the screen is taken in a loop
42+
// it is called at the display refresh interval. "started" is always called
43+
// first. You are provided the current encoder value and state of the OK
44+
// button. If you're using touch screen these value may not be relevant.
45+
3746
// if the encoder / select button is held, we go back to the menu.
3847
if(pressType == RPRESS_HELD) {
3948
renderer.giveBackDisplay();

examples/arduino32/colorTftEthernet32/colorTftEthernet32.ino

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/*
2+
* Shows how to use adafruit graphics with a TFT panel and an ethernet module.
3+
* This is a 32 bit example, which by default targets 32 bit devices.
4+
* Assumed board for this is a SAMD based MKR board.
5+
*
6+
* Getting started: https://www.thecoderscorner.com/products/arduino-libraries/tc-menu/tcmenu-overview-quick-start/
7+
*
8+
* For more details see the README.md file in this directory.
9+
*/
10+
111
#include "colorTftEthernet32_menu.h"
212
#include <IoAbstractionWire.h>
313
#include <EepromAbstractionWire.h>
@@ -10,27 +20,17 @@
1020
#include "ColorEtherenetCustomDraw.h"
1121
#include <tcMenuVersion.h>
1222

13-
// contains the graphical widget title components.
23+
// contains the tcMenu library included graphical widget title components.
1424
#include "stockIcons/wifiAndConnectionIcons16x12.h"
1525

16-
/*
17-
* Shows how to use adafruit graphics with a TFT panel and an ethernet module.
18-
* This is a 32 bit example, which by default targets 32 bit devices.
19-
* Assumed board for this is a SAMD based MKR board.
20-
*
21-
* Getting started: https://www.thecoderscorner.com/products/arduino-libraries/tc-menu/tcmenu-overview-quick-start/
22-
*
23-
* For more details see the README.md file in this directory.
24-
*/
25-
2626
// we are going to allow control of the menu over local area network
2727
// so therefore must configure ethernet..
2828
byte mac[] = {
2929
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
3030
};
3131

32-
// and we create an analog device with enhanced range because we are using a 32bit board.
33-
ArduinoAnalogDevice analogDevice(12, 10);
32+
// and we create an analog device with enhanced range because on M.
33+
ArduinoAnalogDevice& analogDevice = internalAnalogDevice();
3434

3535
// We add a title widget that shows when a user is connected to the device. Connection icons
3636
// are in the standard icon set we included at the top.
@@ -66,9 +66,12 @@ void onCommsChange(CommunicationInfo info) {
6666
}
6767

6868
void setup() {
69+
// This example logs using IoLogging, see the following guide to enable
70+
// https://www.thecoderscorner.com/products/arduino-libraries/io-abstraction/arduino-logging-with-io-logging/
71+
IOLOG_START_SERIAL
72+
6973
// we used an i2c device (io8574) so must initialise wire too
7074
Wire.begin();
71-
Serial.begin(115200);
7275

7376
// here we make all menu items except menu voltage wrap around. Wrap means that when the value hits maximum it
7477
// goes back to 0, and when it hits 0 it goes back to maximum. Default is all wrapping off.
@@ -120,9 +123,14 @@ void setup() {
120123
// register the custom drawing handler
121124
renderer.setCustomDrawingHandler(&myCustomDraw);
122125

123-
ioDevicePinMode(switches.getIoAbstraction(), ledPin, OUTPUT);
126+
// set the LED pin that we control as output
127+
switches.getIoAbstraction()->pinMode(ledPin, OUTPUT);
124128

129+
// we can register call back that is called when the main menu title is pressed, in this case we just show
130+
// the tcMenu version number in a dialog.
125131
setTitlePressedCallback([](int id) {
132+
// withMenuDialogIfAvailable checks if the dialog can be presented now, and if so will call the function
133+
// provided with the dialog as the parameter. you then just prepare the dialog to be shown.
126134
withMenuDialogIfAvailable([](MenuBasedDialog* dlg) {
127135
dlg->setButtons(BTNTYPE_CLOSE, BTNTYPE_NONE);
128136
dlg->showRam("ARM Example", false);
@@ -132,7 +140,6 @@ void setup() {
132140
});
133141
});
134142

135-
// Start 2nd encoder
136143
Serial.println("Setting up second encoder now");
137144

138145
// here we want the encoder set to the range of values that menuCurrent takes, this is just for example,
@@ -147,7 +154,7 @@ void setup() {
147154
// it will repeat at 25 * 20 millis before acceleration kicks in.
148155
switches.addSwitch(encoder2Click, [](pinid_t pin, bool held) {
149156
menuPwrDelay.setBoolean(!menuPwrDelay.getBoolean());
150-
ioDeviceDigitalWriteS(switches.getIoAbstraction(), ledPin, menuPwrDelay.getBoolean());
157+
switches.getIoAbstraction()->digitalWriteS(ledPin, menuPwrDelay.getBoolean());
151158
}, 25);
152159
// End 2nd encoder
153160
}
@@ -157,9 +164,11 @@ void loop() {
157164
}
158165

159166
void writeToDac() {
167+
// here we show how to convert analog menu items into floating point values
160168
float volts = menuVoltage.getAsFloatingPointValue();
161169
float curr = menuCurrent.getAsFloatingPointValue();
162-
170+
171+
// and now we set the output voltage of A0 using a float between 0..1
163172
float total = (volts / 64.0F) * (curr / 2.0F);
164173
analogDevice.setCurrentFloat(A0, total);
165174
menuVoltA0.setFloatValue(total);

0 commit comments

Comments
 (0)