From cf77281abb721650be27a24b114403309d946536 Mon Sep 17 00:00:00 2001 From: "lxbpxylps@126.com" Date: Wed, 3 Nov 2021 23:41:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=AF=BB=E6=95=B0=E6=A0=A1?= =?UTF-8?q?=E5=87=86=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.json | 22 ++++++++++++++++++++++ data.json | 2 +- mainwindow.py | 7 ------- serialhandler.py | 11 +++++++++++ start.bat | 1 + 5 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 config.json create mode 100644 start.bat diff --git a/config.json b/config.json new file mode 100644 index 0000000..4544991 --- /dev/null +++ b/config.json @@ -0,0 +1,22 @@ +{ + "node2": { + "humi": 0.8, + "temp": 0, + "light": 0 + }, + "node3": { + "humi": 0, + "temp": -0.2, + "light": 0 + }, + "node4": { + "humi": -2, + "temp": 0.4, + "light": 0 + }, + "node5": { + "humi": 0.6, + "temp": 0, + "light": 0 + } +} \ No newline at end of file diff --git a/data.json b/data.json index dddbdf9..03afdfa 100644 --- a/data.json +++ b/data.json @@ -1 +1 @@ -{"time": "2021-10-31 14:13:45", "node2": {"humi": 46.4, "temp": 25.6, "light": 80.8}, "node3": {"humi": 47.6, "temp": 26.3, "light": 73.3}, "node4": {"humi": 47.3, "temp": 26.4, "light": 124.2}, "node5": {"humi": 47.4, "temp": 25.7, "light": 130.8}} \ No newline at end of file +{"time": "2021-11-02 14:47:42", "node2": {"humi": 52.6, "temp": 27.7, "light": 180.8}, "node3": {"humi": 51.7, "temp": 27.6, "light": 165.8}, "node4": {"humi": 50.4, "temp": 27.9, "light": 170.8}, "node5": {"humi": 52.3, "temp": 27.8, "light": 173.3}} \ No newline at end of file diff --git a/mainwindow.py b/mainwindow.py index a342b68..6bdbacc 100644 --- a/mainwindow.py +++ b/mainwindow.py @@ -32,13 +32,6 @@ class MainWindow(QMainWindow): menubar_file = menubar.addMenu('文件') menubar_file.addAction(exit_action) - # 菜单栏-校准 - adjust_action = QAction('&校准菜单', self) - adjust_action.triggered.connect(lambda: sys.exit()) - - menubar_adjust = menubar.addMenu('校准') - menubar_adjust.addAction(adjust_action) - # 菜单栏-曲线 draw_node2_action = QAction('&节点2', self) draw_node3_action = QAction('&节点3', self) diff --git a/serialhandler.py b/serialhandler.py index d761717..271821c 100644 --- a/serialhandler.py +++ b/serialhandler.py @@ -53,6 +53,17 @@ class SerialHandler(QThread): print('数据不合理!') continue + # 修正读数 + config = json.loads( + open('./config.json', 'r', encoding='utf-8').read()) + humi += config['node' + str(seq)]['humi'] + temp += config['node' + str(seq)]['temp'] + light += config['node' + str(seq)]['light'] + + humi = round(humi, 2) + temp = round(temp, 2) + light = round(light, 2) + print(f"节点:{seq} 湿度:{humi}% 温度:{temp}°C 光照度:{light}lx") # 写入 json 文件 diff --git a/start.bat b/start.bat new file mode 100644 index 0000000..7a84f97 --- /dev/null +++ b/start.bat @@ -0,0 +1 @@ +python main.py \ No newline at end of file