slight update

This commit is contained in:
Eric Yu 2023-04-14 04:20:34 -07:00
parent 40a78b81f7
commit adf70dbd08
5 changed files with 13 additions and 7 deletions

View File

@ -18,6 +18,7 @@ GOTO run
rmdir /s /q %env% 2>nul rmdir /s /q %env% 2>nul
rmdir /s /q build 2>nul rmdir /s /q build 2>nul
rmdir /s /q dist 2>nul rmdir /s /q dist 2>nul
rmdir /s /q venv 2>nul
GOTO End GOTO End
:run :run

View File

@ -5,7 +5,6 @@
* @version 0.1 * @version 0.1
* @date 2023-03-03 * @date 2023-03-03
* *
* @copyright Copyright (c) 2023
* *
*/ */
#include <Adafruit_ADS1X15.h> // https://github.com/adafruit/Adafruit_ADS1X15, with partially its "continuous" example code integrated in ths #include <Adafruit_ADS1X15.h> // https://github.com/adafruit/Adafruit_ADS1X15, with partially its "continuous" example code integrated in ths

View File

@ -5,7 +5,7 @@ from datetime import datetime
import serial, time, json import serial, time, json
import serial.tools.list_ports import serial.tools.list_ports
import numpy as np import numpy as np
import csv import csv, traceback
# constant settings # constant settings
SENSORS_MAX = 4 # maximum sensor ports SENSORS_MAX = 4 # maximum sensor ports
@ -85,6 +85,7 @@ def read():
while controller.isOpen(): while controller.isOpen():
try: try:
read_data = controller.readline().decode("utf-8") read_data = controller.readline().decode("utf-8")
print(read_data) # Debug
# use numpy so it can make list calculations easier (and possibly faster) # 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] 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) # 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 # write + export values as .csv format
# converted resistance values in array to scientific notation # converted resistance values in array to scientific notation
dat = f", ".join(np.insert(r_arr2.astype(str), 0, datetime.now().strftime('%H:%M:%S'))) 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 = open(file_name, "a", newline="", encoding="utf-8")
f.write(dat + '\n') f.write(dat + '\n')
f.close() f.close()
except KeyboardInterrupt as e: except KeyboardInterrupt as e:
controller.close()
print(e.__class__.__name__) print(e.__class__.__name__)
break break
except (json.decoder.JSONDecodeError, UnicodeDecodeError): except (json.decoder.JSONDecodeError, UnicodeDecodeError):
print('decoder error') print('decoder error')
except:
traceback.print_exc() # debug, printout error

View File

@ -50,8 +50,9 @@ class SerialPlotter:
def animation(self, t: int) -> None: 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: try:
plt.cla() # clear previous frame plt.cla() # clear previous frame
# read the last line from the .csv file, the data start from the second column so omit index #0 # 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 i += 1
self.timeElapsed += 1 # increment time 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() handles, labels = self.axs.get_legend_handles_labels()
by_label = dict(zip(labels, handles)) 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 self.axs.legend(by_label.values(), by_label.keys(), loc='best', fontsize = max(self.fontSize, 10)) # Make the legend on graph large enough

View File

@ -73,6 +73,7 @@ def gen_settings(resistors, input_voltage, port, filename, window_size, font_siz
settings["file_name"] = filename settings["file_name"] = filename
settings["delay"] = delay settings["delay"] = delay
settings["font_size"] = frame.fontSize.GetValue() 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(name, 'w').write(json.dumps(settings, indent=4))
open(filename, "a", newline="", encoding="utf-8") open(filename, "a", newline="", encoding="utf-8")
@ -114,10 +115,11 @@ if __name__ == '__main__':
console = wx.PyOnDemandOutputWindow(console_title) console = wx.PyOnDemandOutputWindow(console_title)
console.SetParent(frame) console.SetParent(frame)
sys.stderr = console 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") 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.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) frame.btLaunch.Bind(wx.EVT_BUTTON, run)
if os.path.isfile("settings.json"): if os.path.isfile("settings.json"):
try: try: