Browse Source

feat(spoolbuddy): auto-wake display on NFC tag scan or scale activity (#945)

  Display now powers on via wlopm when the daemon detects an NFC tag or
  a significant weight change (>=50g, i.e. spool placed/removed) while
  the screen is blanked.  Minor scale fluctuations no longer wake the
  display or prevent blanking.  The daemon only re-blanks screens it woke
  itself — touch-based wake/blank stays with swayidle so the two don't
  conflict.  Daemon discovers the Wayland session from the shared runtime
  dir since it runs as a systemd service outside the compositor.
maziggy 1 month ago
parent
commit
25203b3491
1 changed files with 8 additions and 1 deletions
  1. 8 1
      spoolbuddy/daemon/main.py

+ 8 - 1
spoolbuddy/daemon/main.py

@@ -171,7 +171,9 @@ async def scale_poll_loop(config: Config, api: APIClient, shared: dict):
 
     last_report = 0.0
     last_reported_grams: float | None = None
+    last_wake_grams: float | None = None
     REPORT_THRESHOLD = 2.0  # Only report if weight changed by more than this (grams)
+    WAKE_THRESHOLD = 50.0  # Only wake display on large changes (spool placed/removed, not sensor bounce)
     try:
         while True:
             result = await asyncio.to_thread(scale.read)
@@ -185,7 +187,12 @@ async def scale_poll_loop(config: Config, api: APIClient, shared: dict):
                     weight_changed = last_reported_grams is None or abs(grams - last_reported_grams) >= REPORT_THRESHOLD
 
                     if weight_changed:
-                        display.wake()
+                        # Wake display only on large weight changes (spool placed/removed)
+                        # to avoid sensor bounce keeping the screen on forever.
+                        wake_changed = last_wake_grams is None or abs(grams - last_wake_grams) >= WAKE_THRESHOLD
+                        if wake_changed:
+                            display.wake()
+                            last_wake_grams = grams
                         await api.scale_reading(
                             device_id=config.device_id,
                             weight_grams=grams,