From 2a634dca0c7962b90004f75c4cdac6225201bb5e Mon Sep 17 00:00:00 2001 From: Christian Kolset Date: Tue, 21 Apr 2026 13:43:52 -0600 Subject: V13 This version contains the profile feature. Allowins users to save the channels, signals and plots for specific labs. --- devices/__pycache__/__init__.cpython-312.pyc | Bin 0 -> 396 bytes devices/__pycache__/__init__.cpython-314.pyc | Bin 401 -> 0 bytes devices/__pycache__/analog_input.cpython-312.pyc | Bin 0 -> 23750 bytes devices/__pycache__/analog_input.cpython-314.pyc | Bin 24525 -> 0 bytes devices/__pycache__/base_device.cpython-312.pyc | Bin 0 -> 5615 bytes devices/__pycache__/base_device.cpython-314.pyc | Bin 7588 -> 0 bytes .../__pycache__/device_registry.cpython-312.pyc | Bin 0 -> 4582 bytes .../__pycache__/device_registry.cpython-314.pyc | Bin 5930 -> 0 bytes devices/__pycache__/digital_io.cpython-312.pyc | Bin 0 -> 18353 bytes devices/__pycache__/digital_io.cpython-314.pyc | Bin 19331 -> 0 bytes devices/__pycache__/serial_device.cpython-312.pyc | Bin 0 -> 14680 bytes devices/__pycache__/serial_device.cpython-314.pyc | Bin 16431 -> 0 bytes devices/analog_input.py | 26 +++++++++++++++++++-- devices/digital_io.py | 19 ++++++++++++++- 14 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 devices/__pycache__/__init__.cpython-312.pyc delete mode 100644 devices/__pycache__/__init__.cpython-314.pyc create mode 100644 devices/__pycache__/analog_input.cpython-312.pyc delete mode 100644 devices/__pycache__/analog_input.cpython-314.pyc create mode 100644 devices/__pycache__/base_device.cpython-312.pyc delete mode 100644 devices/__pycache__/base_device.cpython-314.pyc create mode 100644 devices/__pycache__/device_registry.cpython-312.pyc delete mode 100644 devices/__pycache__/device_registry.cpython-314.pyc create mode 100644 devices/__pycache__/digital_io.cpython-312.pyc delete mode 100644 devices/__pycache__/digital_io.cpython-314.pyc create mode 100644 devices/__pycache__/serial_device.cpython-312.pyc delete mode 100644 devices/__pycache__/serial_device.cpython-314.pyc (limited to 'devices') diff --git a/devices/__pycache__/__init__.cpython-312.pyc b/devices/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000..bd9bb71 Binary files /dev/null and b/devices/__pycache__/__init__.cpython-312.pyc differ diff --git a/devices/__pycache__/__init__.cpython-314.pyc b/devices/__pycache__/__init__.cpython-314.pyc deleted file mode 100644 index 47d46e4..0000000 Binary files a/devices/__pycache__/__init__.cpython-314.pyc and /dev/null differ diff --git a/devices/__pycache__/analog_input.cpython-312.pyc b/devices/__pycache__/analog_input.cpython-312.pyc new file mode 100644 index 0000000..2ff8a31 Binary files /dev/null and b/devices/__pycache__/analog_input.cpython-312.pyc differ diff --git a/devices/__pycache__/analog_input.cpython-314.pyc b/devices/__pycache__/analog_input.cpython-314.pyc deleted file mode 100644 index b6be747..0000000 Binary files a/devices/__pycache__/analog_input.cpython-314.pyc and /dev/null differ diff --git a/devices/__pycache__/base_device.cpython-312.pyc b/devices/__pycache__/base_device.cpython-312.pyc new file mode 100644 index 0000000..f665ff1 Binary files /dev/null and b/devices/__pycache__/base_device.cpython-312.pyc differ diff --git a/devices/__pycache__/base_device.cpython-314.pyc b/devices/__pycache__/base_device.cpython-314.pyc deleted file mode 100644 index 6566690..0000000 Binary files a/devices/__pycache__/base_device.cpython-314.pyc and /dev/null differ diff --git a/devices/__pycache__/device_registry.cpython-312.pyc b/devices/__pycache__/device_registry.cpython-312.pyc new file mode 100644 index 0000000..2694da3 Binary files /dev/null and b/devices/__pycache__/device_registry.cpython-312.pyc differ diff --git a/devices/__pycache__/device_registry.cpython-314.pyc b/devices/__pycache__/device_registry.cpython-314.pyc deleted file mode 100644 index 780bd71..0000000 Binary files a/devices/__pycache__/device_registry.cpython-314.pyc and /dev/null differ diff --git a/devices/__pycache__/digital_io.cpython-312.pyc b/devices/__pycache__/digital_io.cpython-312.pyc new file mode 100644 index 0000000..8c7375b Binary files /dev/null and b/devices/__pycache__/digital_io.cpython-312.pyc differ diff --git a/devices/__pycache__/digital_io.cpython-314.pyc b/devices/__pycache__/digital_io.cpython-314.pyc deleted file mode 100644 index c1a14b4..0000000 Binary files a/devices/__pycache__/digital_io.cpython-314.pyc and /dev/null differ diff --git a/devices/__pycache__/serial_device.cpython-312.pyc b/devices/__pycache__/serial_device.cpython-312.pyc new file mode 100644 index 0000000..7472878 Binary files /dev/null and b/devices/__pycache__/serial_device.cpython-312.pyc differ diff --git a/devices/__pycache__/serial_device.cpython-314.pyc b/devices/__pycache__/serial_device.cpython-314.pyc deleted file mode 100644 index 46fb630..0000000 Binary files a/devices/__pycache__/serial_device.cpython-314.pyc and /dev/null differ diff --git a/devices/analog_input.py b/devices/analog_input.py index 6183f43..508804f 100644 --- a/devices/analog_input.py +++ b/devices/analog_input.py @@ -141,7 +141,22 @@ class AnalogInputDevice(BaseDevice): return self._layer.read() def write_channel(self, channel_id: str, value: Any) -> bool: - return False + """ + Route output commands through the Arduino layer. + + channel_id examples: + "D7" → digital write W:D7:1 or W:D7:0 + "D9" → PWM write P:D9: (if value is 0-255) + "HEAT" → named param C:HEAT:1.0 + """ + if self.backend != "arduino" or not hasattr(self._layer, "digital_write"): + return False + ch = channel_id.strip() + # Digital pin (D7, D13, etc.) + if ch.upper().startswith("D") and ch[1:].isdigit(): + return self._layer.digital_write(ch, int(bool(value))) + # Named parameter / setpoint + return self._layer.set_parameter(ch, value) def get_config_widget(self) -> QWidget: return AnalogInputConfigWidget(self) @@ -295,7 +310,7 @@ class AnalogInputConfigWidget(QWidget): self._diag_box = QTextEdit() self._diag_box.setObjectName("codeEditor") self._diag_box.setReadOnly(True) - self._diag_box.setMaximumHeight(90) + self._diag_box.setMaximumHeight(160) self._diag_box.setPlaceholderText("Connection log will appear here…") diag_lay.addWidget(self._diag_box) @@ -332,6 +347,13 @@ class AnalogInputConfigWidget(QWidget): lines.append(f"Port: {self.device._ard_port}") lines.append(f"Baud: {self.device._ard_baud}") lines.append(f"pyserial: {'available' if ArduinoLayer.is_pyserial_available() else 'NOT INSTALLED'}") + # Show last raw lines received from Arduino + if hasattr(self.device._layer, "raw_lines"): + raw = self.device._layer.raw_lines + if raw: + lines.append("\nLast lines from Arduino:") + for r in raw: + lines.append(f" {r}") if self.device._last_error: lines.append(f"\nError:\n{self.device._last_error}") self._diag_box.setPlainText("\n".join(lines)) diff --git a/devices/digital_io.py b/devices/digital_io.py index 291baea..53014b5 100644 --- a/devices/digital_io.py +++ b/devices/digital_io.py @@ -206,9 +206,26 @@ class DigitalIODevice(BaseDevice): except Exception as e: print(f"[DigitalIODevice] NI write failed: {e}") elif self.backend == "arduino" and self._ard_layer: - self._ard_layer.write(channel_id, int(bool(value))) + # Map channel ID to Arduino pin name: + # do0→D5, do1→D6, do2→D7... (matches DIGITAL_OUT in firmware) + # Or the channel_id itself if it already looks like D5 + pin = channel_id if channel_id.upper().startswith("D") else f"D{5 + int(channel_id.replace('do',''))}" + self._ard_layer.digital_write(pin, int(bool(value))) return True + def pwm_channel(self, channel_id: str, duty_pct: float) -> bool: + """Send a PWM command to an Arduino output pin (0–100%).""" + if self.backend == "arduino" and self._ard_layer and not self.simulate: + pin = channel_id if channel_id.upper().startswith("D") else f"D{9 + int(channel_id.replace('do',''))}" + return self._ard_layer.pwm_write_pct(pin, duty_pct) + return False + + def set_parameter(self, name: str, value: Any) -> bool: + """Send a named parameter/setpoint to the Arduino.""" + if self.backend == "arduino" and self._ard_layer and not self.simulate: + return self._ard_layer.set_parameter(name, value) + return False + def get_config_widget(self) -> QWidget: return DigitalIOConfigWidget(self) -- cgit v1.2.3