支持低功耗模式, 添加 config.LOW_POWER_MODE 配置项

This commit is contained in:
Mizore 2023-01-31 19:08:02 +08:00
parent b8401ffd13
commit 16d909a1d8
2 changed files with 22 additions and 7 deletions

View File

@ -42,4 +42,7 @@ return {
-- --
-- 开机通知 -- 开机通知
BOOT_NOTIFY = true, BOOT_NOTIFY = true,
--
-- 开启低功耗模式
LOW_POWER_MODE = false,
} }

View File

@ -3,18 +3,15 @@ VERSION = "1.0.0"
log.setLevel("DEBUG") log.setLevel("DEBUG")
log.info("main", PROJECT, VERSION) log.info("main", PROJECT, VERSION)
log.info("main", "开机原因", pm.lastReson())
sys = require "sys" sys = require "sys"
sysplus = require "sysplus" sysplus = require "sysplus"
require "sysplus" require "sysplus"
-- 添加硬狗防止程序卡死, 在支持的设备上启用这个功能 -- 添加硬狗防止程序卡死
if wdt then wdt.init(9000)
-- 初始化 watchdog 设置为 9s sys.timerLoopStart(wdt.feed, 3000)
wdt.init(9000)
-- 3s 喂一次狗
sys.timerLoopStart(wdt.feed, 3000)
end
-- 设置 DNS -- 设置 DNS
socket.setDNS(nil, 1, "119.29.29.29") socket.setDNS(nil, 1, "119.29.29.29")
@ -121,6 +118,21 @@ sys.taskInit(
) )
-- 电源键长按查询流量 -- 电源键长按查询流量
sys.subscribe("POWERKEY_LONG_PRESS", util_mobile.queryTraffic) 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 end
) )