led 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2008 OpenWrt.org
  3. START=96
  4. load_led() {
  5. local name
  6. local sysfs
  7. local trigger
  8. local dev
  9. local mode
  10. local default
  11. local delayon
  12. local delayoff
  13. local interval
  14. config_get sysfs $1 sysfs
  15. config_get name $1 name "$sysfs"
  16. config_get trigger $1 trigger "none"
  17. config_get dev $1 dev
  18. config_get mode $1 mode "link"
  19. config_get_bool default $1 default "nil"
  20. config_get delayon $1 delayon
  21. config_get delayoff $1 delayoff
  22. config_get interval $1 interval "50"
  23. config_get port_state $1 port_state
  24. config_get delay $1 delay "150"
  25. config_get message $1 message ""
  26. if [ "$trigger" = "rssi" ]; then
  27. # handled by rssileds userspace process
  28. return
  29. fi
  30. [ -e /sys/class/leds/${sysfs}/brightness ] && {
  31. echo "setting up led ${name}"
  32. [ "$default" = 0 ] &&
  33. echo 0 >/sys/class/leds/${sysfs}/brightness
  34. echo $trigger > /sys/class/leds/${sysfs}/trigger 2> /dev/null
  35. ret="$?"
  36. [ $default = 1 ] &&
  37. echo 1 >/sys/class/leds/${sysfs}/brightness
  38. [ $ret = 0 ] || {
  39. echo >&2 "Skipping trigger '$trigger' for led '$name' due to missing kernel module"
  40. return 1
  41. }
  42. case "$trigger" in
  43. "netdev")
  44. [ -n "$dev" ] && {
  45. echo $dev > /sys/class/leds/${sysfs}/device_name
  46. echo $mode > /sys/class/leds/${sysfs}/mode
  47. }
  48. ;;
  49. "timer")
  50. [ -n "$delayon" ] && \
  51. echo $delayon > /sys/class/leds/${sysfs}/delay_on
  52. [ -n "$delayoff" ] && \
  53. echo $delayoff > /sys/class/leds/${sysfs}/delay_off
  54. ;;
  55. "usbdev")
  56. [ -n "$dev" ] && {
  57. echo $dev > /sys/class/leds/${sysfs}/device_name
  58. echo $interval > /sys/class/leds/${sysfs}/activity_interval
  59. }
  60. ;;
  61. "port_state")
  62. [ -n "$port_state" ] && \
  63. echo $port_state > /sys/class/leds/${sysfs}/port_state
  64. ;;
  65. "morse")
  66. echo $message > /sys/class/leds/${sysfs}/message
  67. echo $delay > /sys/class/leds/${sysfs}/delay
  68. ;;
  69. switch[0-9]*)
  70. local port_mask
  71. config_get port_mask $1 port_mask
  72. [ -n "$port_mask" ] && \
  73. echo $port_mask > /sys/class/leds/${sysfs}/port_mask
  74. ;;
  75. esac
  76. }
  77. }
  78. start() {
  79. [ -e /sys/class/leds/ ] && {
  80. config_load system
  81. config_foreach load_led led
  82. }
  83. }