Skip to content

Commit 243f1a3

Browse files
author
dave
committed
#100 basic lists now work on the touch renderer. Improvements on ESP amplifier project.
1 parent 7a72837 commit 243f1a3

File tree

11 files changed

+330
-107
lines changed

11 files changed

+330
-107
lines changed

examples/colorTftEthernet32/colorTftEthernet.emf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"projectName": "/Users/dave/Documents/Arduino/tcLibraryDev/lib/tcMenu/examples/colorTftEthernet32/colorTftEthernet.emf",
44
"author": "dave",
55
"lastEdited": {
6-
"seconds": 1616685647,
7-
"nanos": 576789000
6+
"seconds": 1617353180,
7+
"nanos": 147621000
88
},
99
"namingRecursive": false,
1010
"items": [

examples/esp32Amplifier/AmplifierController.h

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#define NUM_CHANNELS 4
1515
#endif // NUM_CHANNELS
1616

17+
#define EEPROM_TRIM_POS 140
18+
1719
// 1234567890123456 1234567890123456 1234567890123456 1234567890123456
1820
const char pgmDefaultChannelNames[] PROGMEM = "Turntable\0 Auxiliary\0 USB Audio\0 Storage\0";
1921

@@ -29,18 +31,21 @@ class AmplifierController {
2931
OVERHEATED
3032
};
3133
private:
32-
AnalogMenuItem* levelTrims[NUM_CHANNELS]{};
3334
bool audioDirect;
3435
bool muted = true;
36+
int levelTrims[NUM_CHANNELS];
3537
public:
36-
explicit AmplifierController(AnalogMenuItem* trims[NUM_CHANNELS]) {
37-
for(int i=0; i<NUM_CHANNELS; i++) {
38-
levelTrims[i] = trims[i];
39-
}
38+
explicit AmplifierController() : levelTrims{} {
4039
menuMute.setBoolean(true);
4140
setAmpStatus(WARMING_UP);
4241
}
4342

43+
void initialise() {
44+
for(int i=0; i<NUM_CHANNELS; i++) {
45+
levelTrims[i] = menuMgr.getEepromAbstraction()->read8(EEPROM_TRIM_POS + i);
46+
}
47+
}
48+
4449
uint8_t getChannelInt() {
4550
uint8_t ch = menuChannels.getCurrentValue();
4651
if(ch > NUM_CHANNELS) return 0;
@@ -56,7 +61,7 @@ class AmplifierController {
5661
}
5762

5863
void onVolumeChanged() {
59-
auto trim = levelTrims[getChannelInt()]->getCurrentValue();
64+
auto trim = levelTrims[getChannelInt()];
6065
auto vol = menuVolume.getCurrentValue() + trim;
6166
auto volToWrite = menuMute.getBoolean() ? 0 : vol;
6267
serdebugF2("write volume to bus", volToWrite);
@@ -75,6 +80,18 @@ class AmplifierController {
7580
void onMute(bool mute) {
7681
muted = mute;
7782
}
83+
84+
int getTrim(uint8_t channel) {
85+
if(channel >= NUM_CHANNELS) return 0;
86+
return levelTrims[channel];
87+
}
88+
89+
void setTrim(uint8_t channel, int newTrim) {
90+
if(channel >= NUM_CHANNELS) return;
91+
levelTrims[channel] = newTrim;
92+
menuMgr.getEepromAbstraction()->write8(EEPROM_TRIM_POS + channel, newTrim);
93+
}
94+
7895
};
7996

8097
#endif //TCMENU_ESPAMPLIFIER_AMPLIFIERCONTROLLER_H
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#ifndef TCMENU_ESPAMPLIFIER_TESTINGDIALOGCONTROLLER_H
2+
#define TCMENU_ESPAMPLIFIER_TESTINGDIALOGCONTROLLER_H
3+
4+
class TestingDialogController : public BaseDialogController {
5+
private:
6+
MenuBasedDialog* theDialog;
7+
public:
8+
void initialiseAndGetHeader(BaseDialog *dialog, char *buffer, size_t bufferSize) override {
9+
theDialog = reinterpret_cast<MenuBasedDialog *>(dialog);
10+
strcpy(buffer, "Test Dialog");
11+
}
12+
13+
void dialogDismissed(ButtonType buttonType) override {
14+
if(buttonType == BTNTYPE_OK) {
15+
theDialog->setButtons(BTNTYPE_NONE, BTNTYPE_CLOSE);
16+
theDialog->showRam("Extra dlg", true);
17+
theDialog->copyIntoBuffer("more text");
18+
}
19+
}
20+
21+
bool dialogButtonPressed(int buttonNum) override {
22+
return true;
23+
}
24+
25+
void copyCustomButtonText(int buttonNumber, char *buffer, size_t bufferSize) override {
26+
buffer[0] = 0;
27+
}
28+
} testingDialogController;
29+
30+
inline void showDialogs() {
31+
auto *dlg = renderer.getDialog();
32+
if (dlg && !dlg->isInUse()) {
33+
dlg->setButtons(BTNTYPE_OK, BTNTYPE_CANCEL);
34+
dlg->showController(true, &testingDialogController);
35+
dlg->copyIntoBuffer("some more text");
36+
}
37+
}
38+
39+
#endif //TCMENU_ESPAMPLIFIER_TESTINGDIALOGCONTROLLER_H

examples/esp32Amplifier/esp32Amplifier.emf

Lines changed: 56 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"lastEdited": {
3-
"seconds": 1617265602,
3+
"seconds": 1617370133,
44
"nanos": 0
55
},
66
"codeOptions": {
@@ -123,14 +123,14 @@
123123
"parentId": 0,
124124
"type": "scrollItem",
125125
"item": {
126-
"name": "Channels",
126+
"name": "Channel",
127127
"eepromAddress": 4,
128128
"id": 2,
129129
"readOnly": false,
130130
"localOnly": false,
131131
"visible": true,
132132
"functionName": "onChannelChanged",
133-
"variableName": "",
133+
"variableName": "Channels",
134134
"itemWidth": 16,
135135
"numEntries": 3,
136136
"variable": null,
@@ -186,7 +186,7 @@
186186
"parentId": 5,
187187
"type": "subMenu",
188188
"item": {
189-
"name": "Channel Names",
189+
"name": "Channel Settings",
190190
"eepromAddress": -1,
191191
"id": 7,
192192
"readOnly": false,
@@ -197,54 +197,69 @@
197197
}
198198
},
199199
{
200-
"parentId": 5,
200+
"parentId": 7,
201+
"type": "scrollItem",
202+
"item": {
203+
"name": "Channel Num",
204+
"eepromAddress": -1,
205+
"id": 23,
206+
"readOnly": false,
207+
"localOnly": false,
208+
"visible": true,
209+
"functionName": "",
210+
"variableName": "ChannelSettingsChannel",
211+
"itemWidth": 10,
212+
"numEntries": 3,
213+
"variable": null,
214+
"eepromOffset": 0,
215+
"choiceMode": "CUSTOM_RENDERFN"
216+
}
217+
},
218+
{
219+
"parentId": 7,
201220
"type": "analogItem",
202221
"item": {
203-
"name": "Line 1 adj",
222+
"name": "Level Trim",
204223
"eepromAddress": 9,
205224
"id": 8,
206225
"readOnly": false,
207226
"localOnly": false,
208227
"visible": true,
209-
"variableName": "",
228+
"variableName": "ChannelSettingsLevelTrim",
210229
"maxValue": 20,
211230
"offset": -10,
212231
"divisor": 2,
213232
"unitName": "dB"
214233
}
215234
},
216235
{
217-
"parentId": 5,
218-
"type": "analogItem",
236+
"parentId": 7,
237+
"type": "textItem",
219238
"item": {
220-
"name": "Line 2 adj",
221-
"eepromAddress": 11,
222-
"id": 9,
239+
"name": "Name",
240+
"eepromAddress": -1,
241+
"id": 22,
223242
"readOnly": false,
224243
"localOnly": false,
225244
"visible": true,
226-
"variableName": "",
227-
"maxValue": 20,
228-
"offset": -10,
229-
"divisor": 2,
230-
"unitName": "dB"
245+
"functionName": "",
246+
"variableName": "ChannelSettingsName",
247+
"itemType": "PLAIN_TEXT",
248+
"textLength": 15
231249
}
232250
},
233251
{
234-
"parentId": 5,
235-
"type": "analogItem",
252+
"parentId": 7,
253+
"type": "actionMenu",
236254
"item": {
237-
"name": "Line 3 adj",
238-
"eepromAddress": 13,
239-
"id": 10,
255+
"name": "Update Settings",
256+
"eepromAddress": -1,
257+
"id": 24,
240258
"readOnly": false,
241259
"localOnly": false,
242260
"visible": true,
243-
"variableName": "",
244-
"maxValue": 20,
245-
"offset": -10,
246-
"divisor": 2,
247-
"unitName": "dB"
261+
"functionName": "onChannelSetttingsUpdate",
262+
"variableName": "ChannelSettingsUpdateSettings"
248263
}
249264
},
250265
{
@@ -281,6 +296,20 @@
281296
"unitName": "s"
282297
}
283298
},
299+
{
300+
"parentId": 5,
301+
"type": "actionMenu",
302+
"item": {
303+
"name": "Save settings",
304+
"eepromAddress": -1,
305+
"id": 25,
306+
"readOnly": false,
307+
"localOnly": false,
308+
"visible": true,
309+
"functionName": "onSaveSettings",
310+
"variableName": ""
311+
}
312+
},
284313
{
285314
"parentId": 0,
286315
"type": "subMenu",

examples/esp32Amplifier/esp32Amplifier_main.cpp

Lines changed: 53 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
#include "AmplifierController.h"
2020
#include "app_icondata.h"
2121
#include "TouchCalibrator.h"
22+
#include "TestingDialogController.h"
2223

2324
const char pgmVersionHeader[] PROGMEM = "tcMenu Version";
2425

2526
bool connectedToWifi = false;
2627
EepromAuthenticatorManager authManager;
2728
TitleWidget wifiWidget(iconsWifi, 5, 16, 12, nullptr);
28-
AnalogMenuItem* adjustMenuItems[] = {&menuSettingsLine1Adj, &menuSettingsLine2Adj, &menuSettingsLine3Adj};
29-
AmplifierController controller(adjustMenuItems);
29+
AmplifierController controller;
3030

3131
void prepareWifiForUse();
3232

@@ -54,6 +54,8 @@ void setup() {
5454
menuDirect.setBoolean(true, true);
5555
});
5656

57+
controller.initialise();
58+
5759
touchScreen.calibrateMinMaxValues(0.240F, 0.895F, 0.09F, 0.88F);
5860

5961
renderer.setCustomDrawingHandler(new TouchScreenCalibrator(&touchScreen));
@@ -92,6 +94,8 @@ void setup() {
9294
dlg->show(pgmVersionHeader, false);
9395
});
9496

97+
menuStatusDataList.setNumberOfRows(5);
98+
9599
// If your app relies on getting the callbacks after a menuMgr.load(..) has finished then this does the callbacks
96100
triggerAllChangedCallbacks();
97101
}
@@ -155,45 +159,14 @@ void CALLBACK_FUNCTION onMuteSound(int id) {
155159
controller.onMute(menuMute.getBoolean());
156160
}
157161

158-
class TestingDialogController : public BaseDialogController {
159-
private:
160-
MenuBasedDialog* theDialog;
161-
public:
162-
void initialiseAndGetHeader(BaseDialog *dialog, char *buffer, size_t bufferSize) override {
163-
theDialog = reinterpret_cast<MenuBasedDialog *>(dialog);
164-
strcpy(buffer, "Test Dialog");
165-
}
166-
167-
void dialogDismissed(ButtonType buttonType) override {
168-
if(buttonType == BTNTYPE_OK) {
169-
theDialog->setButtons(BTNTYPE_NONE, BTNTYPE_CLOSE);
170-
theDialog->showRam("Extra dlg", true);
171-
theDialog->copyIntoBuffer("more text");
172-
}
173-
}
174-
175-
bool dialogButtonPressed(int buttonNum) override {
176-
return true;
177-
}
178-
179-
void copyCustomButtonText(int buttonNumber, char *buffer, size_t bufferSize) override {
180-
buffer[0] = 0;
181-
}
182-
} testingDialogController;
183-
184162
void CALLBACK_FUNCTION onShowDialogs(int id) {
185-
auto* dlg = renderer.getDialog();
186-
if(dlg && !dlg->isInUse()) {
187-
dlg->setButtons(BTNTYPE_OK, BTNTYPE_CANCEL);
188-
dlg->showController(true, &testingDialogController);
189-
dlg->copyIntoBuffer("some more text");
190-
}
163+
showDialogs();
191164
}
192165

193166
int CALLBACK_FUNCTION fnStatusDataListRtCall(RuntimeMenuItem* item, uint8_t row, RenderFnMode mode, char* buffer, int bufferSize) {
194167
switch(mode) {
195168
case RENDERFN_INVOKE:
196-
if(renderer.getDialog() && renderer.getDialog()->isInUse()) {
169+
if(row != LIST_PARENT_ITEM_POS && renderer.getDialog() && !renderer.getDialog()->isInUse()) {
197170
renderer.getDialog()->setButtons(BTNTYPE_NONE, BTNTYPE_CLOSE);
198171
renderer.getDialog()->showRam("List select", false);
199172
char sz[10];
@@ -212,3 +185,48 @@ int CALLBACK_FUNCTION fnStatusDataListRtCall(RuntimeMenuItem* item, uint8_t row,
212185
default: return false;
213186
}
214187
}
188+
189+
int CALLBACK_FUNCTION fnChannelSettingsChannelRtCall(RuntimeMenuItem * item, uint8_t row, RenderFnMode mode, char * buffer, int bufferSize) {
190+
switch(mode) {
191+
case RENDERFN_INVOKE: {
192+
auto *eeprom = menuMgr.getEepromAbstraction();
193+
auto romPos = menuChannels.getEepromStart() + (row * menuChannels.getItemWidth());
194+
eeprom->readIntoMemArray((uint8_t *) menuChannelSettingsName.getTextValue(), romPos, menuChannels.getItemWidth());
195+
menuChannelSettingsLevelTrim.setCurrentValue(controller.getTrim(row));
196+
return true;
197+
}
198+
case RENDERFN_NAME:
199+
strcpy(buffer, "Channel");
200+
return true;
201+
case RENDERFN_VALUE:
202+
strcpy(buffer, "Line");
203+
fastltoa(buffer, row + 1, 2, NOT_PADDED, bufferSize);
204+
return true;
205+
case RENDERFN_EEPROM_POS: return 0xFFFF; // lists are generally not saved to EEPROM
206+
default: return false;
207+
}
208+
}
209+
210+
void CALLBACK_FUNCTION onChannelSetttingsUpdate(int id) {
211+
auto *eeprom = menuMgr.getEepromAbstraction();
212+
auto romPos = menuChannels.getEepromStart() + (menuChannelSettingsChannel.getCurrentValue() * menuChannels.getItemWidth());
213+
eeprom->writeArrayToRom(romPos, (uint8_t *) menuChannelSettingsName.getTextValue(), menuChannels.getItemWidth());
214+
controller.setTrim(menuChannelSettingsChannel.getCurrentValue(), menuChannelSettingsLevelTrim.getCurrentValue());
215+
if(renderer.getDialog() && !renderer.getDialog()->isInUse()) {
216+
renderer.getDialog()->setButtons(BTNTYPE_NONE, BTNTYPE_OK);
217+
renderer.getDialog()->showRam("Channel setting saved", true);
218+
char sz[5];
219+
ltoaClrBuff(sz, menuChannelSettingsChannel.getCurrentValue(), 2, NOT_PADDED, sizeof sz);
220+
renderer.getDialog()->copyIntoBuffer(sz);
221+
}
222+
}
223+
224+
void CALLBACK_FUNCTION onSaveSettings(int id) {
225+
menuMgr.save();
226+
EEPROM.commit();
227+
228+
if(renderer.getDialog() && !renderer.getDialog()->isInUse()) {
229+
renderer.getDialog()->setButtons(BTNTYPE_NONE, BTNTYPE_OK);
230+
renderer.getDialog()->showRam("Committed all items", true);
231+
}
232+
}

0 commit comments

Comments
 (0)