mod_led_control: LED actions

This commit is contained in:
gSpot
2023-08-03 16:57:06 +03:00
parent ffc10b81e0
commit f92713818d
7 changed files with 131 additions and 39 deletions

View File

@@ -19,15 +19,15 @@ Internet-detector is an application for checking the availability of the Interne
**OpenWrt >= 21.02:**
opkg update
wget --no-check-certificate -O /tmp/internet-detector_1.0-0_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/internet-detector_1.0-0_all.ipk
opkg install /tmp/internet-detector_1.0-0_all.ipk
rm /tmp/internet-detector_1.0-0_all.ipk
wget --no-check-certificate -O /tmp/internet-detector_1.0-1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/internet-detector_1.0-1_all.ipk
opkg install /tmp/internet-detector_1.0-1_all.ipk
rm /tmp/internet-detector_1.0-1_all.ipk
/etc/init.d/internet-detector start
/etc/init.d/internet-detector enable
wget --no-check-certificate -O /tmp/luci-app-internet-detector_1.0-0_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/luci-app-internet-detector_1.0-0_all.ipk
opkg install /tmp/luci-app-internet-detector_1.0-0_all.ipk
rm /tmp/luci-app-internet-detector_1.0-0_all.ipk
wget --no-check-certificate -O /tmp/luci-app-internet-detector_1.0-1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/luci-app-internet-detector_1.0-1_all.ipk
opkg install /tmp/luci-app-internet-detector_1.0-1_all.ipk
rm /tmp/luci-app-internet-detector_1.0-1_all.ipk
/etc/init.d/rpcd restart
Email notification:
@@ -36,9 +36,9 @@ Email notification:
i18n-ru:
wget --no-check-certificate -O /tmp/luci-i18n-internet-detector-ru_1.0-0_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/luci-i18n-internet-detector-ru_1.0-0_all.ipk
opkg install /tmp/luci-i18n-internet-detector-ru_1.0-0_all.ipk
rm /tmp/luci-i18n-internet-detector-ru_1.0-0_all.ipk
wget --no-check-certificate -O /tmp/luci-i18n-internet-detector-ru_1.0-1_all.ipk https://github.com/gSpotx2f/packages-openwrt/raw/master/current/luci-i18n-internet-detector-ru_1.0-1_all.ipk
opkg install /tmp/luci-i18n-internet-detector-ru_1.0-1_all.ipk
rm /tmp/luci-i18n-internet-detector-ru_1.0-1_all.ipk
**[OpenWrt 19.07](https://github.com/gSpotx2f/luci-app-internet-detector/tree/19.07)**

View File

@@ -6,7 +6,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=internet-detector
PKG_VERSION:=1.0
PKG_RELEASE:=0
PKG_RELEASE:=1
PKG_MAINTAINER:=gSpot <https://github.com/gSpotx2f/luci-app-internet-detector>
include $(INCLUDE_DIR)/package.mk

View File

@@ -11,12 +11,15 @@ local Module = {
runInterval = 5,
sysLedsDir = "/sys/class/leds",
ledName = nil,
ledAction1 = 2,
ledAction2 = 1,
status = nil,
_enabled = false,
_ledDir = nil,
_ledMaxBrightnessFile = nil,
_ledBrightnessFile = nil,
_ledMaxBrightness = nil,
_ledTriggerFile = nil,
_counter = 0,
}
@@ -38,12 +41,17 @@ function Module:init(t)
if not self.ledName then
return
end
self.ledAction1 = tonumber(t.led_action_1)
self.ledAction2 = tonumber(t.led_action_2)
self._ledDir = string.format("%s/%s", self.sysLedsDir, self.ledName)
self._ledMaxBrightnessFile = string.format("%s/max_brightness", self._ledDir)
self._ledBrightnessFile = string.format("%s/brightness", self._ledDir)
self._ledMaxBrightness = self.readValue(self._ledMaxBrightnessFile) or 1
self._ledTriggerFile = string.format("%s/trigger", self._ledDir)
if (not unistd.access(self._ledDir, "r") or
not unistd.access(self._ledBrightnessFile, "rw")) then
not unistd.access(self._ledBrightnessFile, "rw") or
not unistd.access(self._ledTriggerFile, "rw")) then
self._enabled = false
self.syslog("warning", string.format(
"%s: LED '%s' is not available", self.name, self.ledName))
@@ -54,6 +62,31 @@ function Module:init(t)
end
end
function Module:SetTriggerTimer()
self.writeValue(self._ledTriggerFile, "timer")
end
function Module:SetTriggerNone()
self.writeValue(self._ledTriggerFile, "none")
end
function Module:getCurrentTrigger()
local trigger = self.readValue(self._ledTriggerFile)
if trigger and trigger:match("%[timer%]") then
return 1
end
end
function Module:on()
self:SetTriggerNone()
self.writeValue(self._ledBrightnessFile, self._ledMaxBrightness)
end
function Module:off()
self:SetTriggerNone()
self.writeValue(self._ledBrightnessFile, 0)
end
function Module:getCurrentState()
local state = self.readValue(self._ledBrightnessFile)
if state and tonumber(state) > 0 then
@@ -61,33 +94,42 @@ function Module:getCurrentState()
end
end
function Module:on()
self.writeValue(self._ledBrightnessFile, self._ledMaxBrightness)
end
function Module:off()
self.writeValue(self._ledBrightnessFile, 0)
end
function Module:run(currentStatus, lastStatus, timeDiff)
if not self._enabled then
return
end
if self._counter == 0 or self._counter >= self.runInterval or currentStatus ~= lastStatus then
if currentStatus == 0 then
if not self:getCurrentState() then
self:on()
end
else
if self:getCurrentState() then
if self.ledAction1 == 1 then
if self:getCurrentState() or self:getCurrentTrigger() then
self:off()
end
elseif self.ledAction1 == 2 then
if not self:getCurrentState() or self:getCurrentTrigger() then
self:on()
end
elseif self.ledAction1 == 3 then
if not self:getCurrentTrigger() then
self:SetTriggerTimer()
end
end
else
if self.ledAction2 == 1 then
if self:getCurrentState() or self:getCurrentTrigger() then
self:off()
end
elseif self.ledAction2 == 2 then
if not self:getCurrentState() or self:getCurrentTrigger() then
self:on()
end
elseif self.ledAction2 == 3 then
if not self:getCurrentTrigger() then
self:SetTriggerTimer()
end
end
end
self._counter = 0
end
self._counter = self._counter + timeDiff
end

View File

@@ -4,7 +4,7 @@
include $(TOPDIR)/rules.mk
PKG_VERSION:=1.0-0
PKG_VERSION:=1.0-1
LUCI_TITLE:=LuCI support for internet-detector
LUCI_DEPENDS:=+internet-detector
LUCI_PKGARCH:=all

View File

@@ -194,7 +194,6 @@ return view.extend({
if(!this.inetStatus || !this.inetStatus.instances || this.inetStatus.instances.length === 0) {
let label = E('span', { 'class': 'id-label-status id-undefined' }, _('Undefined'))
if(this.currentAppMode !== '0' && this.appStatus !== 'stoped') {
label.classList.add('spinning');
};
@@ -251,7 +250,6 @@ return view.extend({
]).then(stat => {
let curAppStatus = (stat[0].code === 0) ? stat[0].stdout.trim() : null;
let inetStatData = this.inetStatusFromJson(stat[1]);
this.appStatus = curAppStatus;
this.inetStatus = inetStatData;
this.setInternetStatus();
@@ -273,9 +271,11 @@ return view.extend({
return fs.exec(this.execPath, [ 'poll' ]).then(res => {
let inetStatData = this.inetStatusFromJson(res);
if(inetStatData.instances[0]) {
this.uiPollState = inetStatData.instances[0].inet;
};
this.inetStatus = inetStatData;
this.setInternetStatus();
});
@@ -330,6 +330,7 @@ return view.extend({
renderWidget: function(section_id, option_index, cfgvalue) {
this.ctx.setInternetStatus();
return E([
E('label', { 'class': 'cbi-value-title', 'for': 'inetStatusArea' },
_('Internet status')
@@ -652,6 +653,7 @@ return view.extend({
'hosts', _('Hosts'),
_('Hosts to check Internet availability. Hosts are polled (in list order) until at least one of them responds.')
);
//o.datatype = 'or(host,hostport)';
o.datatype = 'or(or(host,hostport),ipaddrport(1))';
o.default = this.defaultHosts;
o.rmempty = false;
@@ -755,11 +757,12 @@ return view.extend({
o = ss.taboption('led_control', form.DummyValue, '_dummy');
o.rawhtml = true;
o.default = '<div class="cbi-section-descr">' +
_('<abbr title="Light Emitting Diode">LED</abbr> is on when Internet is available.') +
_('<abbr title="Light Emitting Diode">LED</abbr> indicates the Internet status.') +
'</div>';
o.modalonly = true;
if(this.leds.length > 0) {
this.leds.sort((a, b) => a.name > b.name);
// enabled
o = ss.taboption('led_control', form.Flag, 'mod_led_control_enabled',
@@ -772,8 +775,27 @@ return view.extend({
_('<abbr title="Light Emitting Diode">LED</abbr> Name'));
o.depends({ mod_led_control_enabled: '1' });
o.modalonly = true;
this.leds.sort((a, b) => a.name > b.name);
this.leds.forEach(e => o.value(e.name));
// led_action_1
o = ss.taboption('led_control', form.ListValue, 'mod_led_control_led_action_1',
_('Action when connected'));
o.depends({ mod_led_control_enabled: '1' });
o.modalonly = true;
o.value(1, _('Off'));
o.value(2, _('On'));
o.value(3, _('Blink'));
o.default = '2';
// led_action_2
o = ss.taboption('led_control', form.ListValue, 'mod_led_control_led_action_2',
_('Action when disconnected'));
o.depends({ mod_led_control_enabled: '1' });
o.modalonly = true;
o.value(1, _('Off'));
o.value(2, _('On'));
o.value(3, _('Blink'));
o.default = '1';
} else {
o = ss.taboption('led_control', form.DummyValue, '_dummy');
o.rawhtml = true;

View File

@@ -20,9 +20,14 @@ msgid "<abbr title=\"Light Emitting Diode\">LED</abbr> control"
msgstr "Управление <abbr title=\"Светодиод\">LED</abbr>"
msgid ""
"<abbr title=\"Light Emitting Diode\">LED</abbr> is on when Internet is "
"available."
msgstr "<abbr title=\"Светодиод\">LED</abbr> включен если Интернет доступен."
"<abbr title=\"Light Emitting Diode\">LED</abbr> indicates the Internet status."
msgstr "<abbr title=\"Светодиод\">LED</abbr> отображает статус Интернет."
msgid "Action when connected"
msgstr "Действие при подключении"
msgid "Action when disconnected"
msgstr "Действие при отключении"
msgid "Add instance"
msgstr "Добавить экземпляр"
@@ -44,6 +49,9 @@ msgstr "Произошла ошибка"
msgid "Big: 248 bytes"
msgstr "Большой: 248 байт"
msgid "Blink"
msgstr "Мигать"
msgid "Check type"
msgstr "Тип проверки"
@@ -291,6 +299,12 @@ msgstr "Сеть будет перезапущена при отключении
msgid "No <abbr title=\"Light Emitting Diode\">LED</abbr>s available..."
msgstr "Нет доступных <abbr title=\"Светодиод\">LED</abbr>..."
msgid "Off"
msgstr "Выключить"
msgid "On"
msgstr "Включить"
msgid "One of the following:"
msgstr "Одно из следующих значений:"

View File

@@ -8,8 +8,13 @@ msgid "<abbr title=\"Light Emitting Diode\">LED</abbr> control"
msgstr ""
msgid ""
"<abbr title=\"Light Emitting Diode\">LED</abbr> is on when Internet is "
"available."
"<abbr title=\"Light Emitting Diode\">LED</abbr> indicates the Internet status."
msgstr ""
msgid "Action when connected"
msgstr ""
msgid "Action when disconnected"
msgstr ""
msgid "Add instance"
@@ -32,6 +37,9 @@ msgstr ""
msgid "Big: 248 bytes"
msgstr ""
msgid "Blink"
msgstr ""
msgid "Check type"
msgstr ""
@@ -261,6 +269,12 @@ msgstr ""
msgid "No <abbr title=\"Light Emitting Diode\">LED</abbr>s available..."
msgstr ""
msgid "Off"
msgstr ""
msgid "On"
msgstr ""
msgid "One of the following:"
msgstr ""