From 16d909a1d8e227eb3a78cb0fc9bea232f54b79b7 Mon Sep 17 00:00:00 2001 From: Mizore Date: Tue, 31 Jan 2023 19:08:02 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E6=94=AF=E6=8C=81=E4=BD=8E?= =?UTF-8?q?=E5=8A=9F=E8=80=97=E6=A8=A1=E5=BC=8F,=20=E6=B7=BB=E5=8A=A0=20`c?= =?UTF-8?q?onfig.LOW=5FPOWER=5FMODE`=20=E9=85=8D=E7=BD=AE=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script/config.lua | 3 +++ script/main.lua | 26 +++++++++++++++++++------- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/script/config.lua b/script/config.lua index cabd4af..ba0bacd 100644 --- a/script/config.lua +++ b/script/config.lua @@ -42,4 +42,7 @@ return { -- -- 开机通知 BOOT_NOTIFY = true, + -- + -- 开启低功耗模式 + LOW_POWER_MODE = false, } diff --git a/script/main.lua b/script/main.lua index 2e6a2da..c5f5700 100644 --- a/script/main.lua +++ b/script/main.lua @@ -3,18 +3,15 @@ VERSION = "1.0.0" log.setLevel("DEBUG") log.info("main", PROJECT, VERSION) +log.info("main", "开机原因", pm.lastReson()) sys = require "sys" sysplus = require "sysplus" require "sysplus" --- 添加硬狗防止程序卡死, 在支持的设备上启用这个功能 -if wdt then - -- 初始化 watchdog 设置为 9s - wdt.init(9000) - -- 3s 喂一次狗 - sys.timerLoopStart(wdt.feed, 3000) -end +-- 添加硬狗防止程序卡死 +wdt.init(9000) +sys.timerLoopStart(wdt.feed, 3000) -- 设置 DNS socket.setDNS(nil, 1, "119.29.29.29") @@ -121,6 +118,21 @@ sys.taskInit( ) -- 电源键长按查询流量 sys.subscribe("POWERKEY_LONG_PRESS", util_mobile.queryTraffic) + + -- 开启低功耗模式 + if config.LOW_POWER_MODE then + sys.wait(1000 * 15) + log.warn("main", "即将关闭 usb 电源, 如需查看日志请在配置中关闭低功耗模式") + sys.wait(1000 * 5) + + -- 关闭 USB + pm.power(pm.USB, false) + pm.power(pm.GPS, false) + pm.power(pm.GPS_ANT, false) + pm.power(pm.DAC_EN, false) + -- 休眠 + pm.force(pm.LIGHT) + end end )