From adf70dbd08d4b4fdb4fee4685254a4582956ca00 Mon Sep 17 00:00:00 2001 From: Eric Yu Date: Fri, 14 Apr 2023 04:20:34 -0700 Subject: [PATCH] slight update --- make.bat | 1 + nano_c_mk1/nano_c_mk1.ino | 1 - read_arduino.py | 7 +++++-- serial_plotter.py | 5 +++-- test.py | 6 ++++-- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/make.bat b/make.bat index 84a1e95..c4113b2 100644 --- a/make.bat +++ b/make.bat @@ -18,6 +18,7 @@ GOTO run rmdir /s /q %env% 2>nul rmdir /s /q build 2>nul rmdir /s /q dist 2>nul + rmdir /s /q venv 2>nul GOTO End :run diff --git a/nano_c_mk1/nano_c_mk1.ino b/nano_c_mk1/nano_c_mk1.ino index 597121e..2185065 100644 --- a/nano_c_mk1/nano_c_mk1.ino +++ b/nano_c_mk1/nano_c_mk1.ino @@ -5,7 +5,6 @@ * @version 0.1 * @date 2023-03-03 * - * @copyright Copyright (c) 2023 * */ #include // https://github.com/adafruit/Adafruit_ADS1X15, with partially its "continuous" example code integrated in ths diff --git a/read_arduino.py b/read_arduino.py index 32a6510..a482891 100644 --- a/read_arduino.py +++ b/read_arduino.py @@ -5,7 +5,7 @@ from datetime import datetime import serial, time, json import serial.tools.list_ports import numpy as np -import csv +import csv, traceback # constant settings SENSORS_MAX = 4 # maximum sensor ports @@ -85,6 +85,7 @@ def read(): while controller.isOpen(): try: read_data = controller.readline().decode("utf-8") + print(read_data) # Debug # use numpy so it can make list calculations easier (and possibly faster) dat_list = np.asarray(json.loads(read_data), dtype=np.float32)[:SENSORS_MAX] # According to the actual req, the data in the data list should be (3.3-data) @@ -103,12 +104,14 @@ def read(): # write + export values as .csv format # converted resistance values in array to scientific notation dat = f", ".join(np.insert(r_arr2.astype(str), 0, datetime.now().strftime('%H:%M:%S'))) - print(dat) f = open(file_name, "a", newline="", encoding="utf-8") f.write(dat + '\n') f.close() except KeyboardInterrupt as e: + controller.close() print(e.__class__.__name__) break except (json.decoder.JSONDecodeError, UnicodeDecodeError): print('decoder error') + except: + traceback.print_exc() # debug, printout error diff --git a/serial_plotter.py b/serial_plotter.py index 9d17483..0ec953e 100644 --- a/serial_plotter.py +++ b/serial_plotter.py @@ -50,8 +50,9 @@ class SerialPlotter: def animation(self, t: int) -> None: """ - render a frame of the animated graph + render a frame of the animated graph. """ + # Some of them copied from the old code, so even Eric may not 100% know what they do. ChatGPT may give a better explaination try: plt.cla() # clear previous frame # read the last line from the .csv file, the data start from the second column so omit index #0 @@ -90,7 +91,7 @@ class SerialPlotter: i += 1 self.timeElapsed += 1 # increment time - # Acknowledgement: https://stackoverflow.com/a/13589144 + # Acknowledgement: https://stackoverflow.com/a/13589144 (can you imagine how long it took me to find this before ChatGPT?) handles, labels = self.axs.get_legend_handles_labels() by_label = dict(zip(labels, handles)) self.axs.legend(by_label.values(), by_label.keys(), loc='best', fontsize = max(self.fontSize, 10)) # Make the legend on graph large enough diff --git a/test.py b/test.py index 2cb8f42..f31d1cf 100644 --- a/test.py +++ b/test.py @@ -73,6 +73,7 @@ def gen_settings(resistors, input_voltage, port, filename, window_size, font_siz settings["file_name"] = filename settings["delay"] = delay settings["font_size"] = frame.fontSize.GetValue() + # TODO: get the input voltage from the UI and save it to the settings.json open(name, 'w').write(json.dumps(settings, indent=4)) open(filename, "a", newline="", encoding="utf-8") @@ -114,10 +115,11 @@ if __name__ == '__main__': console = wx.PyOnDemandOutputWindow(console_title) console.SetParent(frame) sys.stderr = console + # instrad of print(), use sys.stdout.write() to print to allow us redirect the output elsewhere. TODO: may not work in the exe sys.stdout.write("this is an alpha version of the design. This debug terminal will be gone on official release\n") - ports = [comport.device for comport in serial.tools.list_ports.comports()] # get all available ports + ports = [f"{comport.device}: {comport.description}" for comport in serial.tools.list_ports.comports()] # get all available ports frame.dev_list.AppendItems(ports) - frame.SetTitle("SeeDatResistance - Beta 0.1.1") + frame.SetTitle("SeeDatResistance - Beta 0.1.2") frame.btLaunch.Bind(wx.EVT_BUTTON, run) if os.path.isfile("settings.json"): try: