volume_set 967 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/bin/sh
  2. # Check args
  3. if [ ${#} -ne 1 ]; then
  4. echo "Usage: $(basename ${0}) new_volume_percentage"
  5. exit 1
  6. fi
  7. # Check value's range
  8. if [ ${1} -gt 100 ]; then
  9. echo "Usage: Wrong volume percentage (${1}), must be between 0 and 100"
  10. exit 1
  11. fi
  12. # Scale new volume value between 0 and 63
  13. volume_percent=${1}
  14. vol_mini=16;
  15. volume_scaled=$(echo "a = $volume_percent * (63 - $vol_mini) / 100 + $vol_mini + 0.5; scale = 0; a / 1" | bc -l)
  16. #echo $volume_scaled
  17. # Get current value
  18. current_volume=$(volume_get)
  19. # Set new volume
  20. amixer -q sset 'Headphone' ${volume_scaled} unmute
  21. # Change new volume value in volume file
  22. if [ ${?} -eq 0 -a ${current_volume} -ne ${volume_percent} ]; then
  23. fw_setenv volume ${volume_percent}
  24. fi
  25. # Turn on/off audio amplifier if necessary
  26. if [ ${current_volume} -eq 0 -a ${volume_percent} -ne 0 ]; then
  27. start_audio_amp 1
  28. elif [ ${current_volume} -ne 0 -a ${volume_percent} -eq 0 ]; then
  29. start_audio_amp 0
  30. fi
  31. exit 0