# Reference:
# https://gitlab.manjaro.org/manjaro-arm/packages/community/pinebookpro-post-install/-/blob/4b4206c57b21044bf9c00848bd1f8b6f710d19eb/asound.state
# https://gitlab.manjaro.org/manjaro-arm/packages/community/pinebookpro-audio/-/blob/1f567db09495acc3beb5405c9ef85c3c07b86785/audio_jack_plugged_in.sh
Define.MainCardId "rockchipes8326c"
Define.BtCardId "rockchipbt"
Define.Bluetooth "bluealsa"

SectionVerb {
	EnableSequence [
		exec "/usr/bin/logger -t UCM -p info Hii_dvt:SectionVerb:EnableSequence"
		cdev "hw:${var:MainCardId}"
		cset "name='Speakers Switch' off"
		cset "name='Main Mic Switch' off"
		cset "name='Headphone Switch' off"
		cset "name='Headset Mic Switch' off"
		cset "name='I2STDM Digital Loopback Mode' on"
	]

	DisableSequence [
		exec "/usr/bin/logger -t UCM -p info Hii_dvt:SectionVerb:DisableSequence"
		cdev "hw:${var:MainCardId}"
		cset "name='I2STDM Digital Loopback Mode' off"
	]

	Value {
		Priority 200
	}
}

SectionDevice."Speaker" {
	Comment "VC Speaker"

	ConflictingDevice [
		"Headphones"
		"Headset"
	]

	EnableSequence [
		exec "/usr/bin/logger -t UCM -p info vc_dvt:Speaker:EnableSequence"
		# Enable Speaker
		cdev "hw:${var:MainCardId}"
		cset "name='Speakers Switch' on"
	]

	DisableSequence [
		exec "/usr/bin/logger -t UCM -p info vc_dvt:Speaker:DisableSequence"
		# Disable Speaker
		cdev "hw:${var:MainCardId}"
		cset "name='Speakers Switch' off"
	]

	Value {
		#-# PlaybackPriority 100
		PlaybackPriority 400
		PlaybackPCM "hw:${var:MainCardId}"
		PlaybackMasterElem "DAC Playback Volume"
		PlaybackVolume "DAC Playback Volume"
		PlaybackSwitch "Speakers Switch"
	}
}

SectionDevice."Earpiece" {
	Comment "VC Earpiece"
	EnableSequence {
		# exec "/usr/bin/logger -t UCM -p info VoiceCall_dvt:Earpiece:EnableSequence"
		cset "name='Earpiece Playback Switch' on"
		cset "name='Earpiece Playback Volume' 100%"
		cset "name='Earpiece Mic Switch' on"
	}

	DisableSequence [
		exec "/usr/bin/logger -t UCM -p info VoiceCall_dvt:Earpiece:DisableSequence"
		cset "name='Earpiece Playback Switch' off"	# unable to execute cset 'name='Earpiece Playback Switch' off'
		cset "name='Earpiece Mic Switch' off"
	]

	Value {
		PlaybackVolume "Earpiece Playback Volume"
		PlaybackSwitch "Earpiece Playback Switch"
		PlaybackChannels "2"
		PlaybackPriority 300
		PlaybackPCM "hw:${var:MainCardId}"
	}
}

SectionDevice."Mic" {
	Comment "Internal Microphone"

	ConflictingDevice [
		"Headset"
	]

	EnableSequence [
		exec "/usr/bin/logger -t UCM -p info vc_dvt:Mic:EnableSequence"
		# Enable Mic
		cdev "hw:${var:MainCardId}"
		cset "name='Main Mic Switch' on"
	]

	DisableSequence [
		exec "/usr/bin/logger -t UCM -p info vc_dvt:Mic:DisableSequence"
		# Disable Mic
		cdev "hw:${var:MainCardId}"
		cset "name='Main Mic Switch' off"
	]

	Value {
		CapturePriority 200
		CaptureChannels "6"
		CapturePCM "hw:${var:MainCardId},1"
		CaptureMixerElem "ADC"
		CaptureSwitch "Main Mic Switch"
	}
}

SectionDevice."Headphones" {
	Comment "Headphones"

	ConflictingDevice [
		"Speaker"
		"Headset"
	]

	EnableSequence [
		exec "/usr/bin/logger -t UCM -p info vc_dvt:Headphones:EnableSequence"
		cdev "hw:${var:MainCardId}"
		cset "name='Headphone Switch' on"
	]

	DisableSequence [
		exec "/usr/bin/logger -t UCM -p info vc_dvt:Headphones:DisableSequence"
		cdev "hw:${var:MainCardId}"
		cset "name='Headphone Switch' off"
	]

	Value {
		PlaybackPriority 200
		PlaybackPCM "hw:${var:MainCardId}"
		PlaybackMasterElem "DAC Playback Volume"
		PlaybackVolume "DAC Playback Volume"
		PlaybackSwitch "Headphone Switch"
		JackControl "Headphone Jack"
		JackHWMute "Speaker"
	}
}

SectionDevice."Headset" {
	Comment "Headset"

	ConflictingDevice [
		"Speaker"
		"Headphones"
		"Mic"
	]

	EnableSequence [
		exec "/usr/bin/logger -t UCM -p info vc_dvt:Headset:EnableSequence"
		cdev "hw:${var:MainCardId}"
		cset "name='Headphone Switch' on"
		cset "name='Headset Mic Switch' on"
	]

	DisableSequence [
		exec "/usr/bin/logger -t UCM -p info vc_dvt:Headset:DisableSequence"
		cdev "hw:${var:MainCardId}"
		cset "name='Headphone Switch' off"
		cset "name='Headset Mic Switch' off"
	]

	Value {
		PlaybackPriority 200
		PlaybackPCM "hw:${var:MainCardId}"
		CapturePCM "hw:${var:MainCardId}"
		PlaybackMasterElem "DAC Playback Volume"
		PlaybackVolume "DAC Playback Volume"
		PlaybackSwitch "Headphone Switch"
		CaptureMasterElem "ADC Capture Volume"
		CaptureVolume "ADC Capture Volume"
		CaptureSwitch "Headset Mic Switch"
		JackControl "Headphone Jack"
		JackHWMute "Speaker"
	}
}
