diff --git a/src/rom/app.py b/src/rom/app.py index 01f9de6..d80f86f 100644 --- a/src/rom/app.py +++ b/src/rom/app.py @@ -81,7 +81,6 @@ def authenticate(credentials): return decorator - # /status: 获取系统状态 @authenticate(credentials=CREDENTIALS) async def sys_status(request): @@ -92,8 +91,9 @@ async def sys_status(request): "time": "{}-{:02d}-{:02d} {:02d}:{:02d}:{:02d}".format( *time.localtime() ), - "uptime": str(f"{time.ticks_ms() // 1000} sec"), - "memory": str(f"{gc.mem_free() // 1000} KB"), + "uptime": time.ticks_ms(), + "mem_free": gc.mem_free(), + "mem_alloc": gc.mem_alloc(), "uuid": uuid(), "platform": str(sys.platform), "version": str(sys.version), diff --git a/src/rom/www/index.html b/src/rom/www/index.html index fcdc160..48792f3 100644 --- a/src/rom/www/index.html +++ b/src/rom/www/index.html @@ -48,10 +48,20 @@

WS2桌面气象站

-
- +
可用内存: - - + -
UUID: - @@ -92,52 +102,40 @@ -
- -
-

LCD状态

-
-
-
-
- 就绪状态: - - - -
-
- 当前亮度: - -% -
-
- UI类型: - - -
-
- 数据内容: - - -
-
+

LCD显示设置

+
+
+ +
-

显示设置

- - -
当前值: -
+ +
+ + -% +
@@ -151,6 +149,14 @@ + +

LCD数据内容

+ + + + + +
属性
@@ -216,7 +222,8 @@ 彩色
- 环境参数: 温度、湿度、PM2.5、气压、AQI + 环境参数: + 温度、湿度、PM2.5、气压、AQI
@@ -225,7 +232,12 @@
固件: - ws2-v1.3.0 + + ws2-v1.3.0 + 开源
@@ -239,8 +251,20 @@

开放源码

- Kicer@Github: ws2 - Kicer@foresh: ws2(国内访问) + + kicer@Github: ws2 + + + kicer@Foresh: ws2(国内访问)

软件许可

本项目采用MIT许可证开源,欢迎自由使用和修改。

@@ -257,13 +281,11 @@ initTabSwitching(); initEventHandlers(); refreshStatus(); - loadConfig(); - updateDisplaySettings(); }); // 初始化选项卡切换 function initTabSwitching() { - mw.$$(".nav-tab").forEach(tab => { + mw.$$(".nav-tab").forEach((tab) => { mw.on(tab, "click", function () { const tabName = mw.attr(this, "data-tab"); showTab(tabName); @@ -273,19 +295,11 @@ // 初始化事件处理器 function initEventHandlers() { - // 退出按钮 - mw.on(mw.$("#logout-btn"), "click", function () { - alert("退出功能暂未实现"); - }); - // 亮度滑块 mw.on(mw.$("#brightness-slider"), "input", function () { mw.text(mw.$("#brightness-value"), mw.val(this)); }); - // 刷新状态按钮 - mw.on(mw.$("#refresh-status-btn"), "click", refreshStatus); - // 应用显示设置按钮 mw.on( mw.$("#apply-display-btn"), @@ -299,19 +313,14 @@ // 更新LCD状态徽章 function updateLcdBadges(isReady) { - const badge1 = mw.$("#lcd-ready-badge"); - const badge2 = mw.$("#lcd-ready-badge-display"); + const badge = mw.$("#lcd-ready-badge"); if (isReady) { - mw.text(badge1, "正常"); - mw.text(badge2, "正常"); - mw.replaceClass(badge1, "badge-warning", "badge-success"); - mw.replaceClass(badge2, "badge-warning", "badge-success"); + mw.text(badge, "正常"); + mw.replaceClass(badge, "badge-warning", "badge-success"); } else { - mw.text(badge1, "未就绪"); - mw.text(badge2, "未就绪"); - mw.replaceClass(badge1, "badge-success", "badge-warning"); - mw.replaceClass(badge2, "badge-success", "badge-warning"); + mw.text(badge, "未就绪"); + mw.replaceClass(badge, "badge-success", "badge-warning"); } } @@ -347,14 +356,14 @@ async function refreshStatus() { try { // 获取系统状态 - const statusResponse = await mw.ajax.get("/status"); - const statusData = JSON.parse(statusResponse); + const response = await mw.ajax.get("/status"); + const data = JSON.parse(response); // 使用数据绑定更新系统状态 - mw.bind(statusData); + mw.bind(data); // 更新内存仪表盘 - updateMemoryGauge(statusData.memory); + updateMemoryGauge(data.mem_free, data.mem_alloc); showMessage("状态已更新", "success"); } catch (error) { @@ -363,34 +372,24 @@ } // 更新内存仪表盘 - function updateMemoryGauge(memoryStr) { - // 从内存字符串中提取数值,例如 "100 KB" -> 100 - const match = memoryStr.match(/(\d+)/); - if (match) { - // 这里简化处理,假设最大可用内存为50KB - const maxMemory = 50; - const memoryValue = parseInt(match[1]); - const percentage = Math.min( - 100, - Math.round((memoryValue / maxMemory) * 100), - ); + function updateMemoryGauge(free, alloc) { + const maxMemory = parseInt(free) + parseInt(alloc); + const memoryValue = parseInt(alloc); + const percentage = Math.min( + 100, + Math.round((memoryValue / maxMemory) * 100), + ); - // 使用micro.js的图表功能创建仪表盘 - mw.chart.createGauge( - mw.$("#memory-gauge"), - percentage, - 100, - { - label: "内存使用率", - color: - percentage > 80 - ? "#e74c3c" - : percentage > 50 - ? "#f39c12" - : "#27ae60", - }, - ); - } + // 使用micro.js的图表功能创建仪表盘 + mw.chart.createGauge(mw.$("#memory-gauge"), percentage, 100, { + label: "内存使用率", + color: + percentage > 80 + ? "#e74c3c" + : percentage > 50 + ? "#f39c12" + : "#27ae60", + }); } // 更新显示设置 @@ -399,21 +398,18 @@ const response = await mw.ajax.get("/lcd"); const data = JSON.parse(response); - // 更新LCD状态 - const lcdBindings = { - "lcd-ready": data.ready ? "就绪" : "未就绪", - "lcd-brightness": data.brightness, - "lcd-ui-type": data.ui_type, - "lcd-data": JSON.stringify(data.data), - }; - mw.bind(lcdBindings); - - // 更新亮度滑块 + // 更新亮度滑块和显示值 mw.val(mw.$("#brightness-slider"), data.brightness); mw.text(mw.$("#brightness-value"), data.brightness); // 更新UI类型选择框 mw.val(mw.$("#ui-type-select"), data.ui_type); + + // 更新LCD状态徽章 + updateLcdBadges(data.ready); + + // 更新LCD数据表格 + updateLcdDataTable(data.data); } catch (error) { showMessage("获取LCD状态失败: " + error.message, "error"); } @@ -434,7 +430,8 @@ if (data.status === "success") { showMessage("显示设置已应用", "success"); - refreshStatus(); + // 刷新显示设置 + await updateDisplaySettings(); } else { showMessage( "设置失败: " + (data.message || "未知错误"), @@ -493,6 +490,31 @@ } } + // 更新LCD数据表格 + function updateLcdDataTable(data) { + const dataTable = mw.$("#lcd-data-table"); + + // 清除现有行(保留标题行) + while (dataTable.rows.length > 1) { + dataTable.deleteRow(1); + } + + // 添加数据行 + for (const key in data) { + const row = dataTable.insertRow(); + const cell1 = row.insertCell(0); + const cell2 = row.insertCell(1); + + mw.text(cell1, key); + let value = data[key]; + // 如果值是对象,则转换为JSON字符串 + if (typeof value === "object") { + value = JSON.stringify(value); + } + mw.text(cell2, value); + } + } + // 保存配置 async function saveConfig() { try {