leds.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/sh
  2. # Copyright (C) 2013 OpenWrt.org
  3. led_set_attr() {
  4. [ -f "/sys/class/leds/$1/$2" ] && echo "$3" > "/sys/class/leds/$1/$2"
  5. }
  6. led_timer() {
  7. led_set_attr $1 "trigger" "timer"
  8. led_set_attr $1 "delay_on" "$2"
  9. led_set_attr $1 "delay_off" "$3"
  10. }
  11. led_on() {
  12. led_set_attr $1 "trigger" "none"
  13. led_set_attr $1 "brightness" 255
  14. }
  15. led_off() {
  16. led_set_attr $1 "trigger" "none"
  17. led_set_attr $1 "brightness" 0
  18. }
  19. led_morse() {
  20. led_set_attr $1 "trigger" "morse"
  21. led_set_attr $1 "delay" "$2"
  22. led_set_attr $1 "message" "$3"
  23. }
  24. status_led_set_timer() {
  25. led_timer $status_led "$1" "$2"
  26. [ -n "$status_led2" ] && led_timer $status_led2 "$1" "$2"
  27. }
  28. status_led_set_heartbeat() {
  29. led_set_attr $status_led "trigger" "heartbeat"
  30. }
  31. status_led_set_morse() {
  32. led_morse $status_led "$1" "$2"
  33. [ -n "$status_led2" ] && led_morse $status_led2 "$1" "$2"
  34. }
  35. status_led_on() {
  36. led_on $status_led
  37. [ -n "$status_led2" ] && led_on $status_led2
  38. }
  39. status_led_off() {
  40. led_off $status_led
  41. [ -n "$status_led2" ] && led_off $status_led2
  42. }
  43. status_led_blink_slow() {
  44. led_timer $status_led 1000 1000
  45. }
  46. status_led_blink_fast() {
  47. led_timer $status_led 100 100
  48. }
  49. status_led_blink_preinit() {
  50. led_timer $status_led 100 100
  51. }
  52. status_led_blink_failsafe() {
  53. led_timer $status_led 50 50
  54. }
  55. status_led_blink_preinit_regular() {
  56. led_timer $status_led 200 200
  57. }