forked from M-Labs/artiq
moninj: display voltage in DACWidget
This commit is contained in:
parent
9386a7a16f
commit
81a0db0ebf
@ -333,22 +333,24 @@ class _DDSWidget(QtWidgets.QFrame):
|
||||
|
||||
|
||||
class _DACWidget(QtWidgets.QFrame):
|
||||
def __init__(self, dm, spi_channel, channel, title):
|
||||
def __init__(self, dm, spi_channel, channel, title, vref, offset_dacs):
|
||||
QtWidgets.QFrame.__init__(self)
|
||||
self.spi_channel = spi_channel
|
||||
self.channel = channel
|
||||
self.cur_value = 0
|
||||
self.cur_value = 0x8000;
|
||||
self.title = title
|
||||
self.vref = vref
|
||||
self.offset_dacs = offset_dacs
|
||||
|
||||
self.setFrameShape(QtWidgets.QFrame.Box)
|
||||
self.setFrameShadow(QtWidgets.QFrame.Raised)
|
||||
|
||||
grid = QtWidgets.QGridLayout()
|
||||
grid.setContentsMargins(0, 0, 0, 0)
|
||||
grid.setHorizontalSpacing(0)
|
||||
grid.setVerticalSpacing(0)
|
||||
grid.setContentsMargins(5, 5, 5, 5)
|
||||
grid.setHorizontalSpacing(5)
|
||||
grid.setVerticalSpacing(5)
|
||||
self.setLayout(grid)
|
||||
label = QtWidgets.QLabel("{} ch{}".format(title, channel))
|
||||
label = QtWidgets.QLabel("{}[{}]".format(title, channel))
|
||||
label.setAlignment(QtCore.Qt.AlignCenter)
|
||||
grid.addWidget(label, 1, 1)
|
||||
|
||||
@ -362,9 +364,13 @@ class _DACWidget(QtWidgets.QFrame):
|
||||
|
||||
self.refresh_display()
|
||||
|
||||
def mu_to_voltage(self, code):
|
||||
voltage = ((code - self.offset_dacs * 0x4) / (1 << 16)) * (4. * self.vref)
|
||||
return voltage
|
||||
|
||||
def refresh_display(self):
|
||||
self.value.setText("<font size=\"4\">{:.3f}</font><font size=\"2\"> %</font>"
|
||||
.format(self.cur_value * 100 / 2**16))
|
||||
self.value.setText("<font size=\"4\">{:+.3f} V</font>"
|
||||
.format(self.mu_to_voltage(self.cur_value)))
|
||||
|
||||
def sort_key(self):
|
||||
return (2, self.spi_channel, self.channel)
|
||||
@ -373,7 +379,7 @@ class _DACWidget(QtWidgets.QFrame):
|
||||
return (self.title, self.channel)
|
||||
|
||||
def to_model_path(self):
|
||||
return "dac/{} ch{}".format(self.title, self.channel)
|
||||
return "dac/{}[{}]".format(self.title, self.channel)
|
||||
|
||||
|
||||
_WidgetDesc = namedtuple("_WidgetDesc", "uid comment cls arguments")
|
||||
@ -426,9 +432,11 @@ def setup_from_ddb(ddb):
|
||||
while isinstance(spi_device, str):
|
||||
spi_device = ddb[spi_device]
|
||||
spi_channel = spi_device["arguments"]["channel"]
|
||||
vref = v["arguments"].get("vref", 5.)
|
||||
offset_dacs = v["arguments"].get("offset_dacs", 8192)
|
||||
for channel in range(32):
|
||||
widget = _WidgetDesc((k, channel), comment, _DACWidget,
|
||||
(spi_channel, channel, k))
|
||||
(spi_channel, channel, k, vref, offset_dacs))
|
||||
description.add(widget)
|
||||
elif v["type"] == "controller" and k == "core_moninj":
|
||||
mi_addr = v["host"]
|
||||
|
Loading…
Reference in New Issue
Block a user