?? ag_volume.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 + -