From a60d054359f9f2edc63883e56a653b8596e2d081 Mon Sep 17 00:00:00 2001 From: Evan Reichard Date: Tue, 4 Aug 2026 20:44:13 -0400 Subject: [PATCH] feat(power): dim the backlight after ten idle seconds --- src/main.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index a6049e1..889ff92 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -43,6 +43,22 @@ static void fallbackScreen(const char* message) { halted = true; } +// ponytail: fixed 10s / 8% dim, no fade. Make it a setting when someone asks. +constexpr uint32_t kDimAfterMs = 10000; +constexpr int kBacklightChannel = 0; +uint32_t lastTouchMs = 0; +bool dimmed = false; + +void updateBacklight() { + if (touch.touched()) + lastTouchMs = millis(); + bool idle = millis() - lastTouchMs > kDimAfterMs; + if (idle == dimmed) + return; + dimmed = idle; + ledcWrite(kBacklightChannel, dimmed ? 20 : 255); +} + void setup() { Serial.begin(115200); @@ -61,6 +77,12 @@ void setup() { touchSpi.begin(14, 12, 13, TOUCH_CS); touch.begin(touchSpi); + // TFT_eSPI leaves TFT_BL a plain output; LEDC takes it over for dimming. + ledcSetup(kBacklightChannel, 5000, 8); + ledcAttachPin(TFT_BL, kBacklightChannel); + ledcWrite(kBacklightChannel, 255); + lastTouchMs = millis(); + sdSpi.begin(SD_SCK, SD_MISO, SD_MOSI, SD_CS); if (!SD.begin(SD_CS, sdSpi)) { fallbackScreen("SD card mount failed"); @@ -79,6 +101,7 @@ void loop() { delay(100); return; } + updateBacklight(); net::loop(); host.loop(); // The launcher failing to start is the one error no app can recover from.