hfp: set microphone/spaeker gain

This commit is contained in:
Milanka Ringwald 2015-11-23 16:52:55 +01:00
parent 24cb5699a0
commit 0afbc6c63d
4 changed files with 94 additions and 3 deletions

View File

@ -620,13 +620,30 @@ void hfp_handle_hci_event(hfp_callback_t callback, uint8_t packet_type, uint8_t
// translates command string into hfp_command_t CMD
static hfp_command_t parse_command(const char * line_buffer, int isHandsFree){
int offset = isHandsFree ? 0 : 2;
if (strncmp(line_buffer+offset, HFP_REQUEST_PHONE_NUMBER, strlen(HFP_REQUEST_PHONE_NUMBER))){
if (isHandsFree) return HFP_CMD_AG_SEND_PHONE_NUMBER;
return HFP_CMD_HF_REQUEST_PHONE_NUMBER;
}
if (strncmp(line_buffer+offset, HFP_TRANSMIT_DTMF_CODES, strlen(HFP_TRANSMIT_DTMF_CODES))){
return HFP_CMD_TRANSMIT_DTMF_CODES;
}
if (strncmp(line_buffer+offset, HFP_SET_MICROPHONE_GAIN, strlen(HFP_SET_MICROPHONE_GAIN))){
return HFP_CMD_SET_MICROPHONE_GAIN;
}
if (strncmp(line_buffer+offset, HFP_SET_SPEAKER_GAIN, strlen(HFP_SET_SPEAKER_GAIN))){
return HFP_CMD_SET_SPEAKER_GAIN;
}
if (strncmp(line_buffer, HFP_ACTIVATE_VOICE_RECOGNITION, strlen(HFP_ACTIVATE_VOICE_RECOGNITION))){
if (strncmp(line_buffer+offset, HFP_ACTIVATE_VOICE_RECOGNITION, strlen(HFP_ACTIVATE_VOICE_RECOGNITION))){
if (isHandsFree) return HFP_CMD_AG_ACTIVATE_VOICE_RECOGNITION;
return HFP_CMD_HF_ACTIVATE_VOICE_RECOGNITION;
}
if (strncmp(line_buffer, HFP_TURN_OFF_EC_AND_NR, strlen(HFP_TURN_OFF_EC_AND_NR))){
if (strncmp(line_buffer+offset, HFP_TURN_OFF_EC_AND_NR, strlen(HFP_TURN_OFF_EC_AND_NR))){
return HFP_CMD_TURN_OFF_EC_AND_NR;
}
@ -921,6 +938,16 @@ void hfp_parse(hfp_connection_t * context, uint8_t byte, int isHandsFree){
case HFP_PARSER_CMD_SEQUENCE: // parse comma separated sequence, ignore breacktes
switch (context->command){
case HFP_CMD_SET_MICROPHONE_GAIN:
value = atoi((char *)&context->line_buffer[0]);
context->microphone_gain = value;
log_info("hfp parse HFP_CMD_SET_MICROPHONE_GAIN %d\n", value);
break;
case HFP_CMD_SET_SPEAKER_GAIN:
value = atoi((char *)&context->line_buffer[0]);
context->speaker_gain = value;
log_info("hfp parse HFP_CMD_SET_SPEAKER_GAIN %d\n", value);
break;
case HFP_CMD_HF_ACTIVATE_VOICE_RECOGNITION:
value = atoi((char *)&context->line_buffer[0]);
context->ag_activate_voice_recognition = value;

View File

@ -125,6 +125,11 @@ extern "C" {
#define HFP_REDIAL_LAST_NUMBER "AT+BLDN"
#define HFP_TURN_OFF_EC_AND_NR "+NREC" // EC (Echo CAnceling), NR (Noise Reduction)
#define HFP_ACTIVATE_VOICE_RECOGNITION "+BVRA" // EC (Echo CAnceling), NR (Noise Reduction)
#define HFP_SET_MICROPHONE_GAIN "+VGM"
#define HFP_SET_SPEAKER_GAIN "+VGS"
#define HFP_REQUEST_PHONE_NUMBER "+BINP"
#define HFP_TRANSMIT_DTMF_CODES "+VTS"
#define HFP_OK "OK"
@ -176,7 +181,13 @@ typedef enum {
HFP_CMD_TURN_OFF_EC_AND_NR,
HFP_CMD_AG_ACTIVATE_VOICE_RECOGNITION,
HFP_CMD_HF_ACTIVATE_VOICE_RECOGNITION,
HFP_CMD_HF_REQUEST_PHONE_NUMBER,
HFP_CMD_AG_SEND_PHONE_NUMBER,
HFP_CMD_TRANSMIT_DTMF_CODES,
HFP_CMD_SET_MICROPHONE_GAIN,
HFP_CMD_SET_SPEAKER_GAIN
} hfp_command_t;
typedef enum {
HFP_CME_ERROR_AG_FAILURE = 0,
@ -445,6 +456,9 @@ typedef struct hfp_connection {
uint8_t ag_echo_and_noise_reduction;
uint8_t ag_activate_voice_recognition;
uint8_t microphone_gain;
uint8_t speaker_gain;
timer_source_t hfp_timeout;
} hfp_connection_t;

View File

@ -403,6 +403,19 @@ static int hfp_ag_activate_voice_recognition_cmd(uint16_t cid, uint8_t activate_
return send_str_over_rfcomm(cid, buffer);
}
static int hfp_ag_set_speaker_gain_cmd(uint16_t cid, uint8_t gain){
char buffer[30];
sprintf(buffer, "\r\n%s:%d\r\n", HFP_SET_SPEAKER_GAIN, gain);
return send_str_over_rfcomm(cid, buffer);
}
static int hfp_ag_set_microphone_gain_cmd(uint16_t cid, uint8_t gain){
char buffer[30];
sprintf(buffer, "\r\n%s:%d\r\n", HFP_SET_MICROPHONE_GAIN, gain);
return send_str_over_rfcomm(cid, buffer);
}
static uint8_t hfp_ag_suggest_codec(hfp_connection_t *context){
int i,j;
uint8_t codec = HFP_CODEC_CVSD;
@ -593,6 +606,12 @@ static int hfp_ag_run_for_context_service_level_connection_queries(hfp_connectio
// printf(" -> State machine: SLC Queries\n");
switch(context->command){
case HFP_CMD_SET_SPEAKER_GAIN:
hfp_ag_set_speaker_gain_cmd(context->rfcomm_cid, context->ag_activate_voice_recognition);
return 1;
case HFP_CMD_SET_MICROPHONE_GAIN:
hfp_ag_set_microphone_gain_cmd(context->rfcomm_cid, context->ag_activate_voice_recognition);
return 1;
case HFP_CMD_AG_ACTIVATE_VOICE_RECOGNITION:
hfp_supported_features = store_bit(hfp_supported_features, HFP_AGSF_VOICE_RECOGNITION_FUNCTION, context->ag_activate_voice_recognition);
hfp_ag_activate_voice_recognition_cmd(context->rfcomm_cid, context->ag_activate_voice_recognition);
@ -1648,10 +1667,31 @@ void hfp_ag_activate_voice_recognition(bd_addr_t bd_addr, int activate){
hfp_connection_t * connection = get_hfp_connection_context_for_bd_addr(bd_addr);
if (connection->ag_activate_voice_recognition == activate) return;
connection->ag_activate_voice_recognition = activate;
connection->command = HFP_CMD_AG_ACTIVATE_VOICE_RECOGNITION;
hfp_run_for_context(connection);
}
/*
* @brief
*/
void hfp_ag_set_microphone_gain(bd_addr_t bd_addr, int gain){
hfp_connection_t * connection = get_hfp_connection_context_for_bd_addr(bd_addr);
if (connection->microphone_gain != gain){
connection->command = HFP_CMD_SET_MICROPHONE_GAIN;
connection->microphone_gain = gain;
}
}
/*
* @brief
*/
void hfp_ag_set_speaker_gain(bd_addr_t bd_addr, int gain){
hfp_connection_t * connection = get_hfp_connection_context_for_bd_addr(bd_addr);
if (connection->speaker_gain != gain){
connection->command = HFP_CMD_SET_SPEAKER_GAIN;
connection->speaker_gain = gain;
}
}

View File

@ -241,6 +241,16 @@ void hfp_ag_set_battery_level(int level);
*/
void hfp_ag_activate_voice_recognition(bd_addr_t bd_addr, int activate);
/*
* @brief
*/
void hfp_ag_set_microphone_gain(bd_addr_t bd_addr, int gain);
/*
* @brief
*/
void hfp_ag_set_speaker_gain(bd_addr_t bd_addr, int gain);
/* API_END */
#if defined __cplusplus