mirror of
https://github.com/dikeckaan/mu300-linux.git
synced 2026-12-05 08:02:40 +00:00
fix(tf): control signal and Wi-Fi status lamps independently
This commit is contained in:
4 files changed
+165
-2
No files matched your search
@@ -4,6 +4,14 @@ START=99
|
||||
USE_PROCD=1
|
||||
export PATH="$PATH:/opt/mu300/busybox-bin"
|
||||
|
||||
service_triggers() {
|
||||
procd_add_reload_trigger system
|
||||
}
|
||||
|
||||
reload_service() {
|
||||
/opt/mu300/bin/led-status refresh
|
||||
}
|
||||
|
||||
start_service() {
|
||||
# START=99 means the web/LAN services have been started. End the initramfs
|
||||
# chase now; if WAN is not ready yet the specified steady state is red.
|
||||
|
||||
@@ -15,6 +15,9 @@ uci -q batch <<UCI
|
||||
set system.@system[0].hostname='mu300'
|
||||
set system.@system[0].zonename='Europe/Istanbul'
|
||||
set system.@system[0].timezone='<+03>-3'
|
||||
set system.mu300_leds=mu300_leds
|
||||
set system.mu300_leds.signal='1'
|
||||
set system.mu300_leds.wifi='1'
|
||||
set network.lan.ipaddr='$lan_ip'
|
||||
set network.lan.netmask='255.255.255.0'
|
||||
set network.lan.ip6assign='64'
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
'use strict';
|
||||
'require view';
|
||||
'require uci';
|
||||
'require rpc';
|
||||
'require form';
|
||||
'require fs';
|
||||
|
||||
/* Keep LuCI's normal LED actions; add controls for the two physical F50
|
||||
* lamps, whose channels are driven by led-status rather than kernel triggers.
|
||||
* Based on luci-mod-system's 25.12 LED view. */
|
||||
const callLeds = rpc.declare({
|
||||
object: 'luci',
|
||||
method: 'getLEDs',
|
||||
expect: { '': {} }
|
||||
});
|
||||
|
||||
return view.extend({
|
||||
load() {
|
||||
return Promise.all([
|
||||
callLeds(),
|
||||
L.resolveDefault(fs.list('/www' + L.resource('view/system/led-trigger')), [])
|
||||
]).then(function([leds, plugins]) {
|
||||
const tasks = [];
|
||||
|
||||
for (let p of plugins) {
|
||||
const m = p.name.match(/^(.+)\.js$/);
|
||||
if (p.type != 'file' || m == null)
|
||||
continue;
|
||||
|
||||
tasks.push(L.require('view.system.led-trigger.' + m[1]).then(L.bind(function(name) {
|
||||
return L.resolveDefault(L.require('view.system.led-trigger.' + name)).then(function(form) {
|
||||
return { name: name, form: form };
|
||||
});
|
||||
}, this, m[1])));
|
||||
}
|
||||
|
||||
return Promise.all(tasks).then(function(plugins) {
|
||||
return [leds, plugins];
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
render([leds, plugins]) {
|
||||
let m, s, o;
|
||||
const triggers = [];
|
||||
for (let k in leds)
|
||||
for (let t of leds[k].triggers)
|
||||
triggers.push(t);
|
||||
|
||||
m = new form.Map('system',
|
||||
_('<abbr title="Light Emitting Diode">LED</abbr> Configuration'),
|
||||
_('Customizes the behaviour of the device <abbr title="Light Emitting Diode">LED</abbr>s if possible.'));
|
||||
|
||||
/* One RGB signal lamp and one separate Wi-Fi lamp. A single sysfs LED
|
||||
* action cannot disable all RGB channels, while led-status would also
|
||||
* overwrite its brightness at the next state change. */
|
||||
s = m.section(form.NamedSection, 'mu300_leds', 'mu300_leds', _('Physical status lamps'));
|
||||
s.anonymous = true;
|
||||
s.addremove = false;
|
||||
o = s.option(form.Flag, 'signal', _('Signal lamp (LTE / 5G / no service)'));
|
||||
o.default = '1';
|
||||
o.rmempty = false;
|
||||
o = s.option(form.Flag, 'wifi', _('Wi-Fi hotspot lamp'));
|
||||
o.default = '1';
|
||||
o.rmempty = false;
|
||||
|
||||
s = m.section(form.GridSection, 'led', '');
|
||||
s.anonymous = true;
|
||||
s.addremove = true;
|
||||
s.sortable = true;
|
||||
s.addbtntitle = _('Add LED action');
|
||||
s.nodescriptions = true;
|
||||
|
||||
s.option(form.Value, 'name', _('Name'));
|
||||
o = s.option(form.ListValue, 'sysfs', _('<abbr title="Light Emitting Diode">LED</abbr> Name'));
|
||||
Object.keys(leds).sort().forEach(function(name) {
|
||||
o.value(name);
|
||||
});
|
||||
o = s.option(form.ListValue, 'trigger', _('Trigger'));
|
||||
for (let plugin of plugins) {
|
||||
if (plugin.form.kernel == false) {
|
||||
o.value(plugin.name, plugin.form.trigger);
|
||||
} else if (triggers.indexOf(plugin.name) >= 0) {
|
||||
o.value(plugin.name, plugin.form.trigger);
|
||||
}
|
||||
}
|
||||
o.onchange = function(ev, section, value) {
|
||||
const nes = this.map.findElement('id', 'cbid.system.%s.trigger'.format(section)).nextElementSibling;
|
||||
for (let plugin of plugins) {
|
||||
if (plugin.name === value && nes)
|
||||
nes.innerText = plugin.form.description || '';
|
||||
}
|
||||
};
|
||||
o.load = function(section_id) {
|
||||
const trigger = uci.get('system', section_id, 'trigger');
|
||||
for (let plugin of plugins) {
|
||||
if (plugin.name === trigger)
|
||||
this.description = plugin.form.description || ' ';
|
||||
}
|
||||
return trigger;
|
||||
};
|
||||
s.addModalOptions = function(s) {
|
||||
for (let plugin of plugins)
|
||||
plugin.form.addFormOptions(s);
|
||||
|
||||
const opts = s.getOption();
|
||||
const removeIfNoneActive = function(original_remove_fn, section_id) {
|
||||
let isAnyActive = false;
|
||||
for (let optname in opts) {
|
||||
if (opts[optname].ucioption != this.ucioption)
|
||||
continue;
|
||||
if (!opts[optname].isActive(section_id))
|
||||
continue;
|
||||
isAnyActive = true;
|
||||
break;
|
||||
}
|
||||
if (!isAnyActive)
|
||||
original_remove_fn.call(this, section_id);
|
||||
};
|
||||
|
||||
for (let optname in opts) {
|
||||
if (!opts[optname].ucioption || optname == opts[optname].ucioption)
|
||||
continue;
|
||||
opts[optname].remove = removeIfNoneActive.bind(opts[optname], opts[optname].remove);
|
||||
}
|
||||
};
|
||||
o = s.option(form.Value, 'interval', _('Interval'), _('milliseconds'));
|
||||
o.placeholder = '50';
|
||||
|
||||
return m.render();
|
||||
}
|
||||
});
|
||||
@@ -45,6 +45,10 @@ fi
|
||||
STATE_FILE=/run/led-status.state
|
||||
WIFI_FILE=/run/led-status.wifi
|
||||
BLINK_PID=/run/led-status.blink.pid
|
||||
SIGNAL_ENABLED=$(uci -q get system.mu300_leds.signal 2>/dev/null)
|
||||
WIFI_ENABLED=$(uci -q get system.mu300_leds.wifi 2>/dev/null)
|
||||
[ "$SIGNAL_ENABLED" = 0 ] || SIGNAL_ENABLED=1
|
||||
[ "$WIFI_ENABLED" = 0 ] || WIFI_ENABLED=1
|
||||
|
||||
# Status reads must be side-effect free. In particular, dashboards and event
|
||||
# handlers may query this during boot and must not stop the chase animation.
|
||||
@@ -53,6 +57,19 @@ if [ "${1:-}" = current ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# LuCI's System > LED Configuration stores the two physical lamps separately.
|
||||
# Reapply their current logical states after a UCI reload without waiting for
|
||||
# the next modem or hostapd event.
|
||||
if [ "${1:-}" = refresh ]; then
|
||||
case "$(cat "$WIFI_FILE" 2>/dev/null)" in
|
||||
on) "$0" wifi-on ;;
|
||||
*) "$0" wifi-off ;;
|
||||
esac
|
||||
state=$(cat "$STATE_FILE" 2>/dev/null)
|
||||
[ -n "$state" ] || state=offline
|
||||
exec "$0" "$state"
|
||||
fi
|
||||
|
||||
# WiFi changes must not cancel the boot chase, thermal alarm, or modem/network
|
||||
# animation. They only drive the F50's independent hotspot lamp.
|
||||
case "${1:-}" in
|
||||
@@ -61,7 +78,7 @@ wifi-on|wifi-off)
|
||||
echo "$wifi_state" > "$WIFI_FILE"
|
||||
if [ -n "$WIFI_LED" ]; then
|
||||
echo none > "$(dirname "$WIFI_LED")/trigger" 2>/dev/null
|
||||
[ "$wifi_state" = on ] && echo 127 > "$WIFI_LED" || echo 0 > "$WIFI_LED"
|
||||
[ "$wifi_state" = on ] && [ "$WIFI_ENABLED" = 1 ] && echo 127 > "$WIFI_LED" || echo 0 > "$WIFI_LED"
|
||||
fi
|
||||
exit 0 ;;
|
||||
esac
|
||||
@@ -76,6 +93,7 @@ for f in $(dirname "$LED_R")/trigger $(dirname "$LED_W")/trigger $(dirname "$LED
|
||||
done
|
||||
|
||||
set_rgb() { # R W B (0-255)
|
||||
[ "$SIGNAL_ENABLED" = 1 ] || set -- 0 0 0
|
||||
echo "${1:-0}" > "$LED_R" 2>/dev/null
|
||||
echo "${2:-0}" > "$LED_W" 2>/dev/null
|
||||
echo "${3:-0}" > "$LED_B" 2>/dev/null
|
||||
@@ -91,6 +109,7 @@ pause_us() {
|
||||
}
|
||||
|
||||
start_blink() { # R W B ON_MS OFF_MS
|
||||
[ "$SIGNAL_ENABLED" = 1 ] || { set_rgb 0 0 0; return 0; }
|
||||
_r=$1; _w=$2; _b=$3; _on=$4; _off=$5
|
||||
(
|
||||
while :; do
|
||||
@@ -108,6 +127,7 @@ start_blink() { # R W B ON_MS OFF_MS
|
||||
}
|
||||
|
||||
start_chase() {
|
||||
[ "$SIGNAL_ENABLED" = 1 ] || { set_rgb 0 0 0; return 0; }
|
||||
(
|
||||
while :; do
|
||||
echo 255 > "$LED_R" 2>/dev/null; echo 0 > "$LED_W" 2>/dev/null; echo 0 > "$LED_B" 2>/dev/null; pause_us 120000
|
||||
@@ -157,6 +177,6 @@ thermal) # red blink: SoC too hot (called by thermal-guard)
|
||||
current)
|
||||
cat "$STATE_FILE" 2>/dev/null || echo boot ;;
|
||||
*)
|
||||
echo "usage: $0 boot|modem|registering|online-4g|online-5g|offline|thermal|wifi-on|wifi-off|current" >&2
|
||||
echo "usage: $0 boot|modem|registering|online-4g|online-5g|offline|thermal|wifi-on|wifi-off|current|refresh" >&2
|
||||
exit 1 ;;
|
||||
esac
|
||||
Reference in new issue
Block a user