v1.5 branch refresh based upon upstream master @ c8677ca89e53e3be7988d54280fce166cc894a7e
[librecmc/librecmc.git] / package / base-files / files / lib / functions / leds.sh
index 857e7e53927b04d25b7e54e6e8b3fcdc118d3a9c..8a1d21caeff382a5bdbb79f492a133ec0a1b31a4 100644 (file)
@@ -1,6 +1,20 @@
 #!/bin/sh
 # Copyright (C) 2013 OpenWrt.org
 
+get_dt_led() {
+       local label
+       local ledpath
+       local basepath="/proc/device-tree"
+       local nodepath="$basepath/aliases/led-$1"
+
+       [ -f "$nodepath" ] && ledpath=$(cat "$nodepath")
+       [ -n "$ledpath" ] && \
+               label=$(cat "$basepath$ledpath/label" 2>/dev/null) || \
+               label=$(cat "$basepath$ledpath/chan-name" 2>/dev/null)
+
+       echo "$label"
+}
+
 led_set_attr() {
        [ -f "/sys/class/leds/$1/$2" ] && echo "$3" > "/sys/class/leds/$1/$2"
 }