diff options
Diffstat (limited to 'devices/digital_io.py')
| -rw-r--r-- | devices/digital_io.py | 19 |
1 files changed, 18 insertions, 1 deletions
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) |
