Просмотр исходного кода

Remove stability flipping as scale report trigger

When ADC noise kept the spread hovering around the 2g stability
threshold, the stable flag toggled every cycle, forcing a report with
a slightly different weight each time. Now only actual weight changes
of >=2g trigger reports. The stable flag is still included in each
report for consumers that need it.
maziggy 6 месяцев назад
Родитель
Сommit
2811e2ec34
2 измененных файлов с 3 добавлено и 6 удалено
  1. 1 1
      CHANGELOG.md
  2. 2 5
      spoolbuddy/daemon/main.py

+ 1 - 1
CHANGELOG.md

@@ -12,7 +12,7 @@ All notable changes to Bambuddy will be documented in this file.
 - **SpoolBuddy Daemon Can't Find Hardware Drivers** — The daemon's `nfc_reader.py` and `scale_reader.py` import `read_tag` and `scale_diag` as bare modules, but these files live in `spoolbuddy/scripts/` which isn't on Python's module search path. The systemd service sets `WorkingDirectory` to `spoolbuddy/` and runs `python -m daemon.main`, so only the `spoolbuddy/` and `daemon/` directories are on `sys.path`. Added `scripts/` to `sys.path` at daemon startup, resolved relative to the module file so it works regardless of install path. Also moved the `read_tag` import inside `NFCReader.__init__`'s try/except block — it was previously outside, so a missing module crashed the entire daemon instead of gracefully skipping NFC polling. Demoted hardware-not-available log messages from ERROR to INFO since missing modules are expected when hardware isn't connected.
 
 ### Improved
-- **SpoolBuddy Scale Value Stabilization** — The SpoolBuddy daemon now suppresses redundant scale weight reports: only sends updates when the weight changes by ≥2g or the stability state flips (stable ↔ unstable). Previously every 1-second report interval sent a reading regardless of change, causing the dashboard weight display to bounce continuously. Also increased the NAU7802 moving average window from 5 to 20 samples (500ms → 2s), which smooths ADC noise enough that the averaged value stays within the 2g report threshold between intervals and the stability state stops flipping. The frontend also applies a 3g display threshold as defense-in-depth.
+- **SpoolBuddy Scale Value Stabilization** — The SpoolBuddy daemon now suppresses redundant scale weight reports: only sends updates when the weight changes by ≥2g. Previously every 1-second report interval sent a reading regardless of change, and stability state flips (stable ↔ unstable) also triggered reports — when ADC noise kept the spread hovering around the 2g stability threshold, the flag toggled every cycle, forcing a report with a slightly different weight each time. Removed stability flipping as a report trigger (the stable flag is still included in each report for consumers). Also increased the NAU7802 moving average window from 5 to 20 samples (500ms → 2s) to smooth ADC noise. The frontend also applies a 3g display threshold as defense-in-depth.
 - **SpoolBuddy TopBar: Online Printer Selection** — The printer selector in the SpoolBuddy top bar now only shows online printers and auto-selects the first online printer. If the currently selected printer goes offline, it automatically switches to the next available online printer. Also replaced the placeholder icon with the SpoolBuddy logo.
 
 ## [0.2.1] - 2026-02-27

+ 2 - 5
spoolbuddy/daemon/main.py

@@ -79,7 +79,6 @@ async def scale_poll_loop(config: Config, api: APIClient):
 
     last_report = 0.0
     last_reported_grams: float | None = None
-    last_reported_stable: bool | None = None
     REPORT_THRESHOLD = 2.0  # Only report if weight changed by more than this (grams)
     try:
         while True:
@@ -90,11 +89,10 @@ async def scale_poll_loop(config: Config, api: APIClient):
                 now = time.monotonic()
 
                 if now - last_report >= config.scale_report_interval:
-                    # Only send when weight changed meaningfully or stability flipped
+                    # Only send when weight changed meaningfully
                     weight_changed = last_reported_grams is None or abs(grams - last_reported_grams) >= REPORT_THRESHOLD
-                    stability_changed = last_reported_stable is None or stable != last_reported_stable
 
-                    if weight_changed or stability_changed:
+                    if weight_changed:
                         await api.scale_reading(
                             device_id=config.device_id,
                             weight_grams=grams,
@@ -102,7 +100,6 @@ async def scale_poll_loop(config: Config, api: APIClient):
                             raw_adc=raw_adc,
                         )
                         last_reported_grams = grams
-                        last_reported_stable = stable
                     last_report = now
 
             await asyncio.sleep(config.scale_read_interval)