Skip to content

Commit b2cd5b8

Browse files
Removed ugly DAQ_is_enabled run/pause hack
1 parent eee78b2 commit b2cd5b8

File tree

2 files changed

+17
-28
lines changed

2 files changed

+17
-28
lines changed

demo_A_GUI_full.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,6 @@ def __init__(
104104
super().__init__(dev, **kwargs) # Pass kwargs onto QtCore.QObject()
105105
self.dev: WaveGeneratorArduino # Enforce type: removes `_NoDevice()`
106106

107-
# Pause/resume mechanism
108-
self.DAQ_is_enabled = True
109-
110107
self.create_worker_DAQ(
111108
DAQ_trigger=DAQ_TRIGGER.INTERNAL_TIMER,
112109
DAQ_function=self.DAQ_function,
@@ -117,13 +114,6 @@ def __init__(
117114
)
118115
self.create_worker_jobs(debug=debug)
119116

120-
def set_DAQ_enabled(self, state: bool):
121-
self.DAQ_is_enabled = state
122-
if self.DAQ_is_enabled:
123-
self.worker_DAQ.DAQ_function = self.DAQ_function
124-
else:
125-
self.worker_DAQ.DAQ_function = None
126-
127117
def set_waveform_to_sine(self):
128118
self.send(self.dev.set_waveform_to_sine)
129119

@@ -192,6 +182,9 @@ def __init__(
192182
self.qdev.signal_DAQ_updated.connect(self.update_GUI)
193183
self.qlog = qlog
194184

185+
# Run/pause mechanism on updating the GUI and graphs
186+
self.allow_GUI_update_of_readings = True
187+
195188
self.setWindowTitle("Arduino & PyQt multithread demo")
196189
if USE_LARGER_TEXT:
197190
self.setGeometry(40, 60, 1024, 768)
@@ -431,7 +424,7 @@ def __init__(
431424
@Slot(bool)
432425
def process_qpbt_running(self, state: bool):
433426
self.qpbt_running.setText("Running" if state else "Paused")
434-
self.qdev.set_DAQ_enabled(state)
427+
self.allow_GUI_update_of_readings = state
435428

436429
@Slot()
437430
def update_GUI(self):
@@ -448,11 +441,18 @@ def update_GUI(self):
448441
if self.qlog.is_recording()
449442
else ""
450443
)
444+
445+
if not self.allow_GUI_update_of_readings:
446+
return
447+
451448
self.qlin_reading_t.setText(f"{state.time:.3f}")
452449
self.qlin_reading_1.setText(f"{state.reading_1:.4f}")
453450

454451
@Slot()
455452
def update_chart(self):
453+
if not self.allow_GUI_update_of_readings:
454+
return
455+
456456
if DEBUG:
457457
tprint("update_curve")
458458

@@ -544,13 +544,12 @@ def write_data_to_log():
544544

545545
@Slot()
546546
def postprocess_DAQ_updated():
547-
if ard_qdev.DAQ_is_enabled:
548-
# Add readings to chart history
549-
window.history_chart_curve.appendData(
550-
ard.state.time, ard.state.reading_1
551-
)
552-
# Add readings to the log
553-
log.update()
547+
# Add readings to chart history
548+
window.history_chart_curve.appendData(
549+
ard.state.time, ard.state.reading_1
550+
)
551+
# Add readings to the log
552+
log.update()
554553

555554
# --------------------------------------------------------------------------
556555
# Program termination routines

demo_B_GUI_minimal.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,6 @@ def __init__(
101101
super().__init__(dev, **kwargs) # Pass kwargs onto QtCore.QObject()
102102
self.dev: WaveGeneratorArduino # Enforce type: removes `_NoDevice()`
103103

104-
# Pause/resume mechanism
105-
self.DAQ_is_enabled = True
106-
107104
self.create_worker_DAQ(
108105
DAQ_trigger=DAQ_TRIGGER.INTERNAL_TIMER,
109106
DAQ_function=self.DAQ_function,
@@ -114,13 +111,6 @@ def __init__(
114111
)
115112
self.create_worker_jobs(debug=debug)
116113

117-
def set_DAQ_enabled(self, state: bool):
118-
self.DAQ_is_enabled = state
119-
if self.DAQ_is_enabled:
120-
self.worker_DAQ.DAQ_function = self.DAQ_function
121-
else:
122-
self.worker_DAQ.DAQ_function = None
123-
124114
def set_waveform_to_sine(self):
125115
self.send(self.dev.set_waveform_to_sine)
126116

0 commit comments

Comments
 (0)