audio_amp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/bin/sh
  2. # Uncomment the following line to get debug info
  3. #set -x
  4. SELF="$(basename ${0})"
  5. SYSTEM_GPIO="/sys/class/gpio"
  6. # Power Audio Amplifier enable GPIO (('F' - 'A') * 32 + 6 = 166)
  7. GPIO_PF6=166
  8. usage() {
  9. >2& echo "Usage: ${SELF} [1|on|ON|On for ON, 0|off|OFF|Off for OFF]"
  10. exit 1
  11. }
  12. # Check number of arguments
  13. if [ ${#} -ne 1 ]; then
  14. usage
  15. fi
  16. case "${1}" in
  17. 1|on|ON|On)
  18. # Turn ON only if volume is not null
  19. if [ "$(volume get)" -ne "0" ]; then
  20. echo "Turning audio amplifier ON"
  21. else
  22. exit 0
  23. fi
  24. new_state=1
  25. ;;
  26. 0|off|OFF|Off)
  27. echo "Turning audio amplifier OFF"
  28. new_state=0
  29. ;;
  30. *)
  31. usage
  32. ;;
  33. esac
  34. # Export the GPIO if necessary
  35. if [ ! -d "${SYSTEM_GPIO}/gpio${GPIO_PF6}" ]; then
  36. echo ${GPIO_PF6} > "${SYSTEM_GPIO}/export"
  37. fi
  38. # Set the power audio amplifier GPIO as output
  39. echo "out" > "${SYSTEM_GPIO}/gpio${GPIO_PF6}/direction"
  40. # Read the current power audio amplifier state
  41. current_state=$(cat "${SYSTEM_GPIO}/gpio${GPIO_PF6}/value")
  42. # Enable/disable the power audio amplifier if necessary
  43. if [ ${current_state} -ne ${new_state} ]; then
  44. echo ${new_state} > "${SYSTEM_GPIO}/gpio${GPIO_PF6}/value"
  45. fi
  46. exit 0