Skip to content

Commit 3457675

Browse files
committed
#181 standard version dialog, #178 activation callback for lists.
1 parent ded2121 commit 3457675

File tree

7 files changed

+37
-16
lines changed

7 files changed

+37
-16
lines changed

examples/arduino32/piPicoTftEncoder/piPicoTftEncoder.ino

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <IoLogging.h>
1010
#include <TaskManagerIO.h>
1111
#include <BaseDialog.h>
12-
#include <tcMenuVersion.h>
12+
#include <tcUtil.h>
1313

1414
// TFT_eSPI setup is "Setup60_RP2040_ILI9341.h".
1515

@@ -24,8 +24,6 @@ const char* fileNames[] = {
2424

2525
#define FILE_NAME_SIZE 5
2626

27-
void onTitlePressed(int);
28-
2927
void setup() {
3028
// This example logs using IoLogging, see the following guide to enable
3129
// https://www.thecoderscorner.com/products/arduino-libraries/io-abstraction/arduino-logging-with-io-logging/
@@ -35,7 +33,10 @@ void setup() {
3533
setupMenu();
3634

3735
// Add a callback to show the build version when the title is pressed
38-
setTitlePressedCallback(onTitlePressed);
36+
// this uses the standard function to show a version dialog from tcUtil.h
37+
setTitlePressedCallback([](int) {
38+
showVersionDialog(&applicationInfo);
39+
});
3940

4041
// Add another button that directly controls the mute menu item
4142
switches.addSwitch(22, [] (pinid_t key, bool held) {
@@ -154,6 +155,9 @@ void CALLBACK_FUNCTION onShowDialogs(int) {
154155
*/
155156
int CALLBACK_FUNCTION fnRootListRtCall(RuntimeMenuItem* item, uint8_t row, RenderFnMode mode, char* buffer, int bufferSize) {
156157
switch(mode) {
158+
case RENDERFN_ACTIVATE:
159+
serlogF2(SER_DEBUG, "List activate ", row);
160+
return false;
157161
case RENDERFN_INVOKE:
158162
// we have a list of files and a refresh option at the end.
159163
if(row < FILE_NAME_SIZE) {
@@ -187,13 +191,3 @@ int CALLBACK_FUNCTION fnRootListRtCall(RuntimeMenuItem* item, uint8_t row, Rende
187191
default: return false;
188192
}
189193
}
190-
191-
void onTitlePressed(int) {
192-
withMenuDialogIfAvailable([](MenuBasedDialog *dlg) {
193-
dlg->setButtons(BTNTYPE_NONE, BTNTYPE_CLOSE);
194-
dlg->show("TcMenu PI Pico example", false);
195-
char sz[20];
196-
tccore::copyTcMenuVersion(sz, sizeof sz);
197-
dlg->copyIntoBuffer(sz);
198-
});
199-
}

src/MenuItems.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ enum RenderFnMode : uint8_t {
297297
RENDERFN_EEPROM_POS,
298298
/** the callback has been triggered, buffer not needed */
299299
RENDERFN_INVOKE,
300+
/** list only - an item in a list has been activated, IE the index has changed) */
301+
RENDERFN_ACTIVATE,
300302
/** A new value for a position in the list, provided in buffer, it's length is in size. - used only in editable mode */
301303
RENDERFN_SET_VALUE,
302304
/** Gets the range zero based, for this part - used only in editable mode, buffer not needed */

src/RuntimeMenuItem.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ ListRuntimeMenuItem::ListRuntimeMenuItem(menuid_t id, int numberOfRows, RuntimeR
3232
RuntimeMenuItem *ListRuntimeMenuItem::getChildItem(int pos) {
3333
menuType = MENUTYPE_RUNTIME_LIST;
3434
itemPosition = pos;
35-
setActive((activeItem - 1) == pos);
35+
if((activeItem - 1) == pos) {
36+
setActive(true);
37+
renderFn(this, activeItem, RENDERFN_ACTIVATE, nullptr, 0);
38+
} else setActive(false);
3639
return this;
3740
}
3841

@@ -43,7 +46,11 @@ RuntimeMenuItem *ListRuntimeMenuItem::asParent() {
4346
}
4447

4548
RuntimeMenuItem *ListRuntimeMenuItem::asBackMenu() {
46-
setActive(activeItem == 0);
49+
if(activeItem == 0) {
50+
// the title is active.
51+
setActive(true);
52+
renderFn(this, 0, RENDERFN_ACTIVATE, nullptr, 0);
53+
} else setActive(false);
4754
menuType = MENUTYPE_BACK_VALUE;
4855
itemPosition = LIST_PARENT_ITEM_POS;
4956
return this;

src/extras/DrawableTouchCalibrator.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,5 @@ bool IoaTouchScreenCalibrator::loadCalibration() {
138138
if(rom->hasErrorOccurred()) return false;
139139

140140
serlogF(SER_TCMENU_INFO, "Loaded calibration OK");
141+
return true;
141142
}

src/tcMenuVersion.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ namespace tccore {
3939
fastltoa(buffer, TCMENU_PATCH, 3, NOT_PADDED, bufferSize);
4040
}
4141

42+
4243
}
4344

4445
#endif //TCMENU_VERSION_H

src/tcUtil.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include "MenuItems.h"
77
#include "tcMenu.h"
88
#include "tcUtil.h"
9+
#include "BaseDialog.h"
10+
#include "tcMenuVersion.h"
911

1012
#if defined __AVR__ || defined ESP_H
1113
char szGlobalBuffer[16];
@@ -23,3 +25,15 @@ uint8_t safeProgCpy(char* dst, const char* pgmSrc, uint8_t size) {
2325
dst[pos] = 0;
2426
return pos;
2527
}
28+
29+
void showVersionDialog(const ConnectorLocalInfo *localInfo) {
30+
static const ConnectorLocalInfo *localInfoStatic = localInfo;
31+
withMenuDialogIfAvailable([](MenuBasedDialog *dialog) {
32+
dialog->setButtons(BTNTYPE_NONE, BTNTYPE_CLOSE);
33+
dialog->show(localInfoStatic->name, false, nullptr);
34+
char sz[10];
35+
tccore::copyTcMenuVersion(sz, sizeof(sz));
36+
dialog->copyIntoBuffer(sz);
37+
});
38+
39+
}

src/tcUtil.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ struct ConnectorLocalInfo {
2929
char uuid[38];
3030
};
3131

32+
void showVersionDialog(const ConnectorLocalInfo* localInfo);
33+
3234
// There now follows pretty much internal code, boolean negative for dealing with program memory
3335
// never use direct program memory commands, always prefer these, it allows us
3436
// to compile it out much easier.

0 commit comments

Comments
 (0)