summaryrefslogtreecommitdiff
path: root/devices/serial_device.py
diff options
context:
space:
mode:
authorChristian Kolset <ckolset@colostate.edu>2026-07-29 13:12:17 -0600
committerChristian Kolset <ckolset@colostate.edu>2026-07-29 13:12:17 -0600
commitbf9c7746ba60613b66ce8d1e9a68c5480f2b93d1 (patch)
tree21c49fa5d5c51e8935c98e7bf240b9e469287ff0 /devices/serial_device.py
parentb407a079000f6a4b04ecf38eca17c57719e7a7ec (diff)
Sync Mark-10 gauge's live unit into ChannelConfig instead of a fixed default
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 <noreply@anthropic.com>
Diffstat (limited to 'devices/serial_device.py')
-rw-r--r--devices/serial_device.py8
1 files changed, 8 insertions, 0 deletions
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.)