gui/moninj: fix problems with dynamic modification of DDB

This commit is contained in:
Sebastien Bourdeauducq 2015-10-04 17:55:57 +08:00
parent 0e3927b01a
commit 168af9589e
1 changed files with 20 additions and 10 deletions

View File

@ -23,9 +23,9 @@ _mode_enc = {
class _TTLWidget(QtGui.QFrame): class _TTLWidget(QtGui.QFrame):
def __init__(self, send_to_device, channel, force_out, title): def __init__(self, channel, send_to_device, force_out, title):
self.send_to_device = send_to_device
self.channel = channel self.channel = channel
self.send_to_device = send_to_device
self.force_out = force_out self.force_out = force_out
QtGui.QFrame.__init__(self) QtGui.QFrame.__init__(self)
@ -119,7 +119,8 @@ class _TTLWidget(QtGui.QFrame):
class _DDSWidget(QtGui.QFrame): class _DDSWidget(QtGui.QFrame):
def __init__(self, sysclk, title): def __init__(self, channel, sysclk, title):
self.channel = channel
self.sysclk = sysclk self.sysclk = sysclk
QtGui.QFrame.__init__(self) QtGui.QFrame.__init__(self)
@ -163,9 +164,11 @@ class _DeviceManager:
self[k] = v self[k] = v
def __setitem__(self, k, v): def __setitem__(self, k, v):
self.ddb[k] = v
if k in self.ttl_widgets: if k in self.ttl_widgets:
del self[k] del self[k]
if k in self.dds_widgets:
del self[k]
self.ddb[k] = v
if not isinstance(v, dict): if not isinstance(v, dict):
return return
try: try:
@ -176,14 +179,15 @@ class _DeviceManager:
if v["module"] == "artiq.coredevice.ttl": if v["module"] == "artiq.coredevice.ttl":
channel = v["arguments"]["channel"] channel = v["arguments"]["channel"]
force_out = v["class"] == "TTLOut" force_out = v["class"] == "TTLOut"
self.ttl_widgets[channel] = _TTLWidget( self.ttl_widgets[k] = _TTLWidget(
self.send_to_device, channel, force_out, title) channel, self.send_to_device, force_out, title)
self.ttl_cb() self.ttl_cb()
if (v["module"] == "artiq.coredevice.dds" if (v["module"] == "artiq.coredevice.dds"
and v["class"] in {"AD9858", "AD9914"}): and v["class"] in {"AD9858", "AD9914"}):
channel = v["arguments"]["channel"] channel = v["arguments"]["channel"]
sysclk = v["arguments"]["sysclk"] sysclk = v["arguments"]["sysclk"]
self.dds_widgets[channel] = _DDSWidget(sysclk, title) self.dds_widgets[channel] = _DDSWidget(
channel, sysclk, title)
self.dds_cb() self.dds_cb()
except KeyError: except KeyError:
pass pass
@ -191,8 +195,13 @@ class _DeviceManager:
def __delitem__(self, k): def __delitem__(self, k):
del self.ddb[k] del self.ddb[k]
if k in self.ttl_widgets: if k in self.ttl_widgets:
self.ttl_widgets[k].deleteLater()
del self.ttl_widgets[k] del self.ttl_widgets[k]
self.ttl_cb() self.ttl_cb()
if k in self.dds_widgets:
self.dds_widgets[k].deleteLater()
del self.dds_widgets[k]
self.dds_cb()
def get_core_addr(self): def get_core_addr(self):
try: try:
@ -261,16 +270,17 @@ class MonInj(TaskObject):
try: try:
ttl_levels, ttl_oes, ttl_overrides = \ ttl_levels, ttl_oes, ttl_overrides = \
struct.unpack(">QQQ", data[:8*3]) struct.unpack(">QQQ", data[:8*3])
for channel, w in self.dm.ttl_widgets.items(): for w in self.dm.ttl_widgets.values():
channel = w.channel
w.set_value(ttl_levels & (1 << channel), w.set_value(ttl_levels & (1 << channel),
ttl_oes & (1 << channel), ttl_oes & (1 << channel),
ttl_overrides & (1 << channel)) ttl_overrides & (1 << channel))
dds_data = data[8*3:] dds_data = data[8*3:]
ndds = len(dds_data)//4 ndds = len(dds_data)//4
ftws = struct.unpack(">" + "I"*ndds, dds_data) ftws = struct.unpack(">" + "I"*ndds, dds_data)
for channel, w in self.dm.dds_widgets.items(): for w in self.dm.dds_widgets.values():
try: try:
ftw = ftws[channel] ftw = ftws[w.channel]
except KeyError: except KeyError:
pass pass
else: else: