From bf9c7746ba60613b66ce8d1e9a68c5480f2b93d1 Mon Sep 17 00:00:00 2001 From: Christian Kolset Date: Wed, 29 Jul 2026 13:12:17 -0600 Subject: Sync Mark-10 gauge's live unit into ChannelConfig instead of a fixed default MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mark10Layer._parse() already tracked whichever unit suffix the gauge last reported (lb/kgF/N/ozF — the gauge's physical unit button cycles these independently of this app). serial_device.py hardcoded the "force" channel's unit to "N" and never updated it, so switching units on the gauge itself was invisible here. Adds Mark10Layer.current_unit and has SerialDevice.read_channels() keep the "force" ChannelConfig's unit in sync with it on every poll. This fixes the unit shown in anything that reads ChannelConfig.unit live — new plots, channel pickers, CSV log headers — but does not relabel the Y-axis of an already-open plot pane, since plot axis labels are baked into PlotConfig.y_label once at plot-build time, not re-read from the channel live. Making an open pane's axis relabel itself would need new signal plumbing from the device through AcquisitionEngine to the strip chart — a bigger, separate change. Co-Authored-By: Claude Sonnet 5 --- api_layers/protocols/mark10.py | 5 +++++ devices/serial_device.py | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/api_layers/protocols/mark10.py b/api_layers/protocols/mark10.py index a209232..48ed927 100644 --- a/api_layers/protocols/mark10.py +++ b/api_layers/protocols/mark10.py @@ -44,6 +44,11 @@ class Mark10Layer(BaseProtocol): super().__init__(port, baud, poll_interval, simulate) self._unit = "N" + @property + def current_unit(self) -> str: + """Last unit suffix seen in a gauge reply (e.g. "N", "kgF").""" + return self._unit + # ── Protocol ────────────────────────────────────────────────────────── def _poll(self) -> Dict[str, float]: diff --git a/devices/serial_device.py b/devices/serial_device.py index 067656a..eadaa42 100644 --- a/devices/serial_device.py +++ b/devices/serial_device.py @@ -142,6 +142,14 @@ class SerialDevice(BaseDevice): raw = self._layer.read() if not raw: return {} + if self._fmt == "mark10" and hasattr(self._layer, "current_unit"): + # Gauge can be switched between lb/kgF/N/ozF on the device itself — + # keep the channel's unit in sync so new plots/pickers/CSV log + # headers pick up the currently-selected unit instead of a fixed + # default. Does not relabel the axis of an already-open plot pane. + force_ch = self.get_channel("force") + if force_ch is not None: + force_ch.unit = self._layer.current_unit if self._fmt not in _GENERIC_FORMATS: # Protocol layers already key by channel_id — pass through untouched. # (Write-only channels, e.g. CML "M1_VS", never appear in raw — correctly dropped.) -- cgit v1.2.3