forked from M-Labs/artiq
1
0
Fork 0

waveform: add AnalogWaveform

This commit is contained in:
Simon Renblad 2024-01-26 15:08:49 +08:00 committed by Sébastien Bourdeauducq
parent 2d8de3ed93
commit cbe7ac1cfd
1 changed files with 47 additions and 0 deletions

View File

@ -221,6 +221,23 @@ class BitWaveform(_BaseWaveform):
self.plot_data_item.setData(x=[], y=[]) self.plot_data_item.setData(x=[], y=[])
class AnalogWaveform(_BaseWaveform):
def __init__(self, name, width, parent=None):
_BaseWaveform.__init__(self, name, width, parent)
def onDataChange(self, data):
try:
x_data, y_data = zip(*data)
self.plot_data_item.setData(x=x_data, y=y_data)
max_y = max(y_data)
min_y = min(y_data)
self.plot_item.setRange(yRange=(min_y, max_y), padding=0.1)
except:
logger.error(
'Error when displaying waveform: {}'.format(self.name), exc_info=True)
self.plot_data_item.setData(x=[], y=[])
class BitVectorWaveform(_BaseWaveform): class BitVectorWaveform(_BaseWaveform):
def __init__(self, name, width, parent=None): def __init__(self, name, width, parent=None):
_BaseWaveform.__init__(self, name, width, parent) _BaseWaveform.__init__(self, name, width, parent)
@ -269,6 +286,36 @@ class BitVectorWaveform(_BaseWaveform):
self.plot_data_item.setData(x=[], y=[]) self.plot_data_item.setData(x=[], y=[])
class LogWaveform(_BaseWaveform):
def __init__(self, name, width, parent=None):
_BaseWaveform.__init__(self, name, width, parent)
self.plot_data_item.opts['pen'] = None
self.plot_data_item.opts['symbol'] = 'x'
def onDataChange(self, data):
try:
x_data = zip(*data)[0]
self.plot_data_item.setData(
x=x_data, y=np.ones(len(x_data)))
old_msg = ""
old_x = 0
for x, msg in data:
if x == old_x:
old_msg += "\n" + msg
else:
lbl = pg.TextItem(old_msg)
self.addItem(lbl)
lbl.setPos(old_x, 1)
old_msg = msg
old_x = x
lbl = pg.TextItem(old_msg)
self.addItem(lbl)
lbl.setPos(old_x, 1)
except:
logger.error('Error when displaying waveform: {}'.format(self.name), exc_info=True)
self.plot_data_item.setData(x=[], y=[])
class _WaveformView(QtWidgets.QWidget): class _WaveformView(QtWidgets.QWidget):
def __init__(self, parent): def __init__(self, parent):
QtWidgets.QWidget.__init__(self, parent=parent) QtWidgets.QWidget.__init__(self, parent=parent)