aboutsummaryrefslogtreecommitdiffstats
path: root/deckit
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-11-11 20:29:52 +0100
committerDanilo M. <danix@danix.xyz>2026-11-11 20:29:52 +0100
commitfea2e9b221a2d18f9c73e5763adf662128cea5ec (patch)
tree018ac7111d3dce1e4768c7a702d4394baf5589e1 /deckit
parentc6f23856f080feee37c4972fb6689332b9873574 (diff)
downloaddeck-it-fea2e9b221a2d18f9c73e5763adf662128cea5ec.tar.gz
deck-it-fea2e9b221a2d18f9c73e5763adf662128cea5ec.zip
feat(tablet): dim the backlight after an idle timeout
After [tablet] dim_after seconds with no touch the page covers itself and the tablet module's dim action lowers the backlight to dim_brightness over adb, with auto brightness off meanwhile; an LCD's backlight is the drain, so a dark page alone saves little. The touch on the cover only calls undim, which restores both settings, as does the module's stop. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'deckit')
-rw-r--r--deckit/modules/tablet.py45
1 files changed, 43 insertions, 2 deletions
diff --git a/deckit/modules/tablet.py b/deckit/modules/tablet.py
index 3f4b0d9..01a5eba 100644
--- a/deckit/modules/tablet.py
+++ b/deckit/modules/tablet.py
@@ -25,7 +25,7 @@ import subprocess
import threading
import time
-from ..module import Module
+from ..module import Module, ModuleError
STATUS = {"2": "charging", "3": "discharging", "4": "not charging", "5": "full"}
TTL = 10 # seconds; each read is two adb round trips
@@ -105,4 +105,45 @@ def make(cfg: dict) -> Module:
cache["t"] = time.monotonic()
return cache["v"]
- return Module(name="tablet", title="Tablet", state=state)
+ tcfg = cfg.get("tablet", {})
+ dim_after = max(0, int(tcfg.get("dim_after", 120)))
+ level = min(255, max(0, int(tcfg.get("dim_brightness", 8))))
+ saved = {} # mode and brightness from before a dim; empty while bright
+
+ def shell(cmd):
+ serial = cache["serial"] or _find_tablet()
+ if not serial:
+ raise ModuleError("no tablet with the dashboard tunnel")
+ try:
+ return _adb("-s", serial, "shell", cmd).strip()
+ except (subprocess.SubprocessError, OSError) as e:
+ raise ModuleError(str(e) or type(e).__name__)
+
+ # The backlight is what drains an LCD, so a dim page alone saves little.
+ # Auto brightness is switched off while dimmed, else it raises it again.
+ def dim(_=None):
+ with lock:
+ if not saved:
+ saved["mode"] = shell("settings get system screen_brightness_mode")
+ saved["level"] = shell("settings get system screen_brightness")
+ shell(f"settings put system screen_brightness_mode 0;"
+ f" settings put system screen_brightness {level}")
+
+ # ponytail: the saved level lives in memory; a crash while dimmed leaves
+ # the tablet dim until its brightness is raised by hand.
+ def undim(_=None):
+ with lock:
+ if saved:
+ shell(f"settings put system screen_brightness {int(saved['level'])};"
+ f" settings put system screen_brightness_mode {int(saved['mode'])}")
+ saved.clear()
+
+ def stop():
+ try:
+ undim()
+ except ModuleError:
+ pass
+
+ return Module(name="tablet", title="Tablet",
+ state=lambda: {**state(), "dim_after": dim_after},
+ actions={"dim": dim, "undim": undim}, stop=stop)