summaryrefslogtreecommitdiff
path: root/devices/analog_input.py
diff options
context:
space:
mode:
Diffstat (limited to 'devices/analog_input.py')
-rw-r--r--devices/analog_input.py26
1 files changed, 24 insertions, 2 deletions
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:<duty> (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))