From ebf61d13d49a344bce9bb9b67a17ade6b55a8628 Mon Sep 17 00:00:00 2001 From: kicer Date: Mon, 2 Feb 2026 12:20:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=85=A5=E5=AE=9A=E6=97=B6=E7=86=84?= =?UTF-8?q?=E5=B1=8F=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/rom/app.py | 38 +++++++++++++++++++++++++++++++++++++- src/rom/www/index.html | 19 +++++++++++-------- 2 files changed, 48 insertions(+), 9 deletions(-) diff --git a/src/rom/app.py b/src/rom/app.py index d23db6e..0fe7c8f 100644 --- a/src/rom/app.py +++ b/src/rom/app.py @@ -188,6 +188,37 @@ async def eval_cmd(request): finally: await json_response(request, json.dumps(ack)) +# 定时熄屏处理功能,熄屏则返回True +def standby_control(): + # 获取当前时间 (格式: HH:MM) + now = time.localtime() + current_time = "{:02d}:{:02d}".format(now[3], now[4]) + + # 从配置中获取熄屏和唤醒时间 + standby_time = config.get("standby_time") + wakeup_time = config.get("wakeup_time") + + _set = config.get('brightness', 10) + + # 如果设置了熄屏和唤醒时间 + if standby_time and wakeup_time: + # 如果当前时间在熄屏时间之后,唤醒时间之前,则关闭屏幕 + if standby_time <= wakeup_time: + if current_time >= standby_time and current_time < wakeup_time: + _set = 0 + else: + if current_time >= standby_time or current_time < wakeup_time: + _set = 0 + else: + _set = None + + if _set is not None: + if display.brightness(): + if _set == 0: + display.brightness(0) + else: + if _set > 0: + display.brightness(config.get("brightness", 10)) # 恢复亮度 # ntp时钟同步 @@ -327,7 +358,12 @@ async def ui_task(): # 每隔100帧,更新一次UI显示 F += 1 if F % 100 == 0: - display.update_ui() + standby_control() # 控制开关机 + # 只在亮屏时更新显示 + if display.brightness(): + display.update_ui() + else: + gc.collect(); print(f'LCD.idle.mem: {gc.mem_free()}') # 每轮清理一次内存 gc.collect() diff --git a/src/rom/www/index.html b/src/rom/www/index.html index e7f1a88..d3e0621 100644 --- a/src/rom/www/index.html +++ b/src/rom/www/index.html @@ -82,12 +82,10 @@ target="_blank" download >查看城市ID列表) -
留空表示不自动熄屏
+
+ +
+分别设置熄屏和唤醒时间,留空则表示不自动熄屏
@@ -314,7 +312,10 @@ mw.val(mw.$("#city-input"), data.city); } if (data.standby_time) { mw.val(mw.$("#standby-time-input"), data.standby_time); -}// 更新配置表 +} +if (data.wakeup_time) { +mw.val(mw.$("#wakeup-time-input"), data.wakeup_time); +} updateConfigTable(data); } catch (error) { showMessage("获取配置失败: " + error.message, "error"); @@ -354,6 +355,7 @@ try { const userCfgKey = mw.val(mw.$("#custom-config-key")); const userCfgVal = mw.val(mw.$("#custom-config-value")); const city = mw.val(mw.$("#city-input")); +const wakeupTime = mw.val(mw.$("#wakeup-time-input")); const standbyTime = mw.val(mw.$("#standby-time-input"));if (!city) { showMessage("城市名称不能为空", "error"); return; @@ -363,8 +365,9 @@ cityid: encodeURIComponent(city), }; if (userCfgKey !== "") { configData[userCfgKey] = userCfgVal; -}if (standbyTime !== "") { +}if (standbyTime !== "" && wakeupTime !== "") { configData.standby_time = standbyTime; +configData.wakeup_time = wakeupTime; }const response = await mw.ajax.post( "/config/set", configData,