base-files: unify get_dt_led helper function
[openwrt/openwrt.git] / target / linux / lantiq / base-files / etc / diag.sh
index 9e0e1701cb62025e5fb896891ada43f8cba20d98..4fb47bd2731828316cdadb7fe930ef4e353d7571 100644 (file)
@@ -1,24 +1,37 @@
 #!/bin/sh
-# Copyright (C) 2012-2013 OpenWrt.org
+# Copyright (C) 2010-2015 OpenWrt.org
 
 . /lib/functions/leds.sh
 
-status_led="power"
+boot="$(get_dt_led boot)"
+failsafe="$(get_dt_led failsafe)"
+running="$(get_dt_led running)"
 
 set_state() {
+       status_led="$boot"
+
        case "$1" in
        preinit)
-               status_led_set_heartbeat
+               status_led_blink_preinit
                ;;
        failsafe)
-               [ -d /sys/class/leds/power1 ] && {
+               status_led_off
+               [ -n "$running" ] && {
+                       status_led="$running"
                        status_led_off
-                       led_timer "power1" 100 100
-               } || status_led_set_timer 100 100
+               }
+               status_led="$failsafe"
+               status_led_blink_failsafe
+               ;;
+       preinit_regular)
+               status_led_blink_preinit_regular
                ;;
        done)
-               status_led_on
-               led_off "power1"
+               status_led_off
+               [ -n "$running" ] && {
+                       status_led="$running"
+                       status_led_on
+               }
                ;;
        esac
 }