From 5d5bcaed8639a162fda85c8cd0d340c296a054b8 Mon Sep 17 00:00:00 2001 From: Christian Kolset Date: Mon, 10 Aug 2026 16:12:05 -0600 Subject: 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 --- ui/code_templates.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'ui/code_templates.py') diff --git a/ui/code_templates.py b/ui/code_templates.py index ffa1662..2a3ff09 100644 --- a/ui/code_templates.py +++ b/ui/code_templates.py @@ -19,12 +19,29 @@ Namespace available in all kinds: math — Python math module vars — shared SignalProcessor._script_vars dict (read/write) state — per-channel persistent dict (survives between evaluations) + +`vars` is the bridge from the Control Panel into Channel math: a button's +"On Action Script" (ui/control_editor.py) and every Channel script here see +the *same* `vars` dict. e.g. a "Zero" button sets + vars['zero'] = channels.get('force_raw', 0) +and a Channel reads it back with `vars.get('zero', 0)` — see the +"custom_script" template below. Same pattern for an operator-entered +constant like specimen length: a Setpoint control's On Action Script sets +`vars['specimen_length_cm'] = value`, and a Channel divides by it. """ BUILTIN_TEMPLATES: dict = { "none": """\ result = x[0] +""", + + "scale_offset": """\ +# scale/offset also settable from a Control Panel button's On Action Script, +# e.g. vars["offset"] = -x[0] to zero the reading on press +scale = vars.get("scale", 1.0) +offset = vars.get("offset", 0.0) +result = x[0] * scale + offset """, "derivative": """\ @@ -99,11 +116,14 @@ SCRIPT_TEMPLATES: dict = { "expression": "x[0]", "function": """\ +# "offset" can be set here or from a Control Panel button's On Action Script +# (vars is the same dict on both sides) offset = vars.get("offset", 0) return x[0] - offset """, "custom_script": """\ +# Wire a "Zero" button to this: On Action Script -> vars["zero"] = channels.get("", 0) zero = vars.get("zero", 0) result = x[0] - zero """, -- cgit v1.2.3