From 96b2f204e41647bc4afaa0b841c029994ebf31c0 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Mon, 10 Aug 2020 19:28:45 +0800 Subject: [PATCH] factor block_size --- dmi.py | 2 +- gui.py | 19 +++---------------- gui_impl.py | 7 +++++-- 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/dmi.py b/dmi.py index 2ef0300..a3b9bea 100644 --- a/dmi.py +++ b/dmi.py @@ -14,7 +14,7 @@ def main(): freq_base = 1088230e3 block_size = 4096 - gui = GUI() + gui = GUI(block_size) try: induction = InductionHeater("/dev/ttyUSB0", 350e3, 445e3) induction.start() diff --git a/gui.py b/gui.py index bdd5744..9366dd3 100644 --- a/gui.py +++ b/gui.py @@ -48,10 +48,11 @@ class ParentComm: class GUI: - def __init__(self): + def __init__(self, block_size): self.impl = ParentComm() self.impl.create_subprocess([sys.executable, - os.path.join(os.path.dirname(os.path.abspath(__file__)), "gui_impl.py")]) + os.path.join(os.path.dirname(os.path.abspath(__file__)), "gui_impl.py"), + str(block_size)]) def update_beat_spectrum(self, data): obj = {"action": "update_beat_spectrum", "data": data} @@ -61,17 +62,3 @@ class GUI: obj = {"action": "terminate"} self.impl.write_pyon(obj) self.impl.close() - - -def main(): - gui = GUI() - try: - for i in range(200): - gui.update_beat_spectrum(np.random.normal(size=4096)) - time.sleep(1/60) - finally: - gui.close() - - -if __name__ == "__main__": - main() diff --git a/gui_impl.py b/gui_impl.py index 826ff3f..b29296b 100644 --- a/gui_impl.py +++ b/gui_impl.py @@ -1,5 +1,6 @@ import asyncio import os +import sys import logging import numpy as np @@ -10,7 +11,7 @@ from sipyco import pyon class SpectrogramWidget(pg.PlotWidget): - def __init__(self, block_size=4096): + def __init__(self, block_size): super(SpectrogramWidget, self).__init__() self.block_size = block_size @@ -61,6 +62,8 @@ class IPCClient(AsyncioChildComm): def main(): + block_size = int(sys.argv[1]) + app = QtWidgets.QApplication([]) loop = QEventLoop(app) asyncio.set_event_loop(loop) @@ -69,7 +72,7 @@ def main(): ipc = IPCClient(os.getenv("NOPTICA2_IPC")) loop.run_until_complete(ipc.connect()) try: - main_widget = SpectrogramWidget() + main_widget = SpectrogramWidget(block_size) main_widget.show() ipc.set_close_cb(main_widget.close) asyncio.ensure_future(ipc.listen(main_widget))