#!/bin/bash
PART_NUM=$(cat /sys/devices/platform/bone_capemgr/slot-0/part-number)
echo -e "\033[1;33m\033[1mStartup - Adjusting VoIP Settings\033[0m"

if [[ "$PART_NUM" == "nq-voip" ]]; then
    echo -e "\033[1;33m\033[1m    Initialize ALSA settings for VoIP G1 Device\033[0m"
    amixer set 'DSP Setting' Off >/dev/null 2>&1 
    amixer set 'ADC Level' 0 > /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 'CM_L to Left Mixer Negative Resistor' '10 kOhm' >/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 [[ "$PART_NUM" == "nq-edp01" ]]; then
    echo -e "\033[1;33m\033[1m    Setting Rising Edge for EDP01 Device\033[0m"
    echo rising > /sys/class/gpio/gpio49/edge
else
    echo -e "\033[1;33m\033[1m    No settings to change for $PART_NUM Device\033[0m"
fi

VOLUME_SLIDER_FILE=/etc/nyquist/nyquist.volume
if [ ! -e "$VOLUME_SLIDER_FILE" ]; then
	touch $VOLUME_SLIDER_FILE
	echo "-20" >> $VOLUME_SLIDER_FILE
fi