Skip to content
C

feat: add Pocket dashboard theme

YU CHIH CHANG6a3b9f5f7462
diff --git a/docs/THEME_DEVELOPMENT.md b/docs/THEME_DEVELOPMENT.md
index 37e3424..7f9425a 100644
--- a/docs/THEME_DEVELOPMENT.md
+++ b/docs/THEME_DEVELOPMENT.md
@@ -21,6 +21,7 @@ The included themes are:
| `Retro` | 2 | `drawRetroDashboard()` | Warm paper-and-ink instrument UI |
| `Radar` | 3 | `drawRadarDashboard()` | Circular tachometer-focused dark UI |
| `Mono` | 4 | `drawMonoDashboard()` | Monochrome retro-digital instrument UI |
+| `Pocket` | 5 | `drawPocketDashboard()` | Four-tone handheld pixel instrument UI |
Persisted values are part of the device settings format. Never reorder or reuse an existing enum value.
diff --git a/src/SHCustomProtocol.h b/src/SHCustomProtocol.h
index 816c7ef..3fa86a6 100644
--- a/src/SHCustomProtocol.h
+++ b/src/SHCustomProtocol.h
@@ -133,6 +133,7 @@ enum class DashboardTheme : uint8_t
Retro = 2,
Radar = 3,
Mono = 4,
+ Pocket = 5,
};
struct DashboardThemeDescriptor
@@ -147,6 +148,7 @@ static constexpr DashboardThemeDescriptor DASHBOARD_THEMES[] = {
{DashboardTheme::Retro, "RETRO"},
{DashboardTheme::Radar, "RADAR"},
{DashboardTheme::Mono, "MONO"},
+ {DashboardTheme::Pocket, "POCKET"},
};
static constexpr size_t DASHBOARD_THEME_COUNT =
sizeof(DASHBOARD_THEMES) / sizeof(DASHBOARD_THEMES[0]);
@@ -440,7 +442,7 @@ private:
? static_cast<DashboardTheme>(storedTheme)
: DashboardTheme::GT3;
-#if GT7_DASHBOARD_THEME_PREVIEW >= 0 && GT7_DASHBOARD_THEME_PREVIEW <= 4
+#if GT7_DASHBOARD_THEME_PREVIEW >= 0 && GT7_DASHBOARD_THEME_PREVIEW <= 5
activeDashboardTheme =
static_cast<DashboardTheme>(GT7_DASHBOARD_THEME_PREVIEW);
#endif
@@ -1128,6 +1130,9 @@ public:
case DashboardTheme::Mono:
drawMonoDashboard(state, forceUpdate);
break;
+ case DashboardTheme::Pocket:
+ drawPocketDashboard(state, forceUpdate);
+ break;
case DashboardTheme::GT3:
default:
#if GT7_DASHBOARD_LEGACY_UI
@@ -1153,6 +1158,13 @@ public:
fromB + (toB - fromB) * amount / 255);
}
+ void releaseSpriteAfterThemePreview(LGFX_Sprite &sprite, bool &created)
+ {
+ if (settingsScreen != SettingsScreen::ThemeSelection || !created) return;
+ sprite.deleteSprite();
+ created = false;
+ }
+
void drawRetroTextValue(int32_t x, int32_t y, int32_t width, int32_t height,
const String &value, const String &id, uint16_t color, uint8_t font,
textdatum_t datum, bool forceUpdate, float scaleX = 1.0f,
@@ -1202,6 +1214,7 @@ public:
sprite.setTextSize(1.0f);
sprite.pushSprite(x, y);
prevData[id] = cacheState;
+ releaseSpriteAfterThemePreview(sprite, spriteCreated);
}
void drawRetroRpm(const DashboardState &state, bool forceUpdate)
@@ -1327,7 +1340,29 @@ public:
pedalSprite.setColorDepth(16);
spriteCreated = pedalSprite.createSprite(93, 33) != nullptr;
}
- if (!spriteCreated) return;
+ if (!spriteCreated)
+ {
+ // Keep the complete pedal panel visible if heap fragmentation after a
+ // theme switch temporarily prevents allocating the sprite.
+ tft.fillRect(143, 204, 93, 33, paper);
+ tft.setTextColor(ink, paper);
+ tft.setTextDatum(TL_DATUM);
+ tft.drawString("B", 151, 208, 1);
+ tft.drawString("T", 151, 221, 1);
+ const int values[2][2] = {
+ {brakeInput, brakeApplied}, {throttleInput, throttleApplied}};
+ for (int row = 0; row < 2; ++row)
+ {
+ const int y = 211 + row * 13;
+ tft.drawRect(164, y, 68, 7, faint);
+ const int inputW = 66 * values[row][0] / 100;
+ const int appliedW = 66 * values[row][1] / 100;
+ if (inputW > 0) tft.fillRect(165, y + 1, inputW, 5, ink);
+ if (appliedW > 0) tft.fillRect(165, y + 1, appliedW, 5, applied);
+ }
+ prevData["retroPedals"] = value;
+ return;
+ }
pedalSprite.fillSprite(paper);
pedalSprite.setTextColor(ink, paper);
pedalSprite.setTextDatum(TL_DATUM);
@@ -1349,6 +1384,7 @@ public:
}
pedalSprite.pushSprite(143, 204);
prevData["retroPedals"] = value;
+ releaseSpriteAfterThemePreview(pedalSprite, spriteCreated);
}
void drawRetroDashboard(const DashboardState &state, bool forceUpdate)
@@ -1394,7 +1430,7 @@ public:
tft.drawCentreString("GEAR", 141, 59, 2);
tft.drawString("BEST", 192, 57, 1);
tft.drawString("LAST", 192, 92, 1);
- tft.drawString("CURRENT", 192, 127, 1);
+ tft.drawString("CURRENT", 192, 124, 1);
tft.drawString("FUEL", 8, 166, 1);
tft.drawString("REM", 86, 166, 1);
tft.drawString("LAP", 163, 166, 1);
@@ -1417,7 +1453,7 @@ public:
drawRetroTextValue(190, 103, 124, 17, state.lastLapTime, "retroLast", ink,
2, MR_DATUM, forceUpdate);
const uint16_t currentColor = state.lapInvalidated == "True" ? red : ink;
- drawRetroTextValueBuffered(190, 133, 124, 14, state.currentLapTime,
+ drawRetroTextValueBuffered(190, 134, 124, 14, state.currentLapTime,
"retroCurrent", currentColor, 2, MR_DATUM, forceUpdate,
currentSprite, currentSpriteCreated, 0.9f, 0.82f);
@@ -1539,6 +1575,7 @@ public:
sprite.setTextSize(1.0f);
sprite.pushSprite(x, y);
prevData[id] = cacheState;
+ releaseSpriteAfterThemePreview(sprite, spriteCreated);
}
void drawRadarPedals(const DashboardState &state, bool forceUpdate)
@@ -1582,6 +1619,7 @@ public:
}
pedalSprite.pushSprite(258, 171);
prevData["radarPedals"] = cacheState;
+ releaseSpriteAfterThemePreview(pedalSprite, spriteCreated);
}
void drawRadarTyres(const DashboardState &state, bool forceUpdate,
@@ -1624,6 +1662,7 @@ public:
sprite.setTextSize(1.0f);
sprite.pushSprite(226, 218);
prevData["radarTyres"] = cacheState;
+ releaseSpriteAfterThemePreview(sprite, spriteCreated);
}
void drawRadarStatusDot(int32_t x, int32_t y, bool active,
@@ -1938,6 +1977,7 @@ public:
sprite.setTextSize(1.0f);
sprite.pushSprite(x, y);
prevData[id] = cacheState;
+ releaseSpriteAfterThemePreview(sprite, spriteCreated);
}
void drawMonoSpeed(const String &speed, bool forceUpdate)
@@ -1963,6 +2003,7 @@ public:
sprite.drawString("km/h", 54, 39, 1);
sprite.pushSprite(106, 137);
prevData["monoSpeed"] = speed;
+ releaseSpriteAfterThemePreview(sprite, spriteCreated);
}
void drawMonoRpm(const DashboardState &state, bool forceUpdate)
@@ -2111,6 +2152,7 @@ public:
}
sprite.pushSprite(180, 218);
prevData["monoPedals"] = cacheState;
+ releaseSpriteAfterThemePreview(sprite, spriteCreated);
}
void drawMonoTyres(const DashboardState &state, bool forceUpdate,
@@ -2145,6 +2187,7 @@ public:
}
sprite.pushSprite(2, 218);
prevData["monoTyres"] = cacheState;
+ releaseSpriteAfterThemePreview(sprite, spriteCreated);
}
void drawMonoStatusDot(int centerX, int centerY, bool active,
@@ -2268,6 +2311,456 @@ public:
drawMonoPedals(state, forceUpdate);
}
+ static uint8_t pocketGlyphRow(char c, int row)
+ {
+ static constexpr uint8_t DIGITS[10][7] = {
+ {14, 17, 19, 21, 25, 17, 14}, {4, 12, 4, 4, 4, 4, 14},
+ {14, 17, 1, 2, 4, 8, 31}, {30, 1, 1, 14, 1, 1, 30},
+ {2, 6, 10, 18, 31, 2, 2}, {31, 16, 16, 30, 1, 1, 30},
+ {14, 16, 16, 30, 17, 17, 14}, {31, 1, 2, 4, 8, 8, 8},
+ {14, 17, 17, 14, 17, 17, 14}, {14, 17, 17, 15, 1, 1, 14}};
+ if (c >= '0' && c <= '9') return DIGITS[c - '0'][row];
+ static constexpr uint8_t N[7] = {17, 25, 25, 21, 19, 19, 17};
+ static constexpr uint8_t R[7] = {30, 17, 17, 30, 20, 18, 17};
+ static constexpr uint8_t DASH[7] = {0, 0, 0, 14, 0, 0, 0};
+ if (c == 'N') return N[row];
+ if (c == 'R') return R[row];
+ if (c == '-') return DASH[row];
+ return 0;
+ }
+
+ void drawPocketPixelText(LGFX_Sprite &sprite, const String &text,
+ int centerX, int y, int scale, uint16_t color)
+ {
+ const int glyphW = 5 * scale;
+ const int pitch = 6 * scale;
+ const int startX = centerX - (text.length() * pitch - scale) / 2;
+ for (size_t i = 0; i < text.length(); ++i)
+ {
+ for (int row = 0; row < 7; ++row)
+ {
+ const uint8_t bits = pocketGlyphRow(text[i], row);
+ for (int col = 0; col < 5; ++col)
+ if (bits & (1 << (4 - col)))
+ sprite.fillRect(startX + i * pitch + col * scale,
+ y + row * scale, scale, scale, color);
+ }
+ }
+ }
+
+ void drawPocketGearSpeed(const DashboardState &state, bool forceUpdate)
+ {
+ const String cacheState = state.gear + ":" + state.speed;
+ if (!forceUpdate && prevData["pocketGearSpeed"] == cacheState) return;
+ static LGFX_Sprite sprite(&tft);
+ static bool created = false;
+ if (!created)
+ {
+ sprite.setColorDepth(16);
+ created = sprite.createSprite(158, 105) != nullptr;
+ }
+ if (!created) return;
+ const uint16_t pale = tft.color565(188, 205, 124);
+ const uint16_t darkest = tft.color565(23, 43, 18);
+ sprite.fillSprite(pale);
+ drawPocketPixelText(sprite, state.gear, 79, 4, 8, darkest);
+ drawPocketPixelText(sprite, state.speed, 79, 72, 4, darkest);
+ sprite.setTextColor(darkest, pale);
+ sprite.setTextDatum(ML_DATUM);
+ sprite.setTextSize(1.25f, 1.20f);
+ sprite.drawString("KM/H", 120, 94, 1);
+ sprite.setTextSize(1.0f);
+ sprite.pushSprite(7, 50);
+ prevData["pocketGearSpeed"] = cacheState;
+ releaseSpriteAfterThemePreview(sprite, created);
+ }
+
+ void drawPocketValue(int x, int y, int w, int h, const String &value,
+ const String &id, uint16_t color, uint16_t background, uint8_t font,
+ float scaleX, float scaleY, bool forceUpdate,
+ textdatum_t datum = MC_DATUM)
+ {
+ const String cacheState = value + ":" + String(color);
+ if (!forceUpdate && prevData[id] == cacheState) return;
+ tft.fillRect(x, y, w, h, background);
+ tft.setTextColor(color, background);
+ tft.setTextDatum(datum);
+ tft.setTextSize(scaleX, scaleY);
+ const int textX = datum == MR_DATUM ? x + w - 2
+ : (datum == ML_DATUM ? x + 2 : x + w / 2);
+ tft.drawString(value, textX, y + h / 2, font);
+ tft.setTextSize(1.0f);
+ tft.setTextDatum(TL_DATUM);
+ prevData[id] = cacheState;
+ }
+
+ void drawPocketValueBuffered(int x, int y, int w, int h,
+ const String &value, const String &id, uint16_t color,
+ uint16_t background, uint8_t font, float scaleX, float scaleY,
+ bool forceUpdate, LGFX_Sprite &sprite, bool &created)
+ {
+ const String cacheState = value + ":" + String(color);
+ if (!forceUpdate && prevData[id] == cacheState) return;
+ if (!created)
+ {
+ sprite.setColorDepth(16);
+ created = sprite.createSprite(w, h) != nullptr;
+ }
+ if (!created)
+ {
+ drawPocketValue(x, y, w, h, value, id, color, background,
+ font, scaleX, scaleY, true);
+ return;
+ }
+ sprite.fillSprite(background);
+ sprite.setTextColor(color, background);
+ sprite.setTextDatum(MC_DATUM);
+ sprite.setTextSize(scaleX, scaleY);
+ sprite.drawString(value, w / 2, h / 2, font);
+ sprite.setTextSize(1.0f);
+ sprite.pushSprite(x, y);
+ prevData[id] = cacheState;
+ releaseSpriteAfterThemePreview(sprite, created);
+ }
+
+ void drawPocketPixelFrame(int x, int y, int w, int h, uint16_t color)
+ {
+ static constexpr int T = 2;
+ static constexpr int FOLD = 6;
+ static constexpr int DEPTH = 6;
+ // Orthogonal inward folds: across, inward, back to the outer side.
+ tft.fillRect(x + FOLD, y, w - FOLD * 2, T, color);
+ tft.fillRect(x + FOLD - T, y, T, DEPTH, color);
+ tft.fillRect(x, y + DEPTH - T, FOLD, T, color);
+ tft.fillRect(x + w - FOLD, y, T, DEPTH, color);
+ tft.fillRect(x + w - FOLD, y + DEPTH - T, FOLD, T, color);
+
+ tft.fillRect(x, y + DEPTH - T, T, h - (DEPTH - T) * 2, color);
+ tft.fillRect(x + w - T, y + DEPTH - T, T,
+ h - (DEPTH - T) * 2, color);
+
+ tft.fillRect(x, y + h - DEPTH, FOLD, T, color);
+ tft.fillRect(x + FOLD - T, y + h - DEPTH, T, DEPTH, color);
+ tft.fillRect(x + FOLD, y + h - T, w - FOLD * 2, T, color);
+ tft.fillRect(x + w - FOLD, y + h - DEPTH, FOLD, T, color);
+ tft.fillRect(x + w - FOLD, y + h - DEPTH, T, DEPTH, color);
+ }
+
+ void drawPocketRpm(const DashboardState &state, bool forceUpdate)
+ {
+ static constexpr int COUNT = 14;
+ static constexpr int X = 24;
+ static constexpr int Y = 190;
+ static constexpr int PITCH = 10;
+ static int previousActive = -1;
+ static uint8_t previousPulseStep = 255;
+ const uint16_t darkest = tft.color565(23, 43, 18);
+ const uint16_t dark = tft.color565(76, 95, 47);
+ const uint16_t light = tft.color565(154, 166, 92);
+ const int active = constrain((state.rpmPercent * COUNT + 99) / 100, 0, COUNT);
+ const bool warning = (state.rpmAlertRangeValid &&
+ state.rpmPercent >= state.rpmRedLineSetting) || state.revLimitAlertActive;
+ uint8_t pulseStep = 0;
+ if (warning)
+ {
+ const float wave = 0.5f + 0.5f * cosf(TWO_PI * 3.0f * millis() / 1000.0f);
+ pulseStep = static_cast<uint8_t>(lroundf(wave * 5.0f));
+ }
+ if (!forceUpdate && active == previousActive && pulseStep == previousPulseStep)
+ return;
+ const uint16_t activeColor = warning
+ ? blendRgb565(darkest, dark, pulseStep * 35) : darkest;
+ const uint16_t pale = tft.color565(188, 205, 124);
+ // Clear only the marker lane; never touch the surrounding 2 px frame.
+ tft.fillRect(13, 182, 158, 7, pale);
+ for (int i = 0; i < COUNT; ++i)
+ {
+ const uint16_t color = i < active ? activeColor : light;
+ tft.fillRect(X + i * PITCH, Y, 8, 12, color);
+ }
+ if (state.rpmAlertRangeValid)
+ {
+ const int markerX = X + constrain(
+ state.rpmRedLineSetting * ((COUNT - 1) * PITCH) / 100,
+ 0, (COUNT - 1) * PITCH);
+ tft.fillTriangle(markerX, 188, markerX - 3, 182,
+ markerX + 3, 182, darkest);
+ }
+ previousActive = active;
+ previousPulseStep = pulseStep;
+ }
+
+ void drawPocketFuelAids(const DashboardState &state, bool forceUpdate)
+ {
+ const bool fuelChanged = forceUpdate ||
+ prevData["pocketFuel"] != state.brakeBias;
+ const bool absChanged = forceUpdate ||
+ prevData["pocketAbs"] != state.absActive;
+ const bool tcsChanged = forceUpdate ||
+ prevData["pocketTcs"] != state.tcActive;
+ if (!fuelChanged && !absChanged && !tcsChanged) return;
+ const uint16_t pale = tft.color565(188, 205, 124);
+ const uint16_t darkest = tft.color565(23, 43, 18);
+ const uint16_t dark = tft.color565(76, 95, 47);
+ const uint16_t light = tft.color565(132, 146, 80);
+ tft.setTextColor(darkest, pale);
+ tft.setTextDatum(MC_DATUM);
+ const bool validFuel = state.brakeBias != "--" && state.brakeBias.length();
+ if (fuelChanged)
+ {
+ tft.fillRect(176, 165, 44, 60, pale);
+ tft.setTextSize(1.0f);
+ tft.drawString(validFuel ? state.brakeBias + "%" : "--", 198, 174, 2);
+ // Narrower pump leaves enough visual room for the fuel percentage.
+ tft.fillRect(192, 184, 13, 21, dark);
+ tft.fillRect(195, 187, 7, 6, pale);
+ tft.fillRect(189, 205, 19, 3, dark);
+ tft.drawFastVLine(208, 189, 15, dark);
+ tft.fillRect(205, 186, 4, 4, dark);
+ tft.fillRect(209, 190, 3, 7, dark);
+ tft.drawString("FUEL", 198, 222, 1);
+ }
+
+ const bool absOn = isActiveValue(state.absActive);
+ const bool tcsOn = isActiveValue(state.tcActive);
+ // Match the RPM bar: inactive is pale, active is the solid dark tone.
+ const uint16_t absColor = absOn ? darkest : light;
+ const uint16_t tcsColor = tcsOn ? darkest : light;
+
+ if (absChanged)
+ {
+ tft.fillRect(222, 165, 44, 60, pale);
+ // Circular ABS badge: active state is solid with reversed lettering.
+ if (absOn)
+ tft.fillCircle(244, 194, 12, absColor);
+ else
+ {
+ tft.drawCircle(244, 194, 12, absColor);
+ tft.drawCircle(244, 194, 11, absColor);
+ }
+ for (int angle = 120; angle <= 240; angle += 6)
+ {
+ const float radians = angle * DEG_TO_RAD;
+ tft.fillCircle(244 + lroundf(cosf(radians) * 15.0f),
+ 194 + lroundf(sinf(radians) * 15.0f), 1, absColor);
+ }
+ for (int angle = -60; angle <= 60; angle += 6)
+ {
+ const float radians = angle * DEG_TO_RAD;
+ tft.fillCircle(244 + lroundf(cosf(radians) * 15.0f),
+ 194 + lroundf(sinf(radians) * 15.0f), 1, absColor);
+ }
+ tft.setTextColor(absOn ? pale : absColor, absOn ? absColor : pale);
+ tft.drawString("ABS", 244, 194, 1);
+ tft.setTextColor(darkest, pale);
+ tft.drawString("ABS", 244, 223, 1);
+ }
+
+ if (tcsChanged)
+ {
+ tft.fillRect(268, 165, 38, 60, pale);
+ tft.setTextColor(darkest, pale);
+ // Chunky rear-view slipping-car glyph, drawn for this 42 px status cell.
+ // Symmetrical, flat-topped trapezoid roof with an open rear window.
+ tft.fillRect(285, 181, 10, 2, tcsColor);
+ tft.fillRect(283, 183, 2, 2, tcsColor);
+ tft.fillRect(295, 183, 2, 2, tcsColor);
+ tft.fillRect(281, 185, 2, 4, tcsColor);
+ tft.fillRect(297, 185, 2, 4, tcsColor);
+
+ // Solid rear body with two square, background-colour lamps.
+ tft.fillRect(279, 189, 22, 10, tcsColor);
+ tft.fillRect(282, 191, 4, 3, pale);
+ tft.fillRect(294, 191, 4, 3, pale);
+ tft.fillRect(281, 199, 5, 3, tcsColor);
+ tft.fillRect(294, 199, 5, 3, tcsColor);
+
+ // Two separate, same-direction S-shaped skid trails with softened turns.
+ tft.drawLine(283, 202, 284, 203, tcsColor);
+ tft.drawLine(284, 203, 278, 206, tcsColor);
+ tft.drawLine(278, 206, 280, 208, tcsColor);
+ tft.drawFastHLine(280, 209, 5, tcsColor);
+ tft.drawLine(296, 202, 297, 203, tcsColor);
+ tft.drawLine(297, 203, 291, 206, tcsColor);
+ tft.drawLine(291, 206, 293, 208, tcsColor);
+ tft.drawFastHLine(293, 209, 5, tcsColor);
+ // Keep the trails readable on the physical LCD without adding corner blobs.
+ tft.drawLine(283, 203, 279, 206, tcsColor);
+ tft.drawLine(296, 203, 292, 206, tcsColor);
+ // A second row makes both trails one pixel heavier without changing shape.
+ tft.drawLine(283, 204, 279, 207, tcsColor);
+ tft.drawLine(279, 207, 280, 209, tcsColor);
+ tft.drawLine(296, 204, 292, 207, tcsColor);
+ tft.drawLine(292, 207, 293, 209, tcsColor);
+ // Third pixel of trail weight.
+ tft.drawLine(283, 205, 279, 208, tcsColor);
+ tft.drawLine(279, 208, 280, 210, tcsColor);
+ tft.drawLine(296, 205, 292, 208, tcsColor);
+ tft.drawLine(292, 208, 293, 210, tcsColor);
+ tft.drawString("TCS", 290, 223, 1);
+ }
+
+ // Three equal status columns.
+ for (int y = 167; y < 227; y += 8)
+ {
+ tft.fillRect(220, y, 2, 4, dark);
+ tft.fillRect(266, y, 2, 4, dark);
+ }
+ tft.setTextDatum(TL_DATUM);
+ // Dynamic clearing must never leave the outer folded corners incomplete.
+ drawPocketPixelFrame(10, 162, 300, 69, dark);
+ prevData["pocketFuel"] = state.brakeBias;
+ prevData["pocketAbs"] = state.absActive;
+ prevData["pocketTcs"] = state.tcActive;
+ }
+
+ void drawPocketBottom(const DashboardState &state, bool forceUpdate)
+ {
+ String tyreState;
+ for (int i = 0; i < 4; ++i)
+ tyreState += (i ? ":" : "") +
+ (isnan(state.tyreTemperatures[i]) ? String("--")
+ : String(lroundf(state.tyreTemperatures[i])));
+ const String cacheState = tyreState + ":" + state.absLevel + ":" +
+ state.absFilteredLevel + ":" + state.tcLevel + ":" + state.tcFilteredLevel;
+ if (!forceUpdate && prevData["pocketBottom"] == cacheState) return;
+ const uint16_t pale = tft.color565(188, 205, 124);
+ const uint16_t darkest = tft.color565(23, 43, 18);
+ const uint16_t dark = tft.color565(76, 95, 47);
+ static LGFX_Sprite sprite(&tft);
+ static bool created = false;
+ if (!created)
+ {
+ sprite.setColorDepth(16);
+ created = sprite.createSprite(310, 20) != nullptr;
+ }
+ if (!created)
+ {
+ // Allocation can temporarily fail after browsing several themes. Keep
+ // the panel functional and retry the buffered path on a later update.
+ tft.fillRect(5, 216, 310, 20, pale);
+ tft.setTextColor(darkest, pale);
+ tft.setTextDatum(ML_DATUM);
+ tft.drawString("TYRE", 8, 226, 1);
+ const char *fallbackLabels[] = {"FL", "FR", "RL", "RR"};
+ for (int i = 0; i < 4; ++i)
+ tft.drawString(String(fallbackLabels[i]) +
+ (isnan(state.tyreTemperatures[i]) ? String("--")
+ : String(lroundf(state.tyreTemperatures[i]))),
+ 41 + i * 31, 226, 1);
+ const int fallbackValues[] = {
+ constrain(state.absFilteredLevel.toInt(), 0, 100),
+ constrain(state.tcFilteredLevel.toInt(), 0, 100)};
+ for (int row = 0; row < 2; ++row)
+ {
+ const int y = 218 + row * 9;
+ tft.drawString(row == 0 ? "B" : "T", 179, y + 4, 1);
+ tft.drawRect(190, y, 122, 7, dark);
+ if (fallbackValues[row] > 0)
+ tft.fillRect(191, y + 1,
+ 120 * fallbackValues[row] / 100, 5, darkest);
+ }
+ prevData["pocketBottom"] = cacheState;
+ return;
+ }
+
+ sprite.fillSprite(pale);
+ sprite.setTextColor(darkest, pale);
+ sprite.setTextDatum(ML_DATUM);
+ sprite.drawString("TYRE", 3, 10, 1);
+ const char *labels[] = {"FL", "FR", "RL", "RR"};
+ for (int i = 0; i < 4; ++i)
+ {
+ const String value = String(labels[i]) +
+ (isnan(state.tyreTemperatures[i]) ? String("--")
+ : String(lroundf(state.tyreTemperatures[i])));
+ sprite.drawString(value, 36 + i * 31, 10, 1);
+ }
+ const int values[] = {constrain(state.absFilteredLevel.toInt(), 0, 100),
+ constrain(state.tcFilteredLevel.toInt(), 0, 100)};
+ for (int row = 0; row < 2; ++row)
+ {
+ const int y = 2 + row * 9;
+ sprite.drawString(row == 0 ? "B" : "T", 174, y + 4, 1);
+ sprite.drawRect(185, y, 122, 7, dark);
+ if (values[row] > 0)
+ sprite.fillRect(186, y + 1, 120 * values[row] / 100, 5, darkest);
+ }
+ sprite.pushSprite(5, 216);
+ prevData["pocketBottom"] = cacheState;
+ releaseSpriteAfterThemePreview(sprite, created);
+ }
+
+ void drawPocketDashboard(const DashboardState &state, bool forceUpdate)
+ {
+ static LGFX_Sprite currentSprite(&tft);
+ static bool currentSpriteCreated = false;
+ const uint16_t pale = tft.color565(188, 205, 124);
+ const uint16_t darkest = tft.color565(23, 43, 18);
+ const uint16_t dark = tft.color565(76, 95, 47);
+ if (forceUpdate)
+ {
+ tft.fillScreen(tft.color565(154, 166, 92));
+ tft.fillRect(5, 5, 310, 230, pale);
+ tft.setTextSize(1.0f);
+ tft.setTextColor(pale, darkest);
+ tft.setTextDatum(TL_DATUM);
+ tft.fillRect(9, 14, 31, 18, darkest);
+ // Single-pixel clipped corners keep the label chunky but less boxy.
+ tft.drawPixel(9, 14, pale);
+ tft.drawPixel(39, 14, pale);
+ tft.drawPixel(9, 31, pale);
+ tft.drawPixel(39, 31, pale);
+ tft.drawString("LAP", 15, 19, 1);
+ tft.fillRect(181, 14, 31, 18, darkest);
+ tft.drawPixel(181, 14, pale);
+ tft.drawPixel(211, 14, pale);
+ tft.drawPixel(181, 31, pale);
+ tft.drawPixel(211, 31, pale);
+ tft.drawString("POS", 187, 19, 1);
+ for (int x = 8; x < 312; x += 8) tft.fillRect(x, 39, 4, 2, dark);
+ drawPocketPixelFrame(174, 49, 136, 106, dark);
+ for (int y = 84; y < 150; y += 34)
+ for (int x = 180; x < 306; x += 8) tft.fillRect(x, y, 4, 2, dark);
+ tft.setTextColor(darkest, pale);
+ tft.setTextDatum(ML_DATUM);
+ tft.drawString("BEST", 180, 71, 1);
+ tft.drawString("LAST", 180, 105, 1);
+ tft.drawString("CUR", 180, 139, 1);
+ tft.setTextDatum(TL_DATUM);
+ drawPocketPixelFrame(10, 162, 300, 69, dark);
+ // Match the other dividers: FUEL's left edge is a dotted line.
+ for (int y = 167; y < 227; y += 8)
+ tft.fillRect(173, y, 2, 4, dark);
+ // RPM needs a slight optical correction to match the wider DELTA word.
+ tft.setTextSize(1.30f, 1.20f);
+ tft.drawString("RPM", 18, 173, 1);
+ tft.setTextSize(1.20f, 1.15f);
+ tft.setTextDatum(ML_DATUM);
+ tft.drawString("DELTA", 18, 216, 1);
+ tft.setTextSize(1.0f);
+ tft.setTextDatum(TL_DATUM);
+ }
+
+ drawPocketValue(43, 12, 90, 22, state.tyrePressureRearLeft,
+ "pocketLap", darkest, pale, 2, 1.35f, 1.18f, forceUpdate);
+ drawPocketValue(215, 13, 92, 20, state.tyrePressureFrontRight,
+ "pocketPos", darkest, pale, 2, 1.35f, 1.18f, forceUpdate);
+ drawPocketGearSpeed(state, forceUpdate);
+ drawPocketValue(210, 59, 97, 24, state.bestLapTime,
+ "pocketBest", darkest, pale, 1, 1.65f, 1.50f, forceUpdate);
+ drawPocketValue(210, 93, 97, 24, state.lastLapTime,
+ "pocketLast", darkest, pale, 1, 1.65f, 1.50f, forceUpdate);
+ drawPocketValueBuffered(210, 127, 97, 24, state.currentLapTime,
+ "pocketCurrent", state.lapInvalidated == "True" ? dark : darkest,
+ pale, 1, 1.65f, 1.50f, forceUpdate,
+ currentSprite, currentSpriteCreated);
+ drawPocketRpm(state, forceUpdate);
+ drawPocketValue(66, 204, 102, 24, state.sessionBestLiveDeltaSeconds,
+ "pocketDelta", darkest, pale, 2, 1.0f, 1.0f, forceUpdate, MR_DATUM);
+ drawPocketFuelAids(state, forceUpdate);
+ }
+
void drawThemePlaceholder(
const DashboardState &state,
DashboardTheme theme,
@@ -2829,6 +3322,7 @@ public:
prevData[id] = value;
prevColor[id] = color;
+ releaseSpriteAfterThemePreview(sprite, spriteCreated);
}
void drawCenteredGear(const String &displayGear, bool forceUpdate,
@@ -2894,6 +3388,7 @@ public:
sprite.setFont(&fonts::Font0);
sprite.setTextSize(1.0f);
prevData[id] = displayGear;
+ releaseSpriteAfterThemePreview(sprite, spriteCreated);
}
void drawFuelIndicator(int32_t x, int32_t y, int32_t width, int32_t height,
@@ -2965,9 +3460,23 @@ public:
if (!pedalSpriteCreated)
{
pedalSprite.setColorDepth(16);
- pedalSprite.createSprite(DashboardLayout::PEDAL_BAR_W,
- DashboardLayout::PEDAL_BAR_H);
- pedalSpriteCreated = true;
+ pedalSpriteCreated = pedalSprite.createSprite(
+ DashboardLayout::PEDAL_BAR_W,
+ DashboardLayout::PEDAL_BAR_H) != nullptr;
+ }
+ if (!pedalSpriteCreated)
+ {
+ tft.fillRect(x, y, width, height, TFT_BLACK);
+ if (inputFill > 0)
+ tft.fillRect(x + 1, y + 1 + innerHeight - inputFill,
+ innerWidth, inputFill, inputColor);
+ if (appliedFill > 0)
+ tft.fillRect(x + 1, y + 1 + innerHeight - appliedFill,
+ innerWidth, appliedFill, appliedColor);
+ tft.drawRoundRect(x, y, width, height,
+ DashboardLayout::TYRE_CORNER_RADIUS, tft.color565(82, 86, 92));
+ prevData[id] = state;
+ return;
}
pedalSprite.fillSprite(TFT_BLACK);
@@ -2986,6 +3495,7 @@ public:
pedalSprite.drawRoundRect(0, 0, width, height,
DashboardLayout::TYRE_CORNER_RADIUS, tft.color565(82, 86, 92));
pedalSprite.pushSprite(x, y);
+ releaseSpriteAfterThemePreview(pedalSprite, pedalSpriteCreated);
prevData[id] = state;
}
@@ -3897,6 +4407,7 @@ public:
prevData[id] = data;
prevColor[id] = color;
+ releaseSpriteAfterThemePreview(sprite, spriteCreated);
}
void drawStatusIndicatorCell(
@@ -4011,6 +4522,12 @@ public:
classicPedalSprite.drawRoundRect(0, 0, totalWidth, cellHeight, 5,
TFT_DARKGREY);
classicPedalSprite.pushSprite(x, cellY);
+ if (settingsScreen == SettingsScreen::ThemeSelection)
+ {
+ classicPedalSprite.deleteSprite();
+ spriteWidth = 0;
+ spriteHeight = 0;
+ }
prevData[id] = state;
return;
}