From 91101126e9d044adb8afa635cca1ab5d5a4c51a6 Mon Sep 17 00:00:00 2001 From: Christian Kolset Date: Wed, 22 Apr 2026 12:21:28 -0600 Subject: Fixed saving profile to include devices and their configuration --- ui/control_panel.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'ui/control_panel.py') diff --git a/ui/control_panel.py b/ui/control_panel.py index efd4f17..7a3e416 100644 --- a/ui/control_panel.py +++ b/ui/control_panel.py @@ -43,16 +43,24 @@ class ControlWidget(QFrame): def __init__(self, title: str, icon: str = "⚙", device_id: str = "", channel_id: str = "", - registry: Optional[DeviceRegistry] = None): + registry: Optional[DeviceRegistry] = None, + active_low: bool = False): super().__init__() self.title = title self.icon = icon self.device_id = device_id self.channel_id = channel_id self.registry = registry + self.active_low = active_low self.setObjectName("controlWidget") self._build_frame() + def _logic_level(self, enabled: bool) -> float: + """Map logical ON/OFF to electrical level, respecting active-low outputs.""" + if self.active_low: + return 0.0 if enabled else 1.0 + return 1.0 if enabled else 0.0 + def _build_frame(self): """Build the common outer frame; subclasses fill self._body.""" outer = QVBoxLayout(self) @@ -155,7 +163,7 @@ class OnOffSwitch(ControlWidget): # Re-polish so QSS picks up new objectName for w in (self._btn, self._indicator, self._state_lbl): w.style().unpolish(w); w.style().polish(w) - self._write(1.0 if checked else 0.0) + self._write(self._logic_level(checked)) # ══════════════════════════════════════════════════════════════════════════════ @@ -568,6 +576,7 @@ class ControlPanel(QWidget): spec = ControlSpec( title=widget.title, icon=widget.icon, device_id=widget.device_id, channel_id=widget.channel_id, + active_low=getattr(widget, "active_low", False), ) wrapper = self._make_wrapper(widget, spec) self._widgets.append(widget) @@ -673,6 +682,7 @@ def _build_widget_from_spec(spec, registry: DeviceRegistry) -> Optional[ControlW device_id=spec.device_id, channel_id=spec.channel_id, registry=registry, + active_low=getattr(spec, "active_low", False), ) t = spec.control_type ttl = spec.title -- cgit v1.2.3