leds.sh 1.4 KB

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