diff --git a/mes_gui.py b/mes_gui.py index 27fd2c2..2796db0 100644 --- a/mes_gui.py +++ b/mes_gui.py @@ -1,14 +1,15 @@ - -from gdx import gdx import threading import time -import csv from abc import abstractmethod + +import cv2 import numpy as np +from gdx import gdx + class DataWorker(threading.Thread): - def __init__(self, out_filename=""): + def __init__(self): threading.Thread.__init__(self) self._running = False self._start_time = 0 @@ -28,13 +29,13 @@ def run(self): self.preprocess() self._running = True - self._data = np.array([tuple([0] * self._cols)]) + self._data = np.array([tuple([0] * (self._num_channels + 1))]) self._start_time = time.perf_counter() while self._running: measurements = self.read() current_time = time.perf_counter() - self._start_time measurements.insert(0, current_time) - if len(measurements) == self._cols: + if len(measurements) == self._num_channels + 1: self._data = np.vstack([self._data, measurements]) # print(measurements) @@ -44,14 +45,15 @@ self.postprocess() self._data = self._data[1:, :] + class GoDirectWorker(DataWorker): - def __init__(self, out_filename): - super().__init__(out_filename) + def __init__(self): + super().__init__() # Connect GoDirect device self._gdx = gdx.gdx() self._gdx.open(connection="usb") self._gdx.select_sensors([1]) - self._cols = 2 + self._num_channels = 1 print("GoDirect connected.") def preprocess(self): @@ -64,19 +66,26 @@ self._gdx.stop() self._gdx.close() + if __name__ == "__main__": - godirect_worker = GoDirectWorker("") + win_name = "measurement" + cv2.namedWindow(win_name, cv2.WINDOW_NORMAL) + display_width = 800 + display_height = 600 + + godirect_worker = GoDirectWorker() godirect_worker.start() # Wait for stop print("measurement start.") - recode_dulation = 3 # sec - for i in range(recode_dulation): - time.sleep(1) - print(i + 1, "/", recode_dulation, "sec") + while True: + disp = np.zeros((display_height, display_width, 3), np.uint8) + cv2.imshow(win_name, disp) + if cv2.waitKey(30) == 27: + break + # input("Press ENTER to stop") print("measurement end.") - print(godirect_worker._data) # Closing godirect_worker.stop()