⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ag_microphone.c

📁 bluetooth audio gateway
💻 C
字号:
#include "ag_private.h"
#include "ag.h"

#include <stdlib.h>
#include <string.h>


/*
    sendMicrophoneGain

    Send out a microphone gain AT cmd
*/
static void sendMicrophoneGain(uint8 gain)
{
    /* 
        Check gain is in the range allowed by the supported profile. 
        Gain is unsigned so will always be >= zero 
    */
    if (gain <= 15)
    {
        uint8 *ptr;
        const char *at_mic_str = "\r\n+VGM=??\r\n";
        uint16 buflen = strlen(at_mic_str);
        char *buf = (char *) agAlloc(buflen);
        memcpy(buf, at_mic_str, buflen);
        ptr = (uint8 *)buf;
        
        while (*ptr != '=')
            ptr ++ ;
        
        /* insert the mic gain */
        ptr[1] = '0' + gain /10;
        ptr[2] = '0' + gain % 10;
        
        /* TODO maybe should set a pending flag in case this fails */
        (void) agSendATmessage(buf, buflen);
        
        agMicChangeInd(AGState.remote_addr, gain);
        
        free(buf);
    }
    /* TODO else send error to app telling it gain was not in range */    
}


/*
    agMicChangeReqAction

    Request to send a set microphone gain AT command.
    Because this is not supported internally i.e. you cannot set the 
    mic gain on the EAG (in the same way that you can set the volume 
    level for example) this function just checks the parameters sent
    to it are valid and sends out the AT command.
*/
void agMicChangeReqAction(uint8 gain)
{
    if (agIsCurrentlyHandsFree())
    {
        /* HFP does not need SCO to be up to send mic gain */
        sendMicrophoneGain(gain);
    }
    else
    {
        /* Make sure there is a SCO connected */ 
        if (agScoConnectedQuery())
            sendMicrophoneGain(gain);
        else
            agSendErrorToClient(AgErrorUnexpectedPrimitive, 0);
    }
}


/*
    agMicChangeInd

    Inform the user of a change in the microphone gain. Similarly to the
    volume command, this is generated when a VGM AT command is received
    from the remote device.
*/
void agMicChangeInd(BD_ADDR_T addr, uint16 gain)
{
    /* inform the interface */
    handleMicrophoneChangeInd(agGetConnectionHandle(&addr), (uint8) gain);    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -