#!/bin/sh
# Wrapper script for q6voiced: this tries to guess the correct ALSA card and
# device IDs based on the main device-tree "compatible"

# shellcheck disable=SC2198
# This works as $@ is converted to a string by concatenating its components
if [ -z "$@" ]; then
    # Most devices use hw:0,4 for the voice call interface
    q6voice_card=0
    q6voice_device=4

    for _dt_compatible in $(tr '\0' ' ' < /proc/device-tree/compatible); do
        # Override the device ID only if/when needed
        case "$_dt_compatible" in
            "shift,axolotl")
                q6voice_device=12
                ;;
            "oneplus,enchilada"|"oneplus,fajita")
                q6voice_device=6
                ;;
        esac
    done

    /usr/libexec/q6voiced "hw:${q6voice_card},${q6voice_device}"
else
    # shellcheck disable=SC2068
    /usr/libexec/q6voiced $@
fi
