#!/bin/bash

DEVICE_TYPE=$1
paramnum="$#"

show_usage()
{
	echo "Usage:"
	echo ""
	echo " alsa_setup [DEVICE_TYPE]"
	echo ""
	echo " Valid DEVICE_TYPE: "
	echo "   nq-voip"
	echo "   nq-mix"
	echo "   nq-asb"
	echo "   nq-ga20p2"
}

check_num_parameters()
{
        # Exit if number of parameters are incorrect
        expectedparamnum=$1
        if [ "$paramnum" -ne $expectedparamnum ]; then
		echo "Expected $expectedparamnum arguments - exiting"
		show_usage
                exit 1
        fi
}

check_num_parameters 1

#For VoIP Speaker
if [ "$DEVICE_TYPE" == "nq-voip" ]; then
	#echo "Adjusting VoIP Settings"
	amixer set 'DSP Setting' Off >/dev/null 2>&1 
	amixer set 'ADCFGA Left Mute' mute >/dev/null 2>&1 
	amixer set 'ADCFGA Right Mute' mute >/dev/null 2>&1
	amixer set 'LO DAC' unmute >/dev/null 2>&1
	amixer set 'LOL Output Mixer L_DAC' unmute >/dev/null 2>&1
	amixer set 'LOR Output Mixer R_DAC' unmute >/dev/null 2>&1
	amixer set 'HPL Output Mixer IN1_L' mute > /dev/null 2>&1
	amixer set 'HP Driver Gain' 0 > /dev/null 2>&1
	amixer set 'IN1_L to Left Mixer Positive Resistor' '10 kOhm' >/dev/null 2>&1
	amixer set 'IN1_L to Right Mixer Positive Resistor' 'Off' >/dev/null 2>&1
	amixer set 'IN1_R to Left Mixer Positive Resistor' 'Off' >/dev/null 2>&1
	amixer set 'IN1_R to Right Mixer Positive Resistor' '10 kOhm' >/dev/null 2>&1
elif [ "$DEVICE_TYPE" == "nq-asb" ]; then
	#echo "Adjusting ASB Settings"
	amixer set 'DSP Setting' ASB >/dev/null 2>&1 
	amixer set 'ADCFGA Left Mute' mute >/dev/null 2>&1 
	amixer set 'ADCFGA Right Mute' mute >/dev/null 2>&1
	amixer set 'ADC Level' 24 > /dev/null 2>&1
	amixer set 'LO DAC' unmute >/dev/null 2>&1
	amixer set 'LOL Output Mixer L_DAC' unmute >/dev/null 2>&1
	amixer set 'LOR Output Mixer R_DAC' unmute >/dev/null 2>&1
	amixer set 'LO Driver Gain' 0 >/dev/null 2>&1
	amixer set 'HPL Output Mixer IN1_L' unmute > /dev/null 2>&1
	amixer set 'IN1_L to Left Mixer Positive Resistor' '20 kOhm' >/dev/null 2>&1
	amixer set 'IN1_L to Right Mixer Positive Resistor' 'Off' >/dev/null 2>&1
	amixer set 'IN1_R to Left Mixer Positive Resistor' 'Off' >/dev/null 2>&1
	amixer set 'IN1_R to Right Mixer Positive Resistor' '20 kOhm' >/dev/null 2>&1
	amixer set 'PGA Level' 0 > /dev/null 2>&1
elif [ "$DEVICE_TYPE" == "nq-ga10p" ]; then
	#echo "Adjusting GA10P Settings"
	amixer set 'DSP Setting' Off >/dev/null 2>&1 
	amixer set 'ADCFGA Left Mute' mute >/dev/null 2>&1 
	amixer set 'ADCFGA Right Mute' mute >/dev/null 2>&1
	amixer set 'LO DAC' unmute >/dev/null 2>&1
	amixer set 'LOL Output Mixer L_DAC' unmute >/dev/null 2>&1
	amixer set 'LOR Output Mixer R_DAC' unmute >/dev/null 2>&1
	amixer set 'HPL Output Mixer IN1_L' mute > /dev/null 2>&1
	amixer set 'HP Driver Gain' 0 > /dev/null 2>&1
	amixer set 'IN1_L to Right Mixer Negative Resistor' '10 kOhm' >/dev/null 2>&1
	amixer set 'IN1_L to Right Mixer Positive Resistor' 'Off' >/dev/null 2>&1
	amixer set 'IN1_R to Left Mixer Positive Resistor' 'Off' >/dev/null 2>&1
	amixer set 'IN1_R to Right Mixer Positive Resistor' '10 kOhm' >/dev/null 2>&1
elif [ "$DEVICE_TYPE" == "nq-ga20p2" ]; then
	echo "Adjusting GA20P2 Settings"
        amixer set 'CH1' 255 >/dev/null 2>&1
#elif [ "$DEVICE_TYPE" == "nq-mix" ]; then
	#echo "Adjusting Mixer Settings"
else
	echo "No ALSA Settings to adjust for device $DEVICE_TYPE"
fi

