Skip to content

Commit e9766f8

Browse files
committed
#177 clean up BSP touch support
1 parent 3c70ec6 commit e9766f8

File tree

10 files changed

+107
-54
lines changed

10 files changed

+107
-54
lines changed

examples/mbed/stm32f429FrameBuffer/stm32f429FrameBuffer.emf

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"eepromAddress": -1,
1616
"readOnly": false,
1717
"localOnly": false,
18-
"visible": true
18+
"visible": true,
19+
"staticDataInRAM": false
1920
}
2021
},
2122
{
@@ -34,7 +35,8 @@
3435
"eepromAddress": -1,
3536
"readOnly": false,
3637
"localOnly": false,
37-
"visible": true
38+
"visible": true,
39+
"staticDataInRAM": false
3840
}
3941
},
4042
{
@@ -53,7 +55,8 @@
5355
"eepromAddress": -1,
5456
"readOnly": false,
5557
"localOnly": false,
56-
"visible": true
58+
"visible": true,
59+
"staticDataInRAM": false
5760
}
5861
},
5962
{
@@ -67,7 +70,8 @@
6770
"eepromAddress": -1,
6871
"readOnly": false,
6972
"localOnly": false,
70-
"visible": true
73+
"visible": true,
74+
"staticDataInRAM": false
7175
}
7276
},
7377
{
@@ -87,7 +91,8 @@
8791
"functionName": "onTargetChanged",
8892
"readOnly": false,
8993
"localOnly": false,
90-
"visible": true
94+
"visible": true,
95+
"staticDataInRAM": false
9196
}
9297
},
9398
{
@@ -103,7 +108,8 @@
103108
"eepromAddress": 4,
104109
"readOnly": false,
105110
"localOnly": false,
106-
"visible": true
111+
"visible": true,
112+
"staticDataInRAM": false
107113
}
108114
},
109115
{
@@ -117,7 +123,8 @@
117123
"eepromAddress": -1,
118124
"readOnly": false,
119125
"localOnly": false,
120-
"visible": true
126+
"visible": true,
127+
"staticDataInRAM": false
121128
}
122129
},
123130
{
@@ -132,7 +139,8 @@
132139
"eepromAddress": 8,
133140
"readOnly": false,
134141
"localOnly": false,
135-
"visible": true
142+
"visible": true,
143+
"staticDataInRAM": false
136144
}
137145
},
138146
{
@@ -146,7 +154,8 @@
146154
"eepromAddress": -1,
147155
"readOnly": false,
148156
"localOnly": false,
149-
"visible": true
157+
"visible": true,
158+
"staticDataInRAM": false
150159
}
151160
},
152161
{
@@ -165,7 +174,8 @@
165174
"eepromAddress": -1,
166175
"readOnly": true,
167176
"localOnly": false,
168-
"visible": true
177+
"visible": true,
178+
"staticDataInRAM": false
169179
}
170180
},
171181
{
@@ -184,7 +194,8 @@
184194
"eepromAddress": -1,
185195
"readOnly": true,
186196
"localOnly": false,
187-
"visible": true
197+
"visible": true,
198+
"staticDataInRAM": false
188199
}
189200
},
190201
{
@@ -200,7 +211,8 @@
200211
"eepromAddress": -1,
201212
"readOnly": false,
202213
"localOnly": false,
203-
"visible": true
214+
"visible": true,
215+
"staticDataInRAM": false
204216
}
205217
},
206218
{
@@ -216,7 +228,8 @@
216228
"eepromAddress": -1,
217229
"readOnly": false,
218230
"localOnly": false,
219-
"visible": true
231+
"visible": true,
232+
"staticDataInRAM": false
220233
}
221234
},
222235
{
@@ -231,7 +244,8 @@
231244
"eepromAddress": -1,
232245
"readOnly": false,
233246
"localOnly": false,
234-
"visible": true
247+
"visible": true,
248+
"staticDataInRAM": false
235249
}
236250
},
237251
{
@@ -248,7 +262,8 @@
248262
"eepromAddress": -1,
249263
"readOnly": false,
250264
"localOnly": false,
251-
"visible": true
265+
"visible": true,
266+
"staticDataInRAM": false
252267
}
253268
},
254269
{
@@ -263,7 +278,8 @@
263278
"eepromAddress": -1,
264279
"readOnly": false,
265280
"localOnly": false,
266-
"visible": true
281+
"visible": true,
282+
"staticDataInRAM": false
267283
}
268284
},
269285
{
@@ -277,7 +293,8 @@
277293
"functionName": "onPresentDialog",
278294
"readOnly": false,
279295
"localOnly": false,
280-
"visible": true
296+
"visible": true,
297+
"staticDataInRAM": false
281298
}
282299
},
283300
{
@@ -291,7 +308,8 @@
291308
"eepromAddress": -1,
292309
"readOnly": false,
293310
"localOnly": false,
294-
"visible": true
311+
"visible": true,
312+
"staticDataInRAM": false
295313
}
296314
},
297315
{
@@ -310,7 +328,8 @@
310328
"eepromAddress": -1,
311329
"readOnly": false,
312330
"localOnly": false,
313-
"visible": true
331+
"visible": true,
332+
"staticDataInRAM": false
314333
}
315334
},
316335
{
@@ -329,7 +348,8 @@
329348
"eepromAddress": -1,
330349
"readOnly": false,
331350
"localOnly": false,
332-
"visible": true
351+
"visible": true,
352+
"staticDataInRAM": false
333353
}
334354
}
335355
],
@@ -360,16 +380,31 @@
360380
"latestValue": "10",
361381
"subsystem": "DISPLAY"
362382
},
383+
{
384+
"name": "TOUCH_SEPARATOR",
385+
"latestValue": "",
386+
"subsystem": "DISPLAY"
387+
},
388+
{
389+
"name": "TOUCH_SCREEN_REQUIRED",
390+
"latestValue": "true",
391+
"subsystem": "DISPLAY"
392+
},
363393
{
364394
"name": "TOUCH_ROTATION",
365395
"latestValue": "PORTRAIT",
366396
"subsystem": "DISPLAY"
367397
},
368398
{
369-
"name": "TOUCH_SCREEN_REQUIRED",
399+
"name": "TOUCH_SCREEN_CALIBRATE",
370400
"latestValue": "true",
371401
"subsystem": "DISPLAY"
372402
},
403+
{
404+
"name": "TOUCH_CALIBRATION_STORAGE_LOC",
405+
"latestValue": "400",
406+
"subsystem": "DISPLAY"
407+
},
373408
{
374409
"name": "ITEM_FONT",
375410
"latestValue": "ada:OpenSansCyrillicLatin18,0",
@@ -409,6 +444,7 @@
409444
"namingRecursive": true,
410445
"saveToSrc": false,
411446
"useCppMain": true,
447+
"usingSizedEEPROMStorage": false,
412448
"eepromDefinition": "bsp:0",
413449
"authenticatorDefinition": "",
414450
"projectIoExpanders": [

examples/mbed/stm32f429FrameBuffer/stm32f429FrameBuffer_menu.cpp

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,24 @@ StChromaArtDrawable Drawable;
2121
GraphicsDeviceRenderer renderer(30, applicationInfo.name, &Drawable);
2222
StBspTouchInterrogator touchInterrogator(240, 320);
2323
MenuTouchScreenManager touchScreen(&touchInterrogator, &renderer, iotouch::TouchInterrogator::PORTRAIT);
24+
tcextras::IoaTouchScreenCalibrator touchCalibrator(&touchScreen, &renderer, 400);
2425

2526
// Global Menu Item declarations
2627
const AnalogMenuInfo minfoUnicodeLevel = { "Рівень", 21, 0xffff, 1000, NO_CALLBACK, 0, 10, "П" };
27-
AnalogMenuItem menuUnicodeLevel(&minfoUnicodeLevel, 0, NULL);
28+
AnalogMenuItem menuUnicodeLevel(&minfoUnicodeLevel, 0, NULL, INFO_LOCATION_PGM);
2829
const char enumStrUnicodeChoice_0[] = "Салат";
2930
const char enumStrUnicodeChoice_1[] = "піца";
3031
const char enumStrUnicodeChoice_2[] = "борщ";
3132
const char* const enumStrUnicodeChoice[] = { enumStrUnicodeChoice_0, enumStrUnicodeChoice_1, enumStrUnicodeChoice_2 };
3233
const EnumMenuInfo minfoUnicodeChoice = { "Вибір", 20, 0xffff, 2, NO_CALLBACK, enumStrUnicodeChoice };
33-
EnumMenuItem menuUnicodeChoice(&minfoUnicodeChoice, 0, &menuUnicodeLevel);
34-
RENDERING_CALLBACK_NAME_INVOKE(fnUnicodeRtCall, backSubItemRenderFn, "Unicode", -1, NO_CALLBACK)
34+
EnumMenuItem menuUnicodeChoice(&minfoUnicodeChoice, 0, &menuUnicodeLevel, INFO_LOCATION_PGM);
3535
const SubMenuInfo minfoUnicode = { "Unicode", 19, 0xffff, 0, NO_CALLBACK };
36-
BackMenuItem menuBackUnicode(fnUnicodeRtCall, &menuUnicodeChoice);
37-
SubMenuItem menuUnicode(&minfoUnicode, &menuBackUnicode, NULL);
36+
BackMenuItem menuBackUnicode(&minfoUnicode, &menuUnicodeChoice, INFO_LOCATION_PGM);
37+
SubMenuItem menuUnicode(&minfoUnicode, &menuBackUnicode, NULL, INFO_LOCATION_PGM);
3838
const AnyMenuInfo minfoDialogs = { "Dialogs", 18, 0xffff, 0, onPresentDialog };
39-
ActionMenuItem menuDialogs(&minfoDialogs, &menuUnicode);
39+
ActionMenuItem menuDialogs(&minfoDialogs, &menuUnicode, INFO_LOCATION_PGM);
4040
const BooleanMenuInfo minfoSamplesBoolCheck = { "Bool Check", 22, 0xffff, 1, NO_CALLBACK, NAMING_CHECKBOX };
41-
BooleanMenuItem menuSamplesBoolCheck(&minfoSamplesBoolCheck, false, NULL);
41+
BooleanMenuItem menuSamplesBoolCheck(&minfoSamplesBoolCheck, false, NULL, INFO_LOCATION_PGM);
4242
RENDERING_CALLBACK_NAME_INVOKE(fnSamplesLgePosRtCall, largeNumItemRenderFn, "LgePos", -1, NO_CALLBACK)
4343
EditableLargeNumberMenuItem menuSamplesLgePos(fnSamplesLgePosRtCall, LargeFixedNumber(7, 0, 12456U, 0U, false), 17, false, &menuSamplesBoolCheck);
4444
RENDERING_CALLBACK_NAME_INVOKE(fnSamplesRGBRtCall, rgbAlphaItemRenderFn, "RGB", -1, NO_CALLBACK)
@@ -48,45 +48,43 @@ TimeFormattedMenuItem menuSamplesTime(fnSamplesTimeRtCall, TimeStorage(0, 0, 0,
4848
RENDERING_CALLBACK_NAME_INVOKE(fnSamplesTextRtCall, textItemRenderFn, "Text", -1, NO_CALLBACK)
4949
TextMenuItem menuSamplesText(fnSamplesTextRtCall, "", 14, 10, &menuSamplesTime);
5050
const AnalogMenuInfo minfoBeltSpeed = { "Belt Speed", 13, 0xffff, 200, NO_CALLBACK, 0, 100, "mS" };
51-
AnalogMenuItem menuBeltSpeed(&minfoBeltSpeed, 200, &menuSamplesText);
51+
AnalogMenuItem menuBeltSpeed(&minfoBeltSpeed, 200, &menuSamplesText, INFO_LOCATION_PGM);
5252
const char enumStrBeltStatus_0[] = "Running";
5353
const char enumStrBeltStatus_1[] = "Warm Up";
5454
const char enumStrBeltStatus_2[] = "Stopped";
5555
const char* const enumStrBeltStatus[] = { enumStrBeltStatus_0, enumStrBeltStatus_1, enumStrBeltStatus_2 };
5656
const EnumMenuInfo minfoBeltStatus = { "Belt Status", 12, 0xffff, 2, NO_CALLBACK, enumStrBeltStatus };
57-
EnumMenuItem menuBeltStatus(&minfoBeltStatus, 1, &menuBeltSpeed);
58-
RENDERING_CALLBACK_NAME_INVOKE(fnSamplesRtCall, backSubItemRenderFn, "Samples", -1, NO_CALLBACK)
57+
EnumMenuItem menuBeltStatus(&minfoBeltStatus, 1, &menuBeltSpeed, INFO_LOCATION_PGM);
5958
const SubMenuInfo minfoSamples = { "Samples", 11, 0xffff, 0, NO_CALLBACK };
60-
BackMenuItem menuBackSamples(fnSamplesRtCall, &menuBeltStatus);
61-
SubMenuItem menuSamples(&minfoSamples, &menuBackSamples, &menuDialogs);
59+
BackMenuItem menuBackSamples(&minfoSamples, &menuBeltStatus, INFO_LOCATION_PGM);
60+
SubMenuItem menuSamples(&minfoSamples, &menuBackSamples, &menuDialogs, INFO_LOCATION_PGM);
6261
const BooleanMenuInfo minfoConnectivityEnableUSB = { "Enable USB", 10, 8, 1, NO_CALLBACK, NAMING_TRUE_FALSE };
63-
BooleanMenuItem menuConnectivityEnableUSB(&minfoConnectivityEnableUSB, false, NULL);
64-
RENDERING_CALLBACK_NAME_INVOKE(fnConnectivityRtCall, backSubItemRenderFn, "Connectivity", -1, NO_CALLBACK)
62+
BooleanMenuItem menuConnectivityEnableUSB(&minfoConnectivityEnableUSB, false, NULL, INFO_LOCATION_PGM);
6563
const SubMenuInfo minfoConnectivity = { "Connectivity", 9, 0xffff, 0, NO_CALLBACK };
66-
BackMenuItem menuBackConnectivity(fnConnectivityRtCall, &menuConnectivityEnableUSB);
67-
SubMenuItem menuConnectivity(&minfoConnectivity, &menuBackConnectivity, &menuSamples);
64+
BackMenuItem menuBackConnectivity(&minfoConnectivity, &menuConnectivityEnableUSB, INFO_LOCATION_PGM);
65+
SubMenuItem menuConnectivity(&minfoConnectivity, &menuBackConnectivity, &menuSamples, INFO_LOCATION_PGM);
6866
RENDERING_CALLBACK_NAME_INVOKE(fnSettingsRunDurationRtCall, timeItemRenderFn, "Run duration", 4, NO_CALLBACK)
6967
TimeFormattedMenuItem menuSettingsRunDuration(fnSettingsRunDurationRtCall, TimeStorage(0, 0, 0, 0), 8, (MultiEditWireType)6, NULL);
7068
const AnalogMenuInfo minfoSettingsTargetSpeed = { "Target speed", 7, 2, 200, onTargetChanged, 0, 100, "mS" };
71-
AnalogMenuItem menuSettingsTargetSpeed(&minfoSettingsTargetSpeed, 0, &menuSettingsRunDuration);
72-
RENDERING_CALLBACK_NAME_INVOKE(fnSettingsRtCall, backSubItemRenderFn, "Settings", -1, NO_CALLBACK)
69+
AnalogMenuItem menuSettingsTargetSpeed(&minfoSettingsTargetSpeed, 0, &menuSettingsRunDuration, INFO_LOCATION_PGM);
7370
const SubMenuInfo minfoSettings = { "Settings", 5, 0xffff, 0, NO_CALLBACK };
74-
BackMenuItem menuBackSettings(fnSettingsRtCall, &menuSettingsTargetSpeed);
75-
SubMenuItem menuSettings(&minfoSettings, &menuBackSettings, &menuConnectivity);
71+
BackMenuItem menuBackSettings(&minfoSettings, &menuSettingsTargetSpeed, INFO_LOCATION_PGM);
72+
SubMenuItem menuSettings(&minfoSettings, &menuBackSettings, &menuConnectivity, INFO_LOCATION_PGM);
7673
const AnalogMenuInfo minfoConsumption = { "Consumption", 4, 0xffff, 4000, NO_CALLBACK, 0, 1, "W" };
77-
AnalogMenuItem menuConsumption(&minfoConsumption, 200, &menuSettings);
74+
AnalogMenuItem menuConsumption(&minfoConsumption, 200, &menuSettings, INFO_LOCATION_PGM);
7875
const AnalogMenuInfo minfoACLine = { "AC Line", 3, 0xffff, 2600, NO_CALLBACK, 0, 10, "V" };
79-
AnalogMenuItem menuACLine(&minfoACLine, 2450, &menuConsumption);
76+
AnalogMenuItem menuACLine(&minfoACLine, 2450, &menuConsumption, INFO_LOCATION_PGM);
8077
const BooleanMenuInfo minfoPower = { "Power", 6, 0xffff, 1, NO_CALLBACK, NAMING_ON_OFF };
81-
BooleanMenuItem menuPower(&minfoPower, true, &menuACLine);
78+
BooleanMenuItem menuPower(&minfoPower, true, &menuACLine, INFO_LOCATION_PGM);
8279

8380
void setupMenu() {
8481
// First we set up eeprom and authentication (if needed).
82+
setSizeBasedEEPROMStorageEnabled(false);
8583
glBspRom.initialise(0);
8684
menuMgr.setEepromRef(&glBspRom);
8785
// Now add any readonly, non-remote and visible flags.
88-
menuBeltSpeed.setReadOnly(true);
8986
menuBeltStatus.setReadOnly(true);
87+
menuBeltSpeed.setReadOnly(true);
9088

9189
// Code generated by plugins.
9290
renderer.setUpdatesPerSecond(10);

examples/mbed/stm32f429FrameBuffer/stm32f429FrameBuffer_menu.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
#include "BspUserSettings.h"
1919
#include "tcMenuStChromaArt.h"
2020
#include <graphics/MenuTouchScreenEncoder.h>
21+
#include <extras/DrawableTouchCalibrator.h>
2122
#include <RuntimeMenuItem.h>
2223
#include <EditableLargeNumberMenuItem.h>
2324
#include <ScrollChoiceMenuItem.h>
2425
#include <IoAbstraction.h>
26+
#include <EepromItemStorage.h>
2527
#include <mbed/HalStm32EepromAbstraction.h>
2628

2729
// variables we declare that you may need to access
@@ -30,6 +32,7 @@ extern StChromaArtDrawable Drawable;
3032
extern GraphicsDeviceRenderer renderer;
3133
extern StBspTouchInterrogator touchInterrogator;
3234
extern MenuTouchScreenManager touchScreen;
35+
extern tcextras::IoaTouchScreenCalibrator touchCalibrator;
3336
extern const UnicodeFont OpenSansCyrillicLatin18[];
3437
extern const GFXfont RobotoMedium24;
3538

examples/mbed/stm32f429FrameBuffer/tcMenuStChromaArt.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ void StChromaArtDrawable::drawBox(const Coord &where, const Coord &size, bool fi
8383
}
8484

8585
void StChromaArtDrawable::drawCircle(const Coord &where, int radius, bool filled) {
86+
// make sure the circle is within bounds, otherwise it crashes BSP.
87+
if(where.x < radius || where.y < radius || where.x + radius > BSP_LCD_GetXSize() || where.y + radius > BSP_LCD_GetYSize()) return;
88+
8689
BSP_LCD_SetTextColor(drawColor);
8790
if(filled) {
8891
BSP_LCD_FillCircle(where.x, where.y, radius);

examples/mbed/stm32f429FrameBuffer/tcmenu_main.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@ void setup() {
1717

1818
setupMenu();
1919

20+
/**
21+
* The function you provide is called when the touch calibration starts and ends. The parameter is false at start
22+
* and true at the end. At the start you should remove any rotations so that the screen and touch are in alignment
23+
* at their defaults. The UI will then present in the native format, and record the ranges, then once dismissed the
24+
* function is called again, here you should reapply any required settings and if need be to a commit on the EEPROM.
25+
*/
26+
touchCalibrator.initCalibration([](bool finished) {
27+
serlogF2(SER_DEBUG, "Calibration FN done=", finished);
28+
if(finished) {
29+
reinterpret_cast<HalStm32EepromAbstraction*>(menuMgr.getEepromAbstraction())->commit();
30+
}
31+
}, true);
32+
2033
taskManager.scheduleFixedRate(100, [] {
2134
menuACLine.setCurrentValue(2350 + (rand() % 100));
2235
menuConsumption.setCurrentValue(1900 + (rand() % 200));

src/BaseRenderers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ void BaseMenuRenderer::countdownToDefaulting() {
130130
}
131131

132132
void BaseMenuRenderer::takeOverDisplay(RendererCallbackFn displayFn) {
133-
if(displayFn == nullptr && customDrawing != nullptr) return;
133+
if(displayFn == nullptr && customDrawing == nullptr) return;
134134
// when we set this, we are stopping tcMenu rendering and letting this take over
135135
renderFnPressType = RPRESS_NONE;
136136
displayTakenMode = displayFn ? TAKEN_OVER_FN : START_CUSTOM_DRAW;

0 commit comments

Comments
 (0)