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