summaryrefslogtreecommitdiff
path: root/ui/strip_chart.py
diff options
context:
space:
mode:
authorChristian Kolset <ckolset@colostate.edu>2026-08-10 16:12:05 -0600
committerChristian Kolset <ckolset@colostate.edu>2026-08-10 16:12:05 -0600
commit5d5bcaed8639a162fda85c8cd0d340c296a054b8 (patch)
treea7a1a62fb607c9c85127dab4aab17ccf8e22c906 /ui/strip_chart.py
parent46231c00994cd681d598961f2056dbda31c3e483 (diff)
Unify Signals/Channels around auto-naming, plot-by-channel, and shared vars
Devices: auto-name from OS-reported port description (Device Manager / udev string) instead of a generic label; default Serial #Channels 1; consistent simulate-mode checkbox across backends; inline device rename. Channels: calibration/filters move out of Signals into a Channel "Operation" (adds Scale/Offset alongside the existing math kinds); single-physical-source Channels get an embedded Filters block; new Channels auto-name/auto-ID from their source and reject duplicate names/IDs on apply; "Create Channel" button on each Signal row; renamed "Sources" -> "Signals" in the Channels UI; Signals' READ/WRITE dir badge (was silently-broken IN/OUT) now reflects the real writable flag. Plot: default layout is one pane per Channel (not per device, not raw Signals) titled by channel name; "+ Add Channel" is a checkbox dialog instead of an inline dropdown; traces get up/down reorder; live unit changes (e.g. a Mark-10 gauge switching lb/kgF/N/ozF) propagate to an open pane's axis label without clobbering a manually-typed one. Control Panel: hardware assignment now picks from the same writable- Signals list instead of a separate device/channel combo with a hardcoded Arduino pin list; stale visual indicator when a control's target device/channel disconnects or disappears; documented the `vars` bridge (Control Panel On Action Script <-> Channel scripts) in both directions' help text and script templates. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Diffstat (limited to 'ui/strip_chart.py')
-rw-r--r--ui/strip_chart.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/ui/strip_chart.py b/ui/strip_chart.py
index a212e5c..6c644be 100644
--- a/ui/strip_chart.py
+++ b/ui/strip_chart.py
@@ -79,6 +79,9 @@ class StripChartWidget(QWidget):
self._cfg: Optional[LayoutConfig] = None
# (dev_id, ch_id) → [{curve, plot, spec}]
self._curves: Dict[Tuple, List[dict]] = {}
+ # (dev_id, ch_id) → last unit seen — lets refresh_pane_unit() tell an
+ # auto-seeded pane label apart from one the operator typed by hand
+ self._known_units: Dict[Tuple[str, str], str] = {}
# Time-axis plots, scrolled continuously by _scroll_timer rather than
# only when a new sample lands — decouples the visible scroll rate
# from the (much slower) poll rate so it doesn't look stepped.
@@ -179,6 +182,10 @@ class StripChartWidget(QWidget):
key = (tr.device_id, tr.channel_id)
self._curves.setdefault(key, []).append(
{"curve": curve, "plot": plot, "spec": spec, "pane": spec})
+ # Seed with the channel's true current unit (not spec.y_label,
+ # which may be pane title text or a custom label) so the first
+ # live unit-change after a layout rebuild is still detected.
+ self._known_units[key] = self._lookup_channel_unit(*key)
def set_theme(self, theme: str):
"""Hot-swap pyqtgraph colours when the user changes theme."""
@@ -196,6 +203,34 @@ class StripChartWidget(QWidget):
for e in self._curves.get(key, []):
e["curve"].setVisible(enabled)
+ def _lookup_channel_unit(self, device_id: str, channel_id: str) -> str:
+ if device_id == "derived":
+ for dc in self.processor.get_derived():
+ if dc.channel_id == channel_id:
+ return dc.unit
+ return ""
+ dev = self.registry.get_instance(device_id)
+ ch = dev.get_channel(channel_id) if dev else None
+ return ch.unit if ch else ""
+
+ @pyqtSlot(str, str, str)
+ def refresh_pane_unit(self, device_id: str, channel_id: str, new_unit: str):
+ """A channel's unit changed live (e.g. a Mark-10 gauge switched
+ lb/kgF/N/ozF on its own front panel). Update any open pane's Y-axis
+ label that's still showing the *previous* unit verbatim — but never
+ touch a label the operator typed by hand."""
+ key = (device_id, channel_id)
+ old_unit = self._known_units.get(key)
+ self._known_units[key] = new_unit
+ if old_unit == new_unit:
+ return
+ for entry in self._curves.get(key, []):
+ spec = entry["spec"]
+ if spec.y_label != old_unit:
+ continue
+ spec.y_label = new_unit
+ entry["plot"].setLabel("left", new_unit or spec.title)
+
@pyqtSlot(str, str, float, float)
def on_new_data(self, device_id: str, channel_id: str, ts: float, val: float):
if self._paused or not _HAS_PG or not self._cfg: return