Skip to content
C

Add Retro dashboard renderer

YU CHIH CHANGf31e28d9fcd9
diff --git a/THEME_SWITCH_PLAN.md b/THEME_SWITCH_PLAN.md
index 283b915..c364940 100644
--- a/THEME_SWITCH_PLAN.md
+++ b/THEME_SWITCH_PLAN.md
@@ -9,7 +9,7 @@ Overall progress:
- [x] **Phase 1 — Theme infrastructure** — accepted on ST7789 hardware (2026-08-17)
- [x] **Phase 2 — Touch Settings and theme selection** — accepted on ST7789 and ILI9341 hardware (2026-08-17)
- [x] **Phase 3 — Classic 1.2.5 renderer** — accepted on ST7789 hardware (2026-08-17)
-- [ ] **Phase 4 — Retro renderer**
+- [x] **Phase 4 — Retro renderer** — accepted on ST7789 hardware (2026-08-18)
- [ ] **Phase 5 — Integration, regression testing and release**
Working rule for every phase:
@@ -339,18 +339,20 @@ Use the supplied reference image as a style reference, not as a requirement to a
Pass conditions:
-- [ ] The UI clearly reads as a warm gray, dark-text vintage instrument panel.
-- [ ] All current dashboard functions are present, with no additional unsupported functions.
-- [ ] Speed and gear remain readable at a glance on the 2.8-inch display.
-- [ ] Small labels and timing values remain legible from the normal driving position.
-- [ ] Dynamic values do not flicker, jump horizontally or leave background artifacts.
-- [ ] Positive/negative delta and shift warnings remain distinguishable without overpowering the monochrome style.
-- [ ] RPM fill, min-alert position and shift alert respond correctly for cars with different alert RPM ranges.
-- [ ] Switching among Retro, Classic and GT3 repeatedly produces complete, clean redraws.
-- [ ] Retro remains stable for at least one normal driving session.
+- [x] The UI clearly reads as a warm gray, dark-text vintage instrument panel.
+- [x] All current dashboard functions are present, with no additional unsupported functions.
+- [x] Speed and gear remain readable at a glance on the 2.8-inch display.
+- [x] Small labels and timing values remain legible from the normal driving position.
+- [x] Dynamic values do not flicker, jump horizontally or leave background artifacts.
+- [x] Positive/negative delta and shift warnings remain distinguishable without overpowering the monochrome style.
+- [x] RPM fill, min-alert position and shift alert respond correctly for cars with different alert RPM ranges.
+- [x] Switching among Retro, Classic and GT3 repeatedly produces complete, clean redraws.
+- [x] Retro remains stable for at least one normal driving session.
Visual approval should be based on photographs of the actual display rather than desktop mockups alone.
+**Acceptance record:** Phase 4 was accepted after iterative ST7789 hardware testing. The final Retro palette uses a `#C6BA98` paper background with dark ink, restrained status accents and the existing telemetry semantics. RPM, speed, current-lap time, tyre temperatures and pedal bars use partial or buffered redraws to eliminate visible SPI clearing flicker. The supplied dashboard image was treated as a visual reference rather than a layout specification.
+
### Phase 5 — Integration and Release
- Test all three themes with live GT7 telemetry.
diff --git a/src/SHCustomProtocol.h b/src/SHCustomProtocol.h
index 8e3a6c5..d107fe7 100644
--- a/src/SHCustomProtocol.h
+++ b/src/SHCustomProtocol.h
@@ -1025,7 +1025,7 @@ public:
drawPage1Legacy(forceUpdate);
break;
case DashboardTheme::Retro:
- drawThemePlaceholder(state, DashboardTheme::Retro, forceUpdate);
+ drawRetroDashboard(state, forceUpdate);
break;
case DashboardTheme::GT3:
default:
@@ -1038,6 +1038,326 @@ public:
}
}
+ static uint16_t blendRgb565(uint16_t from, uint16_t to, uint8_t amount)
+ {
+ const uint8_t fromR = ((from >> 11) & 0x1F) * 255 / 31;
+ const uint8_t fromG = ((from >> 5) & 0x3F) * 255 / 63;
+ const uint8_t fromB = (from & 0x1F) * 255 / 31;
+ const uint8_t toR = ((to >> 11) & 0x1F) * 255 / 31;
+ const uint8_t toG = ((to >> 5) & 0x3F) * 255 / 63;
+ const uint8_t toB = (to & 0x1F) * 255 / 31;
+ return tft.color565(
+ fromR + (toR - fromR) * amount / 255,
+ fromG + (toG - fromG) * amount / 255,
+ fromB + (toB - fromB) * amount / 255);
+ }
+
+ 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,
+ float scaleY = 1.0f)
+ {
+ const String state = value + ":" + String(color);
+ if (!forceUpdate && prevData[id] == state) return;
+ const uint16_t paper = tft.color565(198, 186, 152);
+ tft.fillRect(x, y, width, height, paper);
+ tft.setTextColor(color, paper);
+ tft.setTextDatum(datum);
+ tft.setTextSize(scaleX, scaleY);
+ const int32_t textX = datum == MR_DATUM ? x + width - 2
+ : (datum == MC_DATUM ? x + width / 2 : x + 2);
+ tft.drawString(value, textX, y + height / 2, font);
+ tft.setTextSize(1.0f);
+ tft.setTextDatum(TL_DATUM);
+ prevData[id] = state;
+ }
+
+ void drawRetroTextValueBuffered(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, LGFX_Sprite &sprite,
+ bool &spriteCreated, float scaleX = 1.0f, float scaleY = 1.0f)
+ {
+ const String cacheState = value + ":" + String(color);
+ if (!forceUpdate && prevData[id] == cacheState) return;
+ const uint16_t paper = tft.color565(198, 186, 152);
+ if (!spriteCreated)
+ {
+ sprite.setColorDepth(16);
+ spriteCreated = sprite.createSprite(width, height) != nullptr;
+ }
+ if (!spriteCreated)
+ {
+ drawRetroTextValue(x, y, width, height, value, id, color, font,
+ datum, true, scaleX, scaleY);
+ return;
+ }
+ sprite.fillSprite(paper);
+ sprite.setTextColor(color, paper);
+ sprite.setTextDatum(datum);
+ sprite.setTextSize(scaleX, scaleY);
+ const int32_t textX = datum == MR_DATUM ? width - 2
+ : (datum == MC_DATUM ? width / 2 : 2);
+ sprite.drawString(value, textX, height / 2, font);
+ sprite.setTextSize(1.0f);
+ sprite.pushSprite(x, y);
+ prevData[id] = cacheState;
+ }
+
+ void drawRetroRpm(const DashboardState &state, bool forceUpdate)
+ {
+ static constexpr int SEGMENT_COUNT = 28;
+ static constexpr int SEGMENT_X = 58;
+ static constexpr int SEGMENT_PITCH = 9;
+ static constexpr int SEGMENT_WIDTH = 7;
+ static constexpr int SEGMENT_Y = 24;
+ static constexpr int SEGMENT_HEIGHT = 17;
+ static constexpr float PULSE_HZ = 3.0f;
+ static constexpr uint32_t FRAME_MS = 24;
+ static int previousActive = -1;
+ static bool previousPulse = false;
+ static uint32_t pulseStart = 0;
+ static uint32_t lastFrame = 0;
+ static uint8_t previousMix = 0;
+
+ const uint16_t paper = tft.color565(198, 186, 152);
+ const uint16_t ink = tft.color565(25, 31, 29);
+ const uint16_t faint = tft.color565(118, 116, 103);
+ const uint16_t alert = tft.color565(178, 55, 39);
+ const int active = constrain(
+ (state.rpmPercent * SEGMENT_COUNT + 99) / 100, 0, SEGMENT_COUNT);
+ const bool warning = state.rpmAlertRangeValid &&
+ state.rpmPercent >= state.rpmRedLineSetting;
+ const bool pulse = warning || state.revLimitAlertActive;
+ const uint32_t now = millis();
+ const bool pulseStarted = pulse && !previousPulse;
+ if (pulseStarted) pulseStart = now;
+
+ uint8_t whiteMix = 0;
+ bool pulseFrame = false;
+ if (pulse && (pulseStarted || now - lastFrame >= FRAME_MS))
+ {
+ float peak = 0.30f;
+ if (warning)
+ {
+ const float span = max(1, 100 - state.rpmRedLineSetting);
+ const float progress = constrain(
+ (state.rpmPercent - state.rpmRedLineSetting) / span, 0.0f, 1.0f);
+ peak += 0.20f * progress;
+ }
+ if (state.revLimitAlertActive) peak = 0.62f;
+ const float elapsed = (now - pulseStart) / 1000.0f;
+ const float wave = 0.5f + 0.5f * cosf(TWO_PI * PULSE_HZ * elapsed);
+ whiteMix = static_cast<uint8_t>(lroundf(255.0f * peak * wave));
+ pulseFrame = pulseStarted || whiteMix != previousMix;
+ lastFrame = now;
+ }
+ else if (pulse)
+ {
+ whiteMix = previousMix;
+ }
+
+ const String alertState = String(state.rpmRedLineSetting) + ":" +
+ String(state.rpmAlertRangeValid ? 1 : 0);
+ const bool alertChanged = prevData["retroAlertRange"] != alertState;
+ const bool pulseEnded = !pulse && previousPulse;
+ if (forceUpdate || active != previousActive || alertChanged || pulseFrame || pulseEnded)
+ {
+ for (int i = 0; i < SEGMENT_COUNT; ++i)
+ {
+ const bool fillChanged = previousActive < 0 ||
+ (i >= min(active, previousActive) && i < max(active, previousActive));
+ const bool pulseChanged = i < active && (pulseFrame || pulseEnded);
+ if (!forceUpdate && !alertChanged && !fillChanged && !pulseChanged) continue;
+ const int x = SEGMENT_X + i * SEGMENT_PITCH;
+ tft.fillRect(x, SEGMENT_Y, SEGMENT_WIDTH, SEGMENT_HEIGHT, paper);
+ if (i < active)
+ {
+ const uint16_t color = pulse
+ ? blendRgb565(ink, TFT_WHITE, whiteMix)
+ : ink;
+ tft.fillRect(x, SEGMENT_Y, SEGMENT_WIDTH, SEGMENT_HEIGHT, color);
+ }
+ else
+ {
+ tft.drawRect(x, SEGMENT_Y, SEGMENT_WIDTH, SEGMENT_HEIGHT, faint);
+ }
+ }
+
+ // The amber index marks the car-specific min-alert position.
+ tft.fillRect(SEGMENT_X - 4, 17,
+ SEGMENT_PITCH * (SEGMENT_COUNT - 1) + SEGMENT_WIDTH + 8, 6, paper);
+ if (state.rpmAlertRangeValid)
+ {
+ const float position = constrain(
+ state.rpmRedLineSetting / 100.0f, 0.0f, 1.0f);
+ const int markerX = SEGMENT_X + lroundf(
+ position * SEGMENT_PITCH * (SEGMENT_COUNT - 1)) + SEGMENT_WIDTH / 2;
+ tft.fillTriangle(markerX - 3, 17, markerX + 3, 17,
+ markerX, 22, alert);
+ }
+ }
+
+ const int displayedRpm = ((state.engineRpm + 25) / 50) * 50;
+ drawRetroTextValue(5, 25, 49, 20, String(displayedRpm), "retroRpm",
+ pulse ? alert : ink, 2, MC_DATUM, forceUpdate);
+ previousActive = active;
+ previousPulse = pulse;
+ previousMix = pulse ? whiteMix : 0;
+ prevData["retroAlertRange"] = alertState;
+ }
+
+ void drawRetroPedals(const DashboardState &state, bool forceUpdate)
+ {
+ const int brakeInput = constrain(state.absLevel.toInt(), 0, 100);
+ const int brakeApplied = constrain(state.absFilteredLevel.toInt(), 0, 100);
+ const int throttleInput = constrain(state.tcLevel.toInt(), 0, 100);
+ const int throttleApplied = constrain(state.tcFilteredLevel.toInt(), 0, 100);
+ const String value = String(brakeInput) + ":" + String(brakeApplied) + ":" +
+ String(throttleInput) + ":" + String(throttleApplied);
+ if (!forceUpdate && prevData["retroPedals"] == value) return;
+ const uint16_t paper = tft.color565(198, 186, 152);
+ const uint16_t ink = tft.color565(25, 31, 29);
+ const uint16_t faint = tft.color565(118, 116, 103);
+ const uint16_t applied = tft.color565(74, 93, 69);
+ static LGFX_Sprite pedalSprite(&tft);
+ static bool spriteCreated = false;
+ if (!spriteCreated)
+ {
+ pedalSprite.setColorDepth(16);
+ spriteCreated = pedalSprite.createSprite(93, 33) != nullptr;
+ }
+ if (!spriteCreated) return;
+ pedalSprite.fillSprite(paper);
+ pedalSprite.setTextColor(ink, paper);
+ pedalSprite.setTextDatum(TL_DATUM);
+ pedalSprite.drawString("B", 8, 4, 1);
+ pedalSprite.drawString("T", 8, 17, 1);
+ const int barX = 21;
+ const int barW = 68;
+ const int barH = 7;
+ const int values[2][2] = {
+ {brakeInput, brakeApplied}, {throttleInput, throttleApplied}};
+ for (int row = 0; row < 2; ++row)
+ {
+ const int y = 7 + row * 13;
+ pedalSprite.drawRect(barX, y, barW, barH, faint);
+ const int inputW = (barW - 2) * values[row][0] / 100;
+ const int appliedW = (barW - 2) * values[row][1] / 100;
+ if (inputW > 0) pedalSprite.fillRect(barX + 1, y + 1, inputW, barH - 2, ink);
+ if (appliedW > 0) pedalSprite.fillRect(barX + 1, y + 1, appliedW, barH - 2, applied);
+ }
+ pedalSprite.pushSprite(143, 204);
+ prevData["retroPedals"] = value;
+ }
+
+ void drawRetroDashboard(const DashboardState &state, bool forceUpdate)
+ {
+ static LGFX_Sprite speedSprite(&tft);
+ static LGFX_Sprite currentSprite(&tft);
+ static LGFX_Sprite tyreSprite(&tft);
+ static bool speedSpriteCreated = false;
+ static bool currentSpriteCreated = false;
+ static bool tyreSpriteCreated = false;
+ const uint16_t paper = tft.color565(198, 186, 152);
+ const uint16_t ink = tft.color565(25, 31, 29);
+ const uint16_t faint = tft.color565(118, 116, 103);
+ const uint16_t green = tft.color565(55, 102, 64);
+ const uint16_t red = tft.color565(178, 55, 39);
+
+ if (forceUpdate)
+ {
+ tft.fillScreen(paper);
+ tft.setTextPadding(0);
+ tft.setTextSize(1.0f);
+ tft.setTextDatum(TL_DATUM);
+ tft.setTextColor(ink, paper);
+
+ // Compact industrial panel grid, sized for the 320 x 240 display.
+ tft.drawRoundRect(2, 2, 316, 47, 4, ink);
+ tft.drawRoundRect(2, 52, 94, 106, 4, ink);
+ tft.drawRoundRect(99, 52, 84, 106, 4, ink);
+ tft.drawRoundRect(186, 52, 132, 106, 4, ink);
+ tft.drawFastHLine(186, 87, 132, faint);
+ tft.drawFastHLine(186, 122, 132, faint);
+ tft.drawRoundRect(2, 161, 316, 39, 4, ink);
+ tft.drawFastVLine(80, 161, 39, faint);
+ tft.drawFastVLine(157, 161, 39, faint);
+ tft.drawFastVLine(237, 161, 39, faint);
+ tft.drawRoundRect(2, 203, 316, 35, 4, ink);
+ tft.drawFastVLine(142, 203, 35, faint);
+ tft.drawFastVLine(237, 203, 35, faint);
+
+ tft.drawString("RPM", 8, 8, 2);
+ tft.drawString("SPEED", 8, 59, 2);
+ tft.drawString("km/h", 61, 143, 1);
+ 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("FUEL", 8, 166, 1);
+ tft.drawString("REM", 86, 166, 1);
+ tft.drawString("LAP", 163, 166, 1);
+ tft.drawString("POS", 243, 166, 1);
+ tft.drawString("TYRE TEMP C", 8, 207, 1);
+ tft.drawString("ABS", 243, 208, 1);
+ tft.drawString("TCS", 243, 223, 1);
+ }
+
+ drawRetroRpm(state, forceUpdate);
+ drawRetroTextValueBuffered(7, 77, 84, 62, state.speed, "retroSpeed", ink,
+ 7, MC_DATUM, forceUpdate, speedSprite, speedSpriteCreated, 0.72f, 0.82f);
+ drawRetroTextValue(104, 76, 74, 72, state.gear, "retroGear", ink,
+ 7, MC_DATUM, forceUpdate, 1.05f, 1.08f);
+
+ // Keep labels and values on separate rows. Fractionally scaled bitmap fonts
+ // produced malformed glyphs on the 2.8-inch panel, so Retro uses native sizes.
+ drawRetroTextValue(190, 68, 124, 17, state.bestLapTime, "retroBest", ink,
+ 2, MR_DATUM, forceUpdate);
+ drawRetroTextValue(190, 103, 124, 17, state.lastLapTime, "retroLast", ink,
+ 2, MR_DATUM, forceUpdate);
+ const uint16_t currentColor = state.lapInvalidated == "True" ? red : ink;
+ drawRetroTextValueBuffered(190, 136, 124, 12, state.currentLapTime,
+ "retroCurrent", currentColor, 1, MR_DATUM, forceUpdate,
+ currentSprite, currentSpriteCreated);
+
+ uint16_t deltaColor = ink;
+ if (state.sessionBestLiveDeltaSeconds.startsWith("-")) deltaColor = green;
+ else if (state.sessionBestLiveDeltaSeconds.startsWith("+") &&
+ state.sessionBestLiveDeltaSeconds != "+0.000") deltaColor = red;
+ drawRetroTextValue(190, 148, 124, 8, state.sessionBestLiveDeltaSeconds,
+ "retroDelta", deltaColor, 1, MR_DATUM, forceUpdate);
+
+ drawRetroTextValue(7, 177, 68, 18, state.brakeBias, "retroFuel", ink,
+ 2, MC_DATUM, forceUpdate, 0.9f, 0.95f);
+ drawRetroTextValue(85, 177, 67, 18, state.tyrePressureFrontLeft, "retroRem", ink,
+ 2, MC_DATUM, forceUpdate, 0.9f, 0.95f);
+ String lap = state.tyrePressureRearLeft;
+ lap.replace("/", "/");
+ drawRetroTextValue(162, 177, 70, 18, lap, "retroLap", ink,
+ 2, MC_DATUM, forceUpdate, 0.78f, 0.95f);
+ drawRetroTextValue(242, 177, 70, 18, state.tyrePressureFrontRight, "retroPos", ink,
+ 2, MC_DATUM, forceUpdate, 0.9f, 0.95f);
+
+ String tyres;
+ const char *names[] = {"FL", "FR", "RL", "RR"};
+ for (int i = 0; i < 4; ++i)
+ {
+ if (i > 0) tyres += " ";
+ tyres += names[i];
+ tyres += isnan(state.tyreTemperatures[i])
+ ? "--" : String(lroundf(state.tyreTemperatures[i]));
+ }
+ drawRetroTextValueBuffered(6, 218, 132, 16, tyres, "retroTyres", ink,
+ 1, MC_DATUM, forceUpdate, tyreSprite, tyreSpriteCreated);
+ drawRetroPedals(state, forceUpdate);
+ drawRetroTextValue(273, 205, 40, 15,
+ isActiveValue(state.absActive) ? "ON" : "--", "retroAbs",
+ isActiveValue(state.absActive) ? red : faint, 1, MC_DATUM, forceUpdate);
+ drawRetroTextValue(273, 220, 40, 15,
+ isActiveValue(state.tcActive) ? "ON" : "--", "retroTcs",
+ isActiveValue(state.tcActive) ? red : faint, 1, MC_DATUM, forceUpdate);
+ }
+
void drawThemePlaceholder(
const DashboardState &state,
DashboardTheme theme,
@@ -2708,6 +3028,9 @@ public:
const String state = String(percent) + ":" + String(appliedPercent);
const bool firstDraw = true;
const int oldPercent = 0;
+ const uint16_t inputColor = color == TFT_YELLOW
+ ? tft.color565(255, 245, 150)
+ : tft.color565(110, 170, 255);
if (!forceUpdate && prevData[id] == state)
{
@@ -2738,7 +3061,7 @@ public:
classicPedalSprite.fillSprite(TFT_BLACK);
if (spriteInputFill > 0)
classicPedalSprite.fillRect(spriteInset, spriteInset,
- spriteInputFill, spriteFillHeight, TFT_WHITE);
+ spriteInputFill, spriteFillHeight, inputColor);
if (spriteAppliedFill > 0)
classicPedalSprite.fillRect(spriteInset, spriteInset,
spriteAppliedFill, spriteFillHeight, color);
@@ -2767,7 +3090,7 @@ public:
if (newFill > 0)
{
tft.fillRect(fillX, fillY, newFill, fillHeight,
- TFT_WHITE);
+ inputColor);
}
}
else if (newFill > oldFill)
@@ -2778,7 +3101,7 @@ public:
fillY,
newFill - oldFill,
fillHeight,
- color);
+ inputColor);
}
else if (newFill < oldFill)
{