moninj: rename widget to handler

This commit is contained in:
Simon Renblad 2024-04-15 16:18:36 +08:00
parent acd7ea3efb
commit 1c506973a3

View File

@ -352,7 +352,7 @@ class _DACWidget(QtWidgets.QFrame):
return (self.spi_channel, self.channel)
_WidgetDesc = namedtuple("_WidgetDesc", "uid comment cls arguments")
_HandlerDesc = namedtuple("_HandlerDesc", "uid comment cls arguments")
def setup_from_ddb(ddb):
@ -371,16 +371,16 @@ def setup_from_ddb(ddb):
continue
channel = v["arguments"]["channel"]
force_out = v["class"] == "TTLOut"
widget = _WidgetDesc(k, comment, _TTLWidget, (channel, force_out, k))
description.add(widget)
handler = _HandlerDesc(k, comment, _TTLWidget, (channel, force_out, k))
description.add(handler)
elif (v["module"] == "artiq.coredevice.ad9914" and v["class"] == "AD9914"):
bus_channel = v["arguments"]["bus_channel"]
channel = v["arguments"]["channel"]
dds_sysclk = v["arguments"]["sysclk"]
model = _DDSModel(v["class"], dds_sysclk)
widget = _WidgetDesc(k, comment, _DDSWidget,
(k, bus_channel, channel, model))
description.add(widget)
handler = _HandlerDesc(k, comment, _DDSWidget,
(k, bus_channel, channel, model))
description.add(handler)
elif (v["module"] == "artiq.coredevice.ad9910" and v["class"] == "AD9910") or \
(v["module"] == "artiq.coredevice.ad9912" and v["class"] == "AD9912"):
channel = v["arguments"]["chip_select"] - 4
@ -393,9 +393,9 @@ def setup_from_ddb(ddb):
refclk = ddb[dds_cpld]["arguments"]["refclk"]
clk_div = v["arguments"].get("clk_div", 0)
model = _DDSModel(v["class"], refclk, dds_cpld, pll, clk_div)
widget = _WidgetDesc(k, comment, _DDSWidget,
(k, bus_channel, channel, model))
description.add(widget)
handler = _HandlerDesc(k, comment, _DDSWidget,
(k, bus_channel, channel, model))
description.add(handler)
elif (v["module"] == "artiq.coredevice.ad53xx" and v["class"] == "AD53xx") or \
(v["module"] == "artiq.coredevice.zotino" and v["class"] == "Zotino"):
spi_device = v["arguments"]["spi_device"]
@ -404,9 +404,9 @@ def setup_from_ddb(ddb):
spi_device = ddb[spi_device]
spi_channel = spi_device["arguments"]["channel"]
for channel in range(32):
widget = _WidgetDesc((k, channel), comment, _DACWidget,
(spi_channel, channel, k))
description.add(widget)
handler = _HandlerDesc((k, channel), comment, _DACWidget,
(spi_channel, channel, k))
description.add(handler)
elif v["type"] == "controller" and k == "core_moninj":
mi_addr = v["host"]
mi_port = v.get("port_proxy", 1383)
@ -427,15 +427,15 @@ class _DeviceManager:
self.ddb = dict()
self.description = set()
self.widgets_by_uid = dict()
self.handlers_by_uid = dict()
self.dds_sysclk = 0
self.ttl_cb = lambda: None
self.ttl_widgets = dict()
self.ttl_handlers = dict()
self.dds_cb = lambda: None
self.dds_widgets = dict()
self.dds_handlers = dict()
self.dac_cb = lambda: None
self.dac_widgets = dict()
self.dac_handlers = dict()
def init_ddb(self, ddb):
self.ddb = ddb
@ -449,45 +449,45 @@ class _DeviceManager:
self.reconnect_mi.set()
for to_remove in self.description - description:
widget = self.widgets_by_uid[to_remove.uid]
del self.widgets_by_uid[to_remove.uid]
handler = self.handlers_by_uid[to_remove.uid]
del self.handlers_by_uid[to_remove.uid]
if isinstance(widget, _TTLWidget):
self.setup_ttl_monitoring(False, widget.channel)
widget.deleteLater()
del self.ttl_widgets[widget.channel]
if isinstance(handler, _TTLWidget):
self.setup_ttl_monitoring(False, handler.channel)
handler.deleteLater()
del self.ttl_handlers[handler.channel]
self.ttl_cb()
elif isinstance(widget, _DDSWidget):
self.setup_dds_monitoring(False, widget.bus_channel, widget.channel)
widget.deleteLater()
del self.dds_widgets[(widget.bus_channel, widget.channel)]
elif isinstance(handler, _DDSWidget):
self.setup_dds_monitoring(False, handler.bus_channel, handler.channel)
handler.deleteLater()
del self.dds_handlers[(handler.bus_channel, handler.channel)]
self.dds_cb()
elif isinstance(widget, _DACWidget):
self.setup_dac_monitoring(False, widget.spi_channel, widget.channel)
widget.deleteLater()
del self.dac_widgets[(widget.spi_channel, widget.channel)]
elif isinstance(handler, _DACWidget):
self.setup_dac_monitoring(False, handler.spi_channel, handler.channel)
handler.deleteLater()
del self.dac_handlers[(handler.spi_channel, handler.channel)]
self.dac_cb()
else:
raise ValueError
for to_add in description - self.description:
widget = to_add.cls(self, *to_add.arguments)
handler = to_add.cls(self, *to_add.arguments)
if to_add.comment is not None:
widget.setToolTip(to_add.comment)
self.widgets_by_uid[to_add.uid] = widget
handler.setToolTip(to_add.comment)
self.handlers_by_uid[to_add.uid] = handler
if isinstance(widget, _TTLWidget):
self.ttl_widgets[widget.channel] = widget
if isinstance(handler, _TTLWidget):
self.ttl_handlers[handler.channel] = handler
self.ttl_cb()
self.setup_ttl_monitoring(True, widget.channel)
elif isinstance(widget, _DDSWidget):
self.dds_widgets[(widget.bus_channel, widget.channel)] = widget
self.setup_ttl_monitoring(True, handler.channel)
elif isinstance(handler, _DDSWidget):
self.dds_handlers[(handler.bus_channel, handler.channel)] = handler
self.dds_cb()
self.setup_dds_monitoring(True, widget.bus_channel, widget.channel)
elif isinstance(widget, _DACWidget):
self.dac_widgets[(widget.spi_channel, widget.channel)] = widget
self.setup_dds_monitoring(True, handler.bus_channel, handler.channel)
elif isinstance(handler, _DACWidget):
self.dac_handlers[(handler.spi_channel, handler.channel)] = handler
self.dac_cb()
self.setup_dac_monitoring(True, widget.spi_channel, widget.channel)
self.setup_dac_monitoring(True, handler.spi_channel, handler.channel)
else:
raise ValueError
@ -495,26 +495,26 @@ class _DeviceManager:
def ttl_set_mode(self, channel, mode):
if self.mi_connection is not None:
widget = self.ttl_widgets[channel]
handler = self.ttl_handlers[channel]
if mode == "0":
widget.cur_override = True
widget.cur_level = False
handler.cur_override = True
handler.cur_level = False
self.mi_connection.inject(channel, TTLOverride.level.value, 0)
self.mi_connection.inject(channel, TTLOverride.oe.value, 1)
self.mi_connection.inject(channel, TTLOverride.en.value, 1)
elif mode == "1":
widget.cur_override = True
widget.cur_level = True
handler.cur_override = True
handler.cur_level = True
self.mi_connection.inject(channel, TTLOverride.level.value, 1)
self.mi_connection.inject(channel, TTLOverride.oe.value, 1)
self.mi_connection.inject(channel, TTLOverride.en.value, 1)
elif mode == "exp":
widget.cur_override = False
handler.cur_override = False
self.mi_connection.inject(channel, TTLOverride.en.value, 0)
else:
raise ValueError
# override state may have changed
widget.refresh_display()
handler.refresh_display()
async def _submit_by_content(self, content, class_name, title):
expid = {
@ -662,30 +662,30 @@ class _DeviceManager:
self.mi_connection.monitor_probe(enable, spi_channel, channel)
def monitor_cb(self, channel, probe, value):
if channel in self.ttl_widgets:
widget = self.ttl_widgets[channel]
if channel in self.ttl_handlers:
handler = self.ttl_handlers[channel]
if probe == TTLProbe.level.value:
widget.cur_level = bool(value)
handler.cur_level = bool(value)
elif probe == TTLProbe.oe.value:
widget.cur_oe = bool(value)
widget.refresh_display()
elif (channel, probe) in self.dds_widgets:
widget = self.dds_widgets[(channel, probe)]
widget.dds_model.monitor_update(probe, value)
widget.refresh_display()
elif (channel, probe) in self.dac_widgets:
widget = self.dac_widgets[(channel, probe)]
widget.cur_value = value
widget.refresh_display()
handler.cur_oe = bool(value)
handler.refresh_display()
elif (channel, probe) in self.dds_handlers:
handler = self.dds_handlers[(channel, probe)]
handler.dds_model.monitor_update(probe, value)
handler.refresh_display()
elif (channel, probe) in self.dac_handlers:
handler = self.dac_handlers[(channel, probe)]
handler.cur_value = value
handler.refresh_display()
def injection_status_cb(self, channel, override, value):
if channel in self.ttl_widgets:
widget = self.ttl_widgets[channel]
if channel in self.ttl_handlers:
handler = self.ttl_handlers[channel]
if override == TTLOverride.en.value:
widget.cur_override = bool(value)
handler.cur_override = bool(value)
if override == TTLOverride.level.value:
widget.cur_override_level = bool(value)
widget.refresh_display()
handler.cur_override_level = bool(value)
handler.refresh_display()
def disconnect_cb(self):
logger.error("lost connection to moninj")
@ -711,11 +711,11 @@ class _DeviceManager:
logger.info("ARTIQ dashboard connected to moninj (%s)",
self.mi_addr)
self.mi_connection = new_mi_connection
for ttl_channel in self.ttl_widgets.keys():
for ttl_channel in self.ttl_handlers.keys():
self.setup_ttl_monitoring(True, ttl_channel)
for bus_channel, channel in self.dds_widgets.keys():
for bus_channel, channel in self.dds_handlers.keys():
self.setup_dds_monitoring(True, bus_channel, channel)
for spi_channel, channel in self.dac_widgets.keys():
for spi_channel, channel in self.dac_handlers.keys():
self.setup_dac_monitoring(True, spi_channel, channel)
async def close(self):
@ -757,9 +757,9 @@ class MonInj:
self.dac_dock = _MonInjDock("DAC")
self.dm = _DeviceManager(schedule_ctl)
self.dm.ttl_cb = lambda: self.ttl_dock.layout_widgets(self.dm.ttl_widgets.values())
self.dm.dds_cb = lambda: self.dds_dock.layout_widgets(self.dm.dds_widgets.values())
self.dm.dac_cb = lambda: self.dac_dock.layout_widgets(self.dm.dac_widgets.values())
self.dm.ttl_cb = lambda: self.ttl_dock.layout_widgets(self.dm.ttl_handlers.values())
self.dm.dds_cb = lambda: self.dds_dock.layout_widgets(self.dm.dds_handlers.values())
self.dm.dac_cb = lambda: self.dac_dock.layout_widgets(self.dm.dac_handlers.values())
async def stop(self):
if self.dm is not None: