diff --git a/package/base-files/files/etc/init.d/led b/package/base-files/files/etc/init.d/led index 4d3feddf649..ea2688cab29 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 ] || {