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

📄 ag_volume.c

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

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


/*
    sendVolCmd

    Internal function to actually send a new volume report to the
    client as well as sending a message to the Connection
    Manager.
*/
static void sendVolCmd(const char *at_vol_str)
{
    /* 
        Due to inconsistency between the HS and HF profile the 
        HF uses ':' while the HS uses '=' so the string is passed in
    */      
    uint8 *ptr;        
    uint16 buflen = strlen(at_vol_str);    
    
    char * buf = (char *) agAlloc(buflen);
    memcpy(buf, at_vol_str, buflen);
    ptr = (uint8 *)buf;        

    while ((*ptr != '=') && (*ptr != ':'))        
        ptr ++ ;

    ptr[1] = '0' + AGState.speakerGain /10;
    ptr[2] = '0' + AGState.speakerGain % 10;

	/* TODO what if this fails */
    if (agSendATmessage(buf, buflen))
        agVolumeChangeInd(AGState.remote_addr, AGState.speakerGain);
    
    free(buf);
}


/*
    agSendVolumeCommand

    Checks if the conditions necessary to send a volume command are met 
    otherwise sends an error
*/
static void agSendVolumeCommand(void)
{
    if (agIsCurrentlyHandsFree())
    {        
        sendVolCmd("\r\n+VGS:??\r\n");
    }
    else
    {
        /* For HS SCO must be up before this can be sent */
        if (agScoConnectedQuery())
            sendVolCmd("\r\n+VGS=??\r\n");
        else
            agSendErrorToClient(AgErrorUnexpectedPrimitive, 0);
    }
    
}


/* 
    agSendVolume

    Send the current volume setting (called when volume request could not
    be sent because the rfcomm credits were insufficient. (non static so 
    it can be called externally
*/
void agSendVolume()
{
    agSendVolumeCommand();
}


/*
    agVolumeChangeInd

    Inform the user of the new volume - this could either be called as
    the result of an incoming vgs command from the headset or the user
    pressing the volume button and generating a vgsReq.
*/
void agVolumeChangeInd(BD_ADDR_T addr, uint16 gain)
{    
    AGState.speakerGain = gain & 0xf;
    
    /* Inform the interface that the volume has changed */
    handleVolumeChangeInd(agGetConnectionHandle(&addr), (uint8) AGState.speakerGain);        
}


/*
    agVolumeChangeReqAction

    Called as a result of a button press.
*/
void agVolumeChangeReqAction(int8 increment, uint8 gain)
{
    switch (increment)
    {
    case 1 :
        if (AGState.speakerGain < 15)
        {            
            AGState.speakerGain++;                    
            agSendVolumeCommand();                    
        }
        break ;
        
    case -1 :
        if (AGState.speakerGain >= 1)
        {            
            AGState.speakerGain--;
            agSendVolumeCommand();                    
        }
        break;
        
    case 0 :
        gain &= 0xf ;
        if (gain != AGState.speakerGain)
        {            
            AGState.speakerGain = gain;
            agSendVolumeCommand();                    
        }
        break ;
        
    default :        
        break ;
    }
}

⌨️ 快捷键说明

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