From: Florian Eckert Date: Thu, 1 Feb 2024 11:51:02 +0000 (+0100) Subject: base-files/leds: add setting the LED color via uci X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=c6fabd0bc3354099bcfc73aa4064139b23fb509d;p=openwrt%2Fstaging%2Fblogic.git base-files/leds: add setting the LED color via uci Add the possibility that colored LEDs can also be configured via the uci. config led 'led1' option name '' option sysfs '' option trigger 'default-on' option default '1' --> option color_{$color} '<0-255>' The supported names of the variable "${color}" for the selected LED can be queried in the file with the name 'multi_index'. Signed-off-by: Florian Eckert --- diff --git a/package/base-files/files/etc/init.d/led b/package/base-files/files/etc/init.d/led index 4d3feddf649b..ea2688cab29e 100755 --- a/package/base-files/files/etc/init.d/led +++ b/package/base-files/files/etc/init.d/led @@ -3,6 +3,39 @@ START=96 +led_color_set() { + local cfg="$1" + local sysfs="$2" + + local max_b + local colors + local color + local multi_intensity + local value + local write + + [ -e /sys/class/leds/${sysfs}/multi_intensity ] || return + [ -e /sys/class/leds/${sysfs}/multi_index ] || return + + max_b="$(cat /sys/class/leds/${sysfs}/max_brightness)" + colors="$(cat /sys/class/leds/${sysfs}/multi_index | tr " " "\n")" + multi_intensity="" + for color in $colors; do + config_get value $1 "color_${color}" "0" + [ "$value" -gt 0 ] && write=1 + [ "$value" -gt "$max_b" ] && value="$max_b" + multi_intensity="${multi_intensity}${value} " + done + + # Check if any color is configured + [ "$write" = 1 ] || return + # Remove last whitespace + multi_intensity="${multi_intensity:0:-1}" + + echo "setting '${name}' led color to '${multi_intensity}'" + echo "${multi_intensity}" > /sys/class/leds/${sysfs}/multi_intensity +} + load_led() { local name local sysfs @@ -68,6 +101,8 @@ load_led() { [ $default = 1 ] && cat /sys/class/leds/${sysfs}/max_brightness > /sys/class/leds/${sysfs}/brightness + led_color_set "$1" "$sysfs" + echo $trigger > /sys/class/leds/${sysfs}/trigger 2> /dev/null ret="$?" [ $ret = 0 ] || {