mirror of https://github.com/m-labs/artiq.git
dashboard: add DAC monitoring widgets
This commit is contained in:
parent
bb6e7618bb
commit
e80a527f2e
|
@ -1,5 +1,6 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
|
from itertools import chain
|
||||||
|
|
||||||
from PyQt5 import QtCore, QtWidgets, QtGui
|
from PyQt5 import QtCore, QtWidgets, QtGui
|
||||||
|
|
||||||
|
@ -130,13 +131,10 @@ class _TTLWidget(QtWidgets.QFrame):
|
||||||
return self.channel
|
return self.channel
|
||||||
|
|
||||||
|
|
||||||
class _DDSWidget(QtWidgets.QFrame):
|
class _SimpleDisplayWidget(QtWidgets.QFrame):
|
||||||
def __init__(self, bus_channel, channel, title):
|
def __init__(self, title):
|
||||||
QtWidgets.QFrame.__init__(self)
|
QtWidgets.QFrame.__init__(self)
|
||||||
|
|
||||||
self.bus_channel = bus_channel
|
|
||||||
self.channel = channel
|
|
||||||
|
|
||||||
self.setFrameShape(QtWidgets.QFrame.Box)
|
self.setFrameShape(QtWidgets.QFrame.Box)
|
||||||
self.setFrameShadow(QtWidgets.QFrame.Raised)
|
self.setFrameShadow(QtWidgets.QFrame.Raised)
|
||||||
|
|
||||||
|
@ -159,9 +157,22 @@ class _DDSWidget(QtWidgets.QFrame):
|
||||||
grid.setRowStretch(2, 0)
|
grid.setRowStretch(2, 0)
|
||||||
grid.setRowStretch(3, 1)
|
grid.setRowStretch(3, 1)
|
||||||
|
|
||||||
self.cur_frequency = 0
|
|
||||||
self.refresh_display()
|
self.refresh_display()
|
||||||
|
|
||||||
|
def refresh_display(self):
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def sort_key(self):
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
|
class _DDSWidget(_SimpleDisplayWidget):
|
||||||
|
def __init__(self, bus_channel, channel, title):
|
||||||
|
self.bus_channel = bus_channel
|
||||||
|
self.channel = channel
|
||||||
|
self.cur_frequency = 0
|
||||||
|
_SimpleDisplayWidget.__init__(self, title)
|
||||||
|
|
||||||
def refresh_display(self):
|
def refresh_display(self):
|
||||||
self.value.setText("<font size=\"4\">{:.7f}</font><font size=\"2\"> MHz</font>"
|
self.value.setText("<font size=\"4\">{:.7f}</font><font size=\"2\"> MHz</font>"
|
||||||
.format(self.cur_frequency/1e6))
|
.format(self.cur_frequency/1e6))
|
||||||
|
@ -170,6 +181,21 @@ class _DDSWidget(QtWidgets.QFrame):
|
||||||
return (self.bus_channel, self.channel)
|
return (self.bus_channel, self.channel)
|
||||||
|
|
||||||
|
|
||||||
|
class _DACWidget(_SimpleDisplayWidget):
|
||||||
|
def __init__(self, spi_channel, channel, title):
|
||||||
|
self.spi_channel = spi_channel
|
||||||
|
self.channel = channel
|
||||||
|
self.cur_value = 0
|
||||||
|
_SimpleDisplayWidget.__init__(self, "{} ch{}".format(title, channel))
|
||||||
|
|
||||||
|
def refresh_display(self):
|
||||||
|
self.value.setText("<font size=\"4\">{:.3f}</font><font size=\"2\"> %</font>"
|
||||||
|
.format(self.cur_value*100/2**16))
|
||||||
|
|
||||||
|
def sort_key(self):
|
||||||
|
return (self.spi_channel, self.channel)
|
||||||
|
|
||||||
|
|
||||||
class _DeviceManager:
|
class _DeviceManager:
|
||||||
def __init__(self, init):
|
def __init__(self, init):
|
||||||
self.core_addr = None
|
self.core_addr = None
|
||||||
|
@ -184,6 +210,9 @@ class _DeviceManager:
|
||||||
self.dds_cb = lambda: None
|
self.dds_cb = lambda: None
|
||||||
self.dds_widgets = dict()
|
self.dds_widgets = dict()
|
||||||
self.dds_widgets_by_channel = dict()
|
self.dds_widgets_by_channel = dict()
|
||||||
|
self.dac_cb = lambda: None
|
||||||
|
self.dac_widgets = dict()
|
||||||
|
self.dac_widgets_by_channel = dict()
|
||||||
for k, v in init.items():
|
for k, v in init.items():
|
||||||
self[k] = v
|
self[k] = v
|
||||||
|
|
||||||
|
@ -192,11 +221,13 @@ class _DeviceManager:
|
||||||
del self[k]
|
del self[k]
|
||||||
if k in self.dds_widgets:
|
if k in self.dds_widgets:
|
||||||
del self[k]
|
del self[k]
|
||||||
|
if k in self.dac_widgets:
|
||||||
|
del self[k]
|
||||||
if not isinstance(v, dict):
|
if not isinstance(v, dict):
|
||||||
return
|
return
|
||||||
|
widgets = []
|
||||||
try:
|
try:
|
||||||
if v["type"] == "local":
|
if v["type"] == "local":
|
||||||
widget = None
|
|
||||||
if k == "core":
|
if k == "core":
|
||||||
self.core_addr = v["arguments"]["host"]
|
self.core_addr = v["arguments"]["host"]
|
||||||
self.new_core_addr.set()
|
self.new_core_addr.set()
|
||||||
|
@ -209,6 +240,7 @@ class _DeviceManager:
|
||||||
self.ttl_widgets_by_channel[channel] = widget
|
self.ttl_widgets_by_channel[channel] = widget
|
||||||
self.ttl_cb()
|
self.ttl_cb()
|
||||||
self.setup_ttl_monitoring(True, channel)
|
self.setup_ttl_monitoring(True, channel)
|
||||||
|
widgets.append(widget)
|
||||||
elif (v["module"] == "artiq.coredevice.dds"
|
elif (v["module"] == "artiq.coredevice.dds"
|
||||||
and v["class"] == "DDSGroupAD9914"):
|
and v["class"] == "DDSGroupAD9914"):
|
||||||
self.dds_sysclk = v["arguments"]["sysclk"]
|
self.dds_sysclk = v["arguments"]["sysclk"]
|
||||||
|
@ -221,10 +253,22 @@ class _DeviceManager:
|
||||||
self.dds_widgets_by_channel[(bus_channel, channel)] = widget
|
self.dds_widgets_by_channel[(bus_channel, channel)] = widget
|
||||||
self.dds_cb()
|
self.dds_cb()
|
||||||
self.setup_dds_monitoring(True, bus_channel, channel)
|
self.setup_dds_monitoring(True, bus_channel, channel)
|
||||||
if widget is not None and "comment" in v:
|
widgets.append(widget)
|
||||||
widget.setToolTip(v["comment"])
|
elif (v["module"] == "artiq.coredevice.ad5360"
|
||||||
|
and v["class"] == "AD5360"):
|
||||||
|
spi_channel = 27 # TODO/FIXME
|
||||||
|
for channel in range(32):
|
||||||
|
widget = _DACWidget(spi_channel, channel, k)
|
||||||
|
self.dac_widgets_by_channel[(spi_channel, channel)] = widget
|
||||||
|
self.setup_dds_monitoring(True, spi_channel, channel)
|
||||||
|
widgets.append(widget)
|
||||||
|
self.dac_widgets[k+str(channel)] = widgets
|
||||||
|
self.dac_cb()
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
if "comment" in v:
|
||||||
|
for widget in widgets:
|
||||||
|
widget.setToolTip(v["comment"])
|
||||||
|
|
||||||
def __delitem__(self, k):
|
def __delitem__(self, k):
|
||||||
if k in self.ttl_widgets:
|
if k in self.ttl_widgets:
|
||||||
|
@ -241,6 +285,13 @@ class _DeviceManager:
|
||||||
del self.dds_widgets_by_channel[(widget.bus_channel, widget.channel)]
|
del self.dds_widgets_by_channel[(widget.bus_channel, widget.channel)]
|
||||||
del self.dds_widgets[k]
|
del self.dds_widgets[k]
|
||||||
self.dds_cb()
|
self.dds_cb()
|
||||||
|
if k in self.dac_widgets:
|
||||||
|
for widget in self.dac_widgets[k]:
|
||||||
|
self.setup_dac_monitoring(False, widget.spi_channel, widget.channel)
|
||||||
|
widget.deleteLater()
|
||||||
|
del self.dac_widgets_by_channel[(widget.spi_channel, widget.channel)]
|
||||||
|
del self.dac_widgets[k]
|
||||||
|
self.dds_cb()
|
||||||
|
|
||||||
def ttl_set_mode(self, channel, mode):
|
def ttl_set_mode(self, channel, mode):
|
||||||
if self.core_connection is not None:
|
if self.core_connection is not None:
|
||||||
|
@ -276,6 +327,10 @@ class _DeviceManager:
|
||||||
if self.core_connection is not None:
|
if self.core_connection is not None:
|
||||||
self.core_connection.monitor(enable, bus_channel, channel)
|
self.core_connection.monitor(enable, bus_channel, channel)
|
||||||
|
|
||||||
|
def setup_dac_monitoring(self, enable, spi_channel, channel):
|
||||||
|
if self.core_connection is not None:
|
||||||
|
self.core_connection.monitor(enable, spi_channel, channel)
|
||||||
|
|
||||||
def monitor_cb(self, channel, probe, value):
|
def monitor_cb(self, channel, probe, value):
|
||||||
if channel in self.ttl_widgets_by_channel:
|
if channel in self.ttl_widgets_by_channel:
|
||||||
widget = self.ttl_widgets_by_channel[channel]
|
widget = self.ttl_widgets_by_channel[channel]
|
||||||
|
@ -288,6 +343,10 @@ class _DeviceManager:
|
||||||
widget = self.dds_widgets_by_channel[(channel, probe)]
|
widget = self.dds_widgets_by_channel[(channel, probe)]
|
||||||
widget.cur_frequency = value*self.dds_sysclk/2**32
|
widget.cur_frequency = value*self.dds_sysclk/2**32
|
||||||
widget.refresh_display()
|
widget.refresh_display()
|
||||||
|
if (channel, probe) in self.dac_widgets_by_channel:
|
||||||
|
widget = self.dac_widgets_by_channel[(channel, probe)]
|
||||||
|
widget.cur_value = value
|
||||||
|
widget.refresh_display()
|
||||||
|
|
||||||
def injection_status_cb(self, channel, override, value):
|
def injection_status_cb(self, channel, override, value):
|
||||||
if channel in self.ttl_widgets_by_channel:
|
if channel in self.ttl_widgets_by_channel:
|
||||||
|
@ -312,6 +371,8 @@ class _DeviceManager:
|
||||||
self.setup_ttl_monitoring(True, ttl_channel)
|
self.setup_ttl_monitoring(True, ttl_channel)
|
||||||
for bus_channel, channel in self.dds_widgets_by_channel.keys():
|
for bus_channel, channel in self.dds_widgets_by_channel.keys():
|
||||||
self.setup_dds_monitoring(True, bus_channel, channel)
|
self.setup_dds_monitoring(True, bus_channel, channel)
|
||||||
|
for spi_channel, channel in self.dac_widgets_by_channel.keys():
|
||||||
|
self.setup_dac_monitoring(True, spi_channel, channel)
|
||||||
|
|
||||||
async def close(self):
|
async def close(self):
|
||||||
self.core_connector_task.cancel()
|
self.core_connector_task.cancel()
|
||||||
|
@ -339,8 +400,8 @@ class _MonInjDock(QtWidgets.QDockWidget):
|
||||||
grid_widget = QtWidgets.QWidget()
|
grid_widget = QtWidgets.QWidget()
|
||||||
grid_widget.setLayout(grid)
|
grid_widget.setLayout(grid)
|
||||||
|
|
||||||
for _, w in sorted(widgets, key=lambda i: i[1].sort_key()):
|
for widget in sorted(widgets, key=lambda w: w.sort_key()):
|
||||||
grid.addWidget(w)
|
grid.addWidget(widget)
|
||||||
|
|
||||||
scroll_area.setWidgetResizable(True)
|
scroll_area.setWidgetResizable(True)
|
||||||
scroll_area.setWidget(grid_widget)
|
scroll_area.setWidget(grid_widget)
|
||||||
|
@ -350,6 +411,7 @@ class MonInj:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.ttl_dock = _MonInjDock("TTL")
|
self.ttl_dock = _MonInjDock("TTL")
|
||||||
self.dds_dock = _MonInjDock("DDS")
|
self.dds_dock = _MonInjDock("DDS")
|
||||||
|
self.dac_dock = _MonInjDock("DAC")
|
||||||
|
|
||||||
self.subscriber = Subscriber("devices", self.init_devices)
|
self.subscriber = Subscriber("devices", self.init_devices)
|
||||||
self.dm = None
|
self.dm = None
|
||||||
|
@ -365,9 +427,12 @@ class MonInj:
|
||||||
def init_devices(self, d):
|
def init_devices(self, d):
|
||||||
self.dm = _DeviceManager(d)
|
self.dm = _DeviceManager(d)
|
||||||
self.dm.ttl_cb = lambda: self.ttl_dock.layout_widgets(
|
self.dm.ttl_cb = lambda: self.ttl_dock.layout_widgets(
|
||||||
self.dm.ttl_widgets.items())
|
self.dm.ttl_widgets.values())
|
||||||
self.dm.dds_cb = lambda: self.dds_dock.layout_widgets(
|
self.dm.dds_cb = lambda: self.dds_dock.layout_widgets(
|
||||||
self.dm.dds_widgets.items())
|
self.dm.dds_widgets.values())
|
||||||
|
self.dm.dac_cb = lambda: self.dac_dock.layout_widgets(
|
||||||
|
chain(*self.dm.dac_widgets.values()))
|
||||||
self.dm.ttl_cb()
|
self.dm.ttl_cb()
|
||||||
self.dm.dds_cb()
|
self.dm.dds_cb()
|
||||||
|
self.dm.dac_cb()
|
||||||
return self.dm
|
return self.dm
|
||||||
|
|
|
@ -185,7 +185,7 @@ def main():
|
||||||
# lay out docks
|
# lay out docks
|
||||||
right_docks = [
|
right_docks = [
|
||||||
d_explorer, d_shortcuts,
|
d_explorer, d_shortcuts,
|
||||||
d_ttl_dds.ttl_dock, d_ttl_dds.dds_dock,
|
d_ttl_dds.ttl_dock, d_ttl_dds.dds_dock, d_ttl_dds.dac_dock,
|
||||||
d_datasets, d_applets
|
d_datasets, d_applets
|
||||||
]
|
]
|
||||||
main_window.addDockWidget(QtCore.Qt.RightDockWidgetArea, right_docks[0])
|
main_window.addDockWidget(QtCore.Qt.RightDockWidgetArea, right_docks[0])
|
||||||
|
|
Loading…
Reference in New Issue