volumed 1.36 KB
Newer Older
aTc's avatar
aTc committed
1
#!/bin/sh
aTc's avatar
aTc committed
2 3 4
#
# Pyra volume control daemon
#
5 6
SCRIPTPATH="$(dirname "$0")"
GPADC=$($SCRIPTPATH/findiio "palmas-gpadc")
aTc's avatar
aTc committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28

[ "$GPADC" ] || exit 1

LASTVOL="unknown"
MAXWHEEL=1200	# reports 0..1250 mV but leave some margin

while [ "$1" ]
do
        case "$1" in
        "-q" )
		QUIET=true
		;;
        "-nhf" )
		NOHANDSFREE=yes
		;;
	* )
		break
		;;
	esac
	shift
done

29
NUM=$($SCRIPTPATH/findsoundcard "L15")	# twl6040 on Pyra
aTc's avatar
aTc committed
30

aTc's avatar
aTc committed
31 32 33 34 35 36 37 38 39
while true
do
	WHEEL=$(cat $GPADC/in_voltage2_input 2>/dev/null)
	# could apply non-linear scale for more intuitive control
	VOL=$(( 100 * ${WHEEL:-0} / $MAXWHEEL ))
	[ "$VOL" -lt 0 ] && VOL=0
	[ "$VOL" -gt 100 ] && VOL=100
	# should check for abs($VOL-$LASTVOL) > threshold
	if [ "$VOL" != "$LASTVOL" ]
aTc's avatar
aTc committed
40
	then # update only if changed since amixer -c "$NUM" command needs some resources
aTc's avatar
aTc committed
41 42 43
		[ "$QUIET" ] || echo $WHEEL - $VOL%
		if [ "$NOHANDSFREE" -o "$VOL" = 0 ]
		then # turn off
aTc's avatar
aTc committed
44 45
			amixer -c "$NUM" -q set "Handsfree Left Playback" "Off" || exit
			amixer -c "$NUM" -q set "Handsfree Right Playback" "Off" || exit
aTc's avatar
aTc committed
46
		else
aTc's avatar
aTc committed
47 48 49
			amixer -c "$NUM" -q set "Handsfree Left Playback" "HF DAC" || exit
			amixer -c "$NUM" -q set "Handsfree Right Playback" "HF DAC" || exit
			amixer -c "$NUM" -q set "Handsfree" "$VOL%" || exit
aTc's avatar
aTc committed
50
		fi
aTc's avatar
aTc committed
51 52
		amixer -c "$NUM" -q set "Headset" "$VOL%" || exit
		amixer -c "$NUM" -q set "Earphone" "$VOL%" || exit
aTc's avatar
aTc committed
53 54 55
		LASTVOL=$VOL
	fi
	sleep 0.1
56
done