led 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. config_get gpio $1 gpio "0"
  27. config_get inverted $1 inverted "0"
  28. if [ "$trigger" = "rssi" ]; then
  29. # handled by rssileds userspace process
  30. return
  31. fi
  32. [ -e /sys/class/leds/${sysfs}/brightness ] && {
  33. echo "setting up led ${name}"
  34. [ "$default" = 0 ] &&
  35. echo 0 >/sys/class/leds/${sysfs}/brightness
  36. echo $trigger > /sys/class/leds/${sysfs}/trigger 2> /dev/null
  37. ret="$?"
  38. [ $default = 1 ] &&
  39. cat /sys/class/leds/${sysfs}/max_brightness > /sys/class/leds/${sysfs}/brightness
  40. [ $ret = 0 ] || {
  41. echo >&2 "Skipping trigger '$trigger' for led '$name' due to missing kernel module"
  42. return 1
  43. }
  44. case "$trigger" in
  45. "netdev")
  46. [ -n "$dev" ] && {
  47. echo $dev > /sys/class/leds/${sysfs}/device_name
  48. echo $mode > /sys/class/leds/${sysfs}/mode
  49. }
  50. ;;
  51. "timer")
  52. [ -n "$delayon" ] && \
  53. echo $delayon > /sys/class/leds/${sysfs}/delay_on
  54. [ -n "$delayoff" ] && \
  55. echo $delayoff > /sys/class/leds/${sysfs}/delay_off
  56. ;;
  57. "usbdev")
  58. [ -n "$dev" ] && {
  59. echo $dev > /sys/class/leds/${sysfs}/device_name
  60. echo $interval > /sys/class/leds/${sysfs}/activity_interval
  61. }
  62. ;;
  63. "port_state")
  64. [ -n "$port_state" ] && \
  65. echo $port_state > /sys/class/leds/${sysfs}/port_state
  66. ;;
  67. "morse")
  68. echo $message > /sys/class/leds/${sysfs}/message
  69. echo $delay > /sys/class/leds/${sysfs}/delay
  70. ;;
  71. "gpio")
  72. echo $gpio > /sys/class/leds/${sysfs}/gpio
  73. echo $inverted > /sys/class/leds/${sysfs}/inverted
  74. ;;
  75. switch[0-9]*)
  76. local port_mask speed_mask
  77. config_get port_mask $1 port_mask
  78. [ -n "$port_mask" ] && \
  79. echo $port_mask > /sys/class/leds/${sysfs}/port_mask
  80. config_get speed_mask $1 speed_mask
  81. [ -n "$speed_mask" ] && \
  82. echo $speed_mask > /sys/class/leds/${sysfs}/speed_mask
  83. ;;
  84. esac
  85. }
  86. }
  87. start() {
  88. [ -e /sys/class/leds/ ] && {
  89. config_load system
  90. config_foreach load_led led
  91. }
  92. }