From 56ae997a7a9540c4d59ad5ea45ef5fb2e27450b5 Mon Sep 17 00:00:00 2001 From: CN_SZTL Date: Sat, 1 Aug 2020 17:45:59 +0800 Subject: [PATCH] luci-app-oled: sync with upstream source --- .../luasrc/model/cbi/oled/setting.lua | 17 ++++++ package/ctcgfw/luci-app-oled/po/zh-cn/oled.po | 9 ++++ .../ctcgfw/luci-app-oled/root/etc/config/oled | 4 +- .../ctcgfw/luci-app-oled/root/etc/init.d/oled | 52 ++++++++++++++++--- 4 files changed, 74 insertions(+), 8 deletions(-) diff --git a/package/ctcgfw/luci-app-oled/luasrc/model/cbi/oled/setting.lua b/package/ctcgfw/luci-app-oled/luasrc/model/cbi/oled/setting.lua index 2b622c7086..7bc8fbf05f 100644 --- a/package/ctcgfw/luci-app-oled/luasrc/model/cbi/oled/setting.lua +++ b/package/ctcgfw/luci-app-oled/luasrc/model/cbi/oled/setting.lua @@ -14,6 +14,23 @@ s:tab("screensaver", translate("screensaver")) o = s:taboption("info", Flag, "enable", translate("Enable")) o.default=0 +o = s:taboption("info", Flag, "autoswitch", translate("Enable Auto switch")) +o.default=0 +from = s:taboption("info", ListValue, "from", translate("From")) +to = s:taboption("info", ListValue, "to", translate("To")) +for i=0,23 do + for j=0,30,30 do + from:value(i*60+j,string.format("%02d:%02d",i,j)) + to:value(i*60+j,string.format("%02d:%02d",i,j)) + end +end +from:value(1440,"24:00") +to:value(1440,"24:00") +from:depends("autoswitch",'1') +to:depends("autoswitch",'1') +from.default=0 +to.default=1440 + --informtion options---- o = s:taboption("info", Flag, "date", translate("Date"), translate('Format YYYY-MM-DD HH:MM:SS')) o.default=0 diff --git a/package/ctcgfw/luci-app-oled/po/zh-cn/oled.po b/package/ctcgfw/luci-app-oled/po/zh-cn/oled.po index 5432ea5604..bc3f8b056a 100644 --- a/package/ctcgfw/luci-app-oled/po/zh-cn/oled.po +++ b/package/ctcgfw/luci-app-oled/po/zh-cn/oled.po @@ -18,6 +18,15 @@ msgstr "CPU温度" msgid "Scroll Text" msgstr "文字滚动" +msgid "Enable Auto switch" +msgstr "启用定时开关" + +msgid "From" +msgstr "起始时间" + +msgid "To" +msgstr "结束时间" + msgid "Text you want to scroll" msgstr "你想要显示的文字" diff --git a/package/ctcgfw/luci-app-oled/root/etc/config/oled b/package/ctcgfw/luci-app-oled/root/etc/config/oled index 25f5208d7f..fd5b0daa68 100644 --- a/package/ctcgfw/luci-app-oled/root/etc/config/oled +++ b/package/ctcgfw/luci-app-oled/root/etc/config/oled @@ -17,4 +17,6 @@ config oled option cputemp '1' option time '60' option enable '0' - + option from '0' + option to '1440' + option autoswitch '0' diff --git a/package/ctcgfw/luci-app-oled/root/etc/init.d/oled b/package/ctcgfw/luci-app-oled/root/etc/init.d/oled index 7beda6f8d5..018962edaf 100755 --- a/package/ctcgfw/luci-app-oled/root/etc/init.d/oled +++ b/package/ctcgfw/luci-app-oled/root/etc/init.d/oled @@ -3,11 +3,34 @@ START=1OO PROG=/usr/bin/oled +stop() { + kill -2 $(pgrep /usr/bin/oled) + kill -9 $(pgrep -f /usr/sbin/netspeed) + echo "oled exit..." +} + start() { enabled=$(uci get oled.@oled[0].enable) if [ $enabled -eq 0 ]; then exit 0 fi + + autoswitch=$(uci get oled.@oled[0].autoswitch) + from=$(uci get oled.@oled[0].from) + to=$(uci get oled.@oled[0].to) + + if [ ${autoswitch} -eq 1 ]; then + hour=$(date +"%H") + min=$(date +"%M") + ihour=`expr $hour + 0` + imin=`expr $min + 0` + now=$(($ihour*60+$imin)) + if [[ $now -lt $from || $now -gt $to ]]; then + stop + exit 0 + fi + fi + #crontab daemon if ! grep "/etc/init.d/oled \+restart" /etc/crontabs/root >/dev/null 2>&1; then echo "*/5 * * * * /etc/init.d/oled restart >/dev/null 2>&1" >> /etc/crontabs/root @@ -33,6 +56,8 @@ start() { scroll=$(uci get oled.@oled[0].scroll) text=$(uci get oled.@oled[0].text) netsource=$(uci get oled.@oled[0].netsource) + + if [ ${netspeed} -eq 1 ]; then nohup /usr/sbin/netspeed ${netsource} >/dev/null 2>&1 & else @@ -43,19 +68,27 @@ start() { } -stop() { - kill -2 $(pgrep /usr/bin/oled) - kill -9 $(pgrep -f /usr/sbin/netspeed) - echo "oled exit..." -} + restart(){ enabled=$(uci get oled.@oled[0].enable) pgrep -f ${PROG} >/dev/null if [ $? -eq 0 ]; then if [ $enabled -eq 1 ]; then - kill -9 $(pgrep /usr/bin/oled) - kill -9 $(pgrep -f /usr/sbin/netspeed) + autoswitch=$(uci get oled.@oled[0].autoswitch) + from=$(uci get oled.@oled[0].from) + to=$(uci get oled.@oled[0].to) + if [ ${autoswitch} -eq 1 ]; then + hour=$(date +"%H") + min=$(date +"%M") + ihour=`expr $hour + 0` + imin=`expr $min + 0` + now=$(($ihour*60+$imin)) + if [[ $now -lt $from || $now -gt $to ]]; then + stop + exit 0 + fi + fi date=$(uci get oled.@oled[0].date) lanip=$(uci get oled.@oled[0].lanip) @@ -77,6 +110,11 @@ restart(){ scroll=$(uci get oled.@oled[0].scroll) text=$(uci get oled.@oled[0].text) netsource=$(uci get oled.@oled[0].netsource) + + + kill -9 $(pgrep /usr/bin/oled) + kill -9 $(pgrep -f /usr/sbin/netspeed) + if [ ${netspeed} -eq 1 ]; then nohup /usr/sbin/netspeed ${netsource} >/dev/null 2>&1 & else