aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Eckert <fe@dev.tdt.de>2024-02-01 12:51:02 +0100
committerFlorian Eckert <fe@dev.tdt.de>2024-02-07 15:34:43 +0100
commitc6fabd0bc3354099bcfc73aa4064139b23fb509d (patch)
tree9baa6824b1a202e5b4881e5562d1eb60608b0e7e
parent3aa812d8bebdb40316d1d57150c766234f5245dd (diff)
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 '<name>' option sysfs '<path>' 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 <fe@dev.tdt.de>
-rwxr-xr-xpackage/base-files/files/etc/init.d/led35
1 files changed, 35 insertions, 0 deletions
diff --git a/package/base-files/files/etc/init.d/led b/package/base-files/files/etc/init.d/led
index 4d3feddf64..ea2688cab2 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 ] || {