From 5f3126f39369121b67f97e029d22c1374a5c7762 Mon Sep 17 00:00:00 2001 From: Simon Renblad Date: Fri, 26 Jan 2024 13:19:40 +0800 Subject: [PATCH] waveform: add BitWaveform --- artiq/dashboard/waveform.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/artiq/dashboard/waveform.py b/artiq/dashboard/waveform.py index 53e250f34..9897c41a2 100644 --- a/artiq/dashboard/waveform.py +++ b/artiq/dashboard/waveform.py @@ -186,6 +186,41 @@ class _BaseWaveform(pg.PlotWidget): super().wheelEvent(e) +class BitWaveform(_BaseWaveform): + def __init__(self, name, width, parent=None): + _BaseWaveform.__init__(self, name, width, parent) + self._arrows = [] + + def onDataChange(self, data): + try: + l = len(data) + display_y = np.empty(l) + display_x = np.empty(l) + display_map = { + "X": 0.5, + "1": 1, + "0": 0 + } + previous_y = None + for i, coord in enumerate(data): + x, y = coord + dis_y = display_map[y] + if previous_y == y: + arw = pg.ArrowItem(pxMode=True, angle=90) + self.addItem(arw) + self._arrows.append(arw) + arw.setPos(x, dis_y) + display_y[i] = dis_y + display_x[i] = x + previous_y = y + self.plot_data_item.setData(x=display_x, y=display_y) + except: + logger.error('Error when displaying waveform: {}'.format(self.name), exc_info=True) + for arw in self._arrows: + self.removeItem(arw) + self.plot_data_item.setData(x=[], y=[]) + + class _WaveformView(QtWidgets.QWidget): def __init__(self, parent): QtWidgets.QWidget.__init__(self, parent=parent)