summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorChristian Kolset <christian.kolset@gmail.com>2026-04-22 12:21:28 -0600
committerChristian Kolset <christian.kolset@gmail.com>2026-04-22 12:21:28 -0600
commit91101126e9d044adb8afa635cca1ab5d5a4c51a6 (patch)
tree5e8a5de10751e82e76092e37760cc984346f7eb7 /core
parent38ba9706e43c24a9d882b9d0d627812e01a30744 (diff)
Fixed saving profile to include devices and their configuration
Diffstat (limited to 'core')
-rw-r--r--core/__pycache__/acquisition.cpython-312.pycbin11068 -> 11417 bytes
-rw-r--r--core/__pycache__/profile.cpython-312.pycbin11779 -> 14026 bytes
-rw-r--r--core/acquisition.py5
-rw-r--r--core/profile.py56
4 files changed, 61 insertions, 0 deletions
diff --git a/core/__pycache__/acquisition.cpython-312.pyc b/core/__pycache__/acquisition.cpython-312.pyc
index 999e174..c593432 100644
--- a/core/__pycache__/acquisition.cpython-312.pyc
+++ b/core/__pycache__/acquisition.cpython-312.pyc
Binary files differ
diff --git a/core/__pycache__/profile.cpython-312.pyc b/core/__pycache__/profile.cpython-312.pyc
index c910e62..0fee9d9 100644
--- a/core/__pycache__/profile.cpython-312.pyc
+++ b/core/__pycache__/profile.cpython-312.pyc
Binary files differ
diff --git a/core/acquisition.py b/core/acquisition.py
index afccb56..57fda7e 100644
--- a/core/acquisition.py
+++ b/core/acquisition.py
@@ -102,6 +102,11 @@ class AcquisitionEngine(QObject):
def get_buffer(self, device_id: str, channel_id: str) -> Optional[ChannelBuffer]:
return self._buffers.get(device_id, {}).get(channel_id)
+ def clear_history(self):
+ for ch_map in self._buffers.values():
+ for buf in ch_map.values():
+ buf.clear()
+
# ── Start / stop ─────────────────────────────────────────────────────
def start(self):
diff --git a/core/profile.py b/core/profile.py
index b2d25b4..2a70370 100644
--- a/core/profile.py
+++ b/core/profile.py
@@ -69,6 +69,7 @@ class ProfileDerived:
class Profile:
name: str = "Untitled Profile"
version: str = "1.0"
+ devices: List[Dict] = field(default_factory=list)
controls: List[Dict] = field(default_factory=list)
channels: List[Dict] = field(default_factory=list)
pipelines: List[Dict] = field(default_factory=list)
@@ -85,6 +86,7 @@ class Profile:
return Profile(
name = d.get("name", ""),
version = d.get("version", "1.0"),
+ devices = d.get("devices", []),
controls = d.get("controls", []),
channels = d.get("channels", []),
pipelines = d.get("pipelines", []),
@@ -136,6 +138,11 @@ class ProfileManager:
) -> Profile:
p = Profile(name=profile_name)
+ # Devices
+ for dev in registry.all_instances():
+ if hasattr(dev, "get_save_config"):
+ p.devices.append(dev.get_save_config())
+
# Controls
p.controls = [spec.to_dict() for spec in control_specs]
@@ -197,6 +204,7 @@ class ProfileManager:
processor,
control_panel,
settings_ref: dict,
+ engine=None,
):
"""Apply a loaded profile to the live application state."""
from ui.control_editor import ControlSpec
@@ -205,6 +213,54 @@ class ProfileManager:
filter_from_dict,
)
+ # ── Devices ──────────────────────────────────────────────────────
+ _DEVICE_FACTORIES = {}
+ try:
+ from devices.analog_input import AnalogInputDevice
+ _DEVICE_FACTORIES["analog_input"] = AnalogInputDevice
+ except Exception:
+ pass
+ try:
+ from devices.digital_io import DigitalIODevice
+ _DEVICE_FACTORIES["digital_io"] = DigitalIODevice
+ except Exception:
+ pass
+ try:
+ from devices.serial_device import SerialDevice
+ _DEVICE_FACTORIES["serial"] = SerialDevice
+ except Exception:
+ pass
+
+ for dev_cfg in profile.devices:
+ dev_type = dev_cfg.get("device_type")
+ dev_id = dev_cfg.get("device_id")
+ if not dev_id:
+ continue
+ factory = _DEVICE_FACTORIES.get(dev_type)
+ if not factory:
+ print(f"[Profile] Unknown device type: {dev_type}")
+ continue
+ try:
+ # Replace existing device so saved config takes effect
+ existing = registry.get_instance(dev_id)
+ if existing is not None:
+ try:
+ existing.disconnect()
+ except Exception:
+ pass
+ registry.remove_instance(dev_id)
+ if engine is not None:
+ engine.remove_device(dev_id)
+
+ kwargs = {k: v for k, v in dev_cfg.items() if k != "device_type"}
+ dev = factory(**kwargs)
+ registry.add_instance(dev)
+ dev.connect()
+ if engine is not None:
+ engine.add_device(dev)
+ except Exception as e:
+ print(f"[Profile] Could not restore device {dev_id}: {e}")
+
# ── Channel overrides ────────────────────────────────────────────
for ch_data in profile.channels:
dev = registry.get_instance(ch_data["device_id"])