Skip to content

Commit e44e416

Browse files
author
dave
committed
Interim update of the examples
1 parent abc82e6 commit e44e416

File tree

12 files changed

+412
-241
lines changed

12 files changed

+412
-241
lines changed

examples/esp/esp32SimHub/esp32SimHub.emf

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -360,15 +360,20 @@
360360
"applicationName": "SimHub Link",
361361
"lastProperties": [
362362
{
363-
"name": "DISPLAY_VARIABLE",
364-
"latestValue": "gfx",
363+
"name": "DISPLAY_SEPARATOR_DISP",
364+
"latestValue": "",
365365
"subsystem": "DISPLAY"
366366
},
367367
{
368368
"name": "DISPLAY_TYPE",
369369
"latestValue": "Adafruit_ILI9341",
370370
"subsystem": "DISPLAY"
371371
},
372+
{
373+
"name": "DISPLAY_VARIABLE",
374+
"latestValue": "gfx",
375+
"subsystem": "DISPLAY"
376+
},
372377
{
373378
"name": "DISPLAY_WIDTH",
374379
"latestValue": "320",
@@ -379,6 +384,11 @@
379384
"latestValue": "240",
380385
"subsystem": "DISPLAY"
381386
},
387+
{
388+
"name": "PINS_SEPARATOR_DISP",
389+
"latestValue": "",
390+
"subsystem": "DISPLAY"
391+
},
382392
{
383393
"name": "DISPLAY_RESET_PIN",
384394
"latestValue": "16",
@@ -405,25 +415,35 @@
405415
"subsystem": "DISPLAY"
406416
},
407417
{
408-
"name": "ST7735_TAB_TYPE",
409-
"latestValue": "INITR_BLACKTAB",
418+
"name": "OTHER_SEPARATOR_DISP",
419+
"latestValue": "",
410420
"subsystem": "DISPLAY"
411421
},
412422
{
413-
"name": "DISPLAY_ROTATION",
414-
"latestValue": "1",
423+
"name": "ST7735_TAB_TYPE",
424+
"latestValue": "INITR_BLACKTAB",
415425
"subsystem": "DISPLAY"
416426
},
417427
{
418428
"name": "UPDATES_PER_SEC",
419429
"latestValue": "5",
420430
"subsystem": "DISPLAY"
421431
},
432+
{
433+
"name": "DISPLAY_ROTATION",
434+
"latestValue": "1",
435+
"subsystem": "DISPLAY"
436+
},
422437
{
423438
"name": "DISPLAY_BUFFER_SIZE",
424439
"latestValue": "40",
425440
"subsystem": "DISPLAY"
426441
},
442+
{
443+
"name": "DISPLAY_CUSTOM_SPI_NAME",
444+
"latestValue": "SPI",
445+
"subsystem": "DISPLAY"
446+
},
427447
{
428448
"name": "SWITCH_THRESHOLD",
429449
"latestValue": "800",
@@ -533,8 +553,7 @@
533553
"menuDefinitions": []
534554
},
535555
"packageNamespace": "",
536-
"appIsModular": false,
537-
"listOfEmbeddedForms": []
556+
"appIsModular": false
538557
},
539558
"stringLists": []
540559
}

examples/esp/esp32SimHub/esp32SimHub_menu.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use elsewhere.
99
*/
1010

11-
// Generated for Arduino ESP32 by TcMenu 4.3.1 on 2024-09-28T16:58:40.173767400Z.
11+
// Generated for Arduino ESP32 by TcMenu 4.5.0 on 2026-01-17T21:26:26.287434Z.
1212

1313
#include <tcMenu.h>
1414
#include "esp32SimHub_menu.h"
@@ -20,7 +20,7 @@
2020
const PROGMEM ConnectorLocalInfo applicationInfo = { "SimHub Link", "4db9fbfe-9fab-4759-b8ff-3e0c6700f475" };
2121
TcMenuRemoteServer remoteServer(applicationInfo);
2222

23-
Adafruit_ILI9341 gfx(22, 17, 16);
23+
Adafruit_ILI9341 gfx(&SPI, 22, 17, 16);
2424
AdafruitDrawable gfxDrawable(&gfx, 40);
2525
GraphicsDeviceRenderer renderer(30, applicationInfo.name, &gfxDrawable);
2626
ESP32TouchKeysAbstraction esp32Touch(800, TOUCH_HVOLT_2V7, TOUCH_LVOLT_0V5, TOUCH_HVOLT_ATTEN_1V);

examples/esp/esp32SimHub/esp32SimHub_menu.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
extern const PROGMEM ConnectorLocalInfo applicationInfo;
2828
extern TcMenuRemoteServer remoteServer;
2929
extern Adafruit_ILI9341 gfx;
30-
extern AdafruitDrawable gfxDrawable;
3130
extern GraphicsDeviceRenderer renderer;
3231
extern ESP32TouchKeysAbstraction esp32Touch;
3332
extern const UnicodeFont OpenSansCyrillicLatin14[];

examples/esp/esp32SimHub/tcMenuAdaFruitGfx.cpp

Lines changed: 55 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@
1919

2020
using namespace tcgfx;
2121

22-
23-
#if DISPLAY_HAS_MEMBUFFER == true
24-
#define refreshDisplayIfNeeded(gr, needUpd) {if(needUpd) reinterpret_cast<Adafruit_ILI9341*>(gr)->display();}
25-
#else
26-
#define refreshDisplayIfNeeded(g, n)
27-
#endif
28-
2922
#ifndef COOKIE_CUT_MEMBUFFER_SIZE
3023
#ifdef __AVR__
3124
#define COOKIE_CUT_MEMBUFFER_SIZE 16
@@ -37,9 +30,10 @@ using namespace tcgfx;
3730
uint16_t memBuffer[COOKIE_CUT_MEMBUFFER_SIZE];
3831

3932
void AdafruitDrawable::transaction(bool isStarting, bool redrawNeeded) {
40-
if(!isStarting) refreshDisplayIfNeeded(graphics, redrawNeeded);
33+
4134
}
4235

36+
4337
void AdafruitDrawable::internalDrawText(const Coord &where, const void *font, int mag, const char *sz) {
4438
graphics->setTextWrap(false);
4539
int baseline=0;
@@ -50,6 +44,59 @@ void AdafruitDrawable::internalDrawText(const Coord &where, const void *font, in
5044
graphics->print(sz);
5145
}
5246

47+
Coord AdafruitDrawable::internalTextExtents(const void *f, int mag, const char *text, int *baseline) {
48+
if(mag == 0) mag = 1; // never allow 0 magnification
49+
50+
graphics->setFont(static_cast<const GFXfont *>(f));
51+
graphics->setTextSize(mag);
52+
auto* font = (GFXfont *) f;
53+
int16_t x1, y1;
54+
uint16_t w, h;
55+
graphics->getTextBounds((char*)text, 3, font?30:2, &x1, &y1, &w, &h);
56+
57+
if(font == nullptr) {
58+
// for the default font, the starting offset is 0, and we calculate the height.
59+
if(baseline) *baseline = 0;
60+
return Coord(w, h);
61+
}
62+
else {
63+
computeBaselineIfNeeded(font);
64+
if(baseline) *baseline = (computedBaseline * mag);
65+
return Coord(int(w), (computedHeight * mag));
66+
}
67+
}
68+
69+
void AdafruitDrawable::computeBaselineIfNeeded(const GFXfont* font) {
70+
// we cache the last baseline, if the font is unchanged, don't calculate again
71+
if(computedFont == font && computedBaseline > 0) return;
72+
73+
// we need to work out the biggest glyph and maximum extent beyond the baseline, we use 4 chars 'Agj(' for this
74+
const char sz[] = "Agj(";
75+
int height = 0;
76+
int bl = 0;
77+
const char* current = sz;
78+
auto fontLast = pgm_read_word(&font->last);
79+
auto fontFirst = pgm_read_word(&font->first);
80+
while(*current && (*current < fontLast)) {
81+
size_t glIdx = *current - fontFirst;
82+
auto allGlyphs = (GFXglyph*)pgm_read_ptr(&font->glyph);
83+
int glyphHeight = int(pgm_read_byte(&allGlyphs[glIdx].height));
84+
if (glyphHeight > height) height = glyphHeight;
85+
auto yOffset = int8_t(pgm_read_byte(&allGlyphs[glIdx].yOffset));
86+
bl += glyphHeight + yOffset;
87+
current++;
88+
}
89+
computedFont = font;
90+
computedBaseline = bl / 4;
91+
computedHeight = height;
92+
}
93+
94+
UnicodeFontHandler *AdafruitDrawable::createFontHandler() {
95+
return new UnicodeFontHandler(newAdafruitTextPipeline(graphics), ENCMODE_UTF8);
96+
}
97+
98+
99+
53100
void AdafruitDrawable::drawBitmap(const Coord &where, const DrawableIcon *icon, bool selected) {
54101
if(icon->getIconType() == DrawableIcon::ICON_XBITMAP) {
55102
graphics->fillRect(where.x, where.y, icon->getDimensions().x, icon->getDimensions().y, backgroundColor);
@@ -142,61 +189,10 @@ void AdafruitDrawable::drawPolygon(const Coord points[], int numPoints, bool fil
142189
}
143190
}
144191

145-
void AdafruitDrawable::computeBaselineIfNeeded(const GFXfont* font) {
146-
// we cache the last baseline, if the font is unchanged, don't calculate again
147-
if(computedFont == font && computedBaseline > 0) return;
148-
149-
// we need to work out the biggest glyph and maximum extent beyond the baseline, we use 4 chars 'Agj(' for this
150-
const char sz[] = "Agj(";
151-
int height = 0;
152-
int bl = 0;
153-
const char* current = sz;
154-
auto fontLast = pgm_read_word(&font->last);
155-
auto fontFirst = pgm_read_word(&font->first);
156-
while(*current && (*current < fontLast)) {
157-
size_t glIdx = *current - fontFirst;
158-
auto allGlyphs = (GFXglyph*)pgm_read_ptr(&font->glyph);
159-
int glyphHeight = int(pgm_read_byte(&allGlyphs[glIdx].height));
160-
if (glyphHeight > height) height = glyphHeight;
161-
auto yOffset = int8_t(pgm_read_byte(&allGlyphs[glIdx].yOffset));
162-
bl += glyphHeight + yOffset;
163-
current++;
164-
}
165-
computedFont = font;
166-
computedBaseline = bl / 4;
167-
computedHeight = height;
168-
}
169-
170-
Coord AdafruitDrawable::internalTextExtents(const void *f, int mag, const char *text, int *baseline) {
171-
if(mag == 0) mag = 1; // never allow 0 magnification
172-
173-
graphics->setFont(static_cast<const GFXfont *>(f));
174-
graphics->setTextSize(mag);
175-
auto* font = (GFXfont *) f;
176-
int16_t x1, y1;
177-
uint16_t w, h;
178-
graphics->getTextBounds((char*)text, 3, font?30:2, &x1, &y1, &w, &h);
179-
180-
if(font == nullptr) {
181-
// for the default font, the starting offset is 0, and we calculate the height.
182-
if(baseline) *baseline = 0;
183-
return Coord(w, h);
184-
}
185-
else {
186-
computeBaselineIfNeeded(font);
187-
if(baseline) *baseline = (computedBaseline * mag);
188-
return Coord(int(w), (computedHeight * mag));
189-
}
190-
}
191-
192192
void AdafruitDrawable::drawPixel(uint16_t x, uint16_t y) {
193193
graphics->writePixel(x, y, drawColor);
194194
}
195195

196-
UnicodeFontHandler *AdafruitDrawable::createFontHandler() {
197-
return new UnicodeFontHandler(newAdafruitTextPipeline(graphics), ENCMODE_UTF8);
198-
}
199-
200196
//
201197
// helper functions
202198
//

examples/esp/esp32SimHub/tcMenuAdaFruitGfx.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
#define DISPLAY_HAS_MEMBUFFER false
3535

36+
3637
using namespace tcgfx;
3738

3839
// some colour displays don't create this value
@@ -159,6 +160,7 @@ class AdafruitDrawable : public DeviceDrawable {
159160
const GFXfont* computedFont = nullptr;
160161
int16_t computedBaseline = 0;
161162
int16_t computedHeight = 0;
163+
162164
protected:
163165
int spriteHeight = 0;
164166
public:

0 commit comments

Comments
 (0)