c69cb9e1c4c76713c2be55fdb55fb1b16630436f
[openwrt/svn-archive/archive.git] / target / linux / ramips / base-files / etc / diag.sh
1 #!/bin/sh
2 #
3 # Copyright (C) 2010 OpenWrt.org
4 #
5 #
6
7 . /lib/ramips.sh
8
9 status_led=""
10
11 led_set_attr() {
12 [ -f "/sys/class/leds/$1/$2" ] && echo "$3" > "/sys/class/leds/$1/$2"
13 }
14
15 status_led_set_timer() {
16 led_set_attr $status_led "trigger" "timer"
17 led_set_attr $status_led "delay_on" "$1"
18 led_set_attr $status_led "delay_off" "$2"
19 }
20
21 status_led_on() {
22 led_set_attr $status_led "trigger" "none"
23 led_set_attr $status_led "brightness" 255
24 }
25
26 status_led_off() {
27 led_set_attr $status_led "trigger" "none"
28 led_set_attr $status_led "brightness" 0
29 }
30
31 get_status_led() {
32 case $(ramips_board_name) in
33 dir-300-b1)
34 status_led="dir-300b:green:status"
35 ;;
36 fonera20n)
37 status_led="fonera20n:green:power"
38 ;;
39 v22rw-2x2)
40 status_led="v22rw-2x2:green:security"
41 ;;
42 whr-g300n)
43 status_led="whr-g300n:red:diag"
44 ;;
45 esac;
46 }
47
48 set_state() {
49 get_status_led
50
51 case "$1" in
52 preinit)
53 insmod leds-gpio
54 status_led_set_timer 200 200
55 ;;
56 failsafe)
57 status_led_set_timer 50 50
58 ;;
59 done)
60 status_led_on
61 ;;
62 esac
63 }