mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-27 23:37:25 +00:00
hfp: activate/deactivate functions, set microphone and speaker gain
This commit is contained in:
parent
2b5b557b38
commit
400b045254
@ -670,7 +670,7 @@ static hfp_command_t parse_command(const char * line_buffer, int isHandsFree){
|
||||
return HFP_CMD_CALL_PHONE_NUMBER;
|
||||
}
|
||||
|
||||
if (strncmp(line_buffer, HFP_REDIAL_LAST_NUMBER, strlen(HFP_REDIAL_LAST_NUMBER)) == 0){
|
||||
if (strncmp(line_buffer+offset, HFP_REDIAL_LAST_NUMBER, strlen(HFP_REDIAL_LAST_NUMBER)) == 0){
|
||||
return HFP_CMD_REDIAL_LAST_NUMBER;
|
||||
}
|
||||
|
||||
|
@ -124,7 +124,7 @@ extern "C" {
|
||||
#define HFP_HANG_UP_CALL "+CHUP"
|
||||
#define HFP_CHANGE_IN_BAND_RING_TONE_SETTING "+BSIR"
|
||||
#define HFP_CALL_PHONE_NUMBER "ATD"
|
||||
#define HFP_REDIAL_LAST_NUMBER "AT+BLDN"
|
||||
#define HFP_REDIAL_LAST_NUMBER "+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"
|
||||
@ -548,6 +548,13 @@ typedef struct hfp_connection {
|
||||
uint8_t hf_activate_call_waiting_notification;
|
||||
uint8_t hf_deactivate_call_waiting_notification;
|
||||
|
||||
uint8_t hf_activate_calling_line_notification;
|
||||
uint8_t hf_deactivate_calling_line_notification;
|
||||
uint8_t hf_activate_echo_canceling_and_noise_reduction;
|
||||
uint8_t hf_deactivate_echo_canceling_and_noise_reduction;
|
||||
uint8_t hf_activate_voice_recognition_notification;
|
||||
uint8_t hf_deactivate_voice_recognition_notification;
|
||||
|
||||
} hfp_connection_t;
|
||||
|
||||
// UTILS_START : TODO move to utils
|
||||
|
197
src/hfp_hf.c
197
src/hfp_hf.c
@ -238,15 +238,39 @@ static int hfp_hf_cmd_ata(uint16_t cid){
|
||||
return send_str_over_rfcomm(cid, buffer);
|
||||
}
|
||||
|
||||
static int hfp_hf_send_clip_enable(uint16_t cid){
|
||||
char buffer[20];
|
||||
sprintf(buffer, "AT%s=1\r\n", HFP_ENABLE_CLIP);
|
||||
static int hfp_hf_set_microphone_gain_cmd(uint16_t cid, int gain){
|
||||
char buffer[40];
|
||||
sprintf(buffer, "AT%s=%d\r\n", HFP_SET_MICROPHONE_GAIN, gain);
|
||||
return send_str_over_rfcomm(cid, buffer);
|
||||
}
|
||||
|
||||
static int hfp_hf_set_speaker_gain_cmd(uint16_t cid, int gain){
|
||||
char buffer[40];
|
||||
sprintf(buffer, "AT%s=%d\r\n", HFP_SET_SPEAKER_GAIN, gain);
|
||||
return send_str_over_rfcomm(cid, buffer);
|
||||
}
|
||||
|
||||
static int hfp_hf_set_calling_line_notification_cmd(uint16_t cid, uint8_t activate){
|
||||
char buffer[40];
|
||||
sprintf(buffer, "AT%s=%d\r\n", HFP_ENABLE_CLIP, activate);
|
||||
return send_str_over_rfcomm(cid, buffer);
|
||||
}
|
||||
|
||||
static int hfp_hf_set_echo_canceling_and_noise_reduction_cmd(uint16_t cid, uint8_t activate){
|
||||
char buffer[40];
|
||||
sprintf(buffer, "AT%s=%d\r\n", HFP_TURN_OFF_EC_AND_NR, activate);
|
||||
return send_str_over_rfcomm(cid, buffer);
|
||||
}
|
||||
|
||||
static int hfp_hf_set_voice_recognition_notification_cmd(uint16_t cid, uint8_t activate){
|
||||
char buffer[40];
|
||||
sprintf(buffer, "AT%s=%d\r\n", HFP_ACTIVATE_VOICE_RECOGNITION, activate);
|
||||
return send_str_over_rfcomm(cid, buffer);
|
||||
}
|
||||
|
||||
static int hfp_hf_set_call_waiting_notification_cmd(uint16_t cid, uint8_t activate){
|
||||
char buffer[40];
|
||||
sprintf(buffer, "%s=%d\r\n", HFP_ENABLE_CALL_WAITING_NOTIFICATION, activate);
|
||||
sprintf(buffer, "AT%s=%d\r\n", HFP_ENABLE_CALL_WAITING_NOTIFICATION, activate);
|
||||
return send_str_over_rfcomm(cid, buffer);
|
||||
}
|
||||
|
||||
@ -264,7 +288,7 @@ static int hfp_hf_send_memory_dial_cmd(uint16_t cid){
|
||||
|
||||
static int hfp_hf_send_redial_last_number_cmd(uint16_t cid){
|
||||
char buffer[20];
|
||||
sprintf(buffer, "%s\r\n", HFP_REDIAL_LAST_NUMBER);
|
||||
sprintf(buffer, "AT%s\r\n", HFP_REDIAL_LAST_NUMBER);
|
||||
return send_str_over_rfcomm(cid, buffer);
|
||||
}
|
||||
|
||||
@ -500,7 +524,64 @@ static void hfp_run_for_context(hfp_connection_t * context){
|
||||
if (!done){
|
||||
done = call_setup_state_machine(context);
|
||||
}
|
||||
|
||||
if (context->send_microphone_gain){
|
||||
context->send_microphone_gain = 0;
|
||||
context->ok_pending = 1;
|
||||
hfp_hf_set_microphone_gain_cmd(context->rfcomm_cid, context->microphone_gain);
|
||||
return;
|
||||
}
|
||||
|
||||
if (context->send_speaker_gain){
|
||||
context->send_speaker_gain = 0;
|
||||
context->ok_pending = 1;
|
||||
hfp_hf_set_speaker_gain_cmd(context->rfcomm_cid, context->speaker_gain);
|
||||
return;
|
||||
}
|
||||
|
||||
if (context->hf_deactivate_calling_line_notification){
|
||||
context->hf_deactivate_calling_line_notification = 0;
|
||||
context->ok_pending = 1;
|
||||
hfp_hf_set_calling_line_notification_cmd(context->rfcomm_cid, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (context->hf_activate_calling_line_notification){
|
||||
context->hf_activate_calling_line_notification = 0;
|
||||
context->ok_pending = 1;
|
||||
hfp_hf_set_calling_line_notification_cmd(context->rfcomm_cid, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
if (context->hf_deactivate_echo_canceling_and_noise_reduction){
|
||||
context->hf_deactivate_echo_canceling_and_noise_reduction = 0;
|
||||
context->ok_pending = 1;
|
||||
hfp_hf_set_echo_canceling_and_noise_reduction_cmd(context->rfcomm_cid, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (context->hf_activate_echo_canceling_and_noise_reduction){
|
||||
context->hf_activate_echo_canceling_and_noise_reduction = 0;
|
||||
context->ok_pending = 1;
|
||||
hfp_hf_set_echo_canceling_and_noise_reduction_cmd(context->rfcomm_cid, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
if (context->hf_deactivate_voice_recognition_notification){
|
||||
context->hf_deactivate_voice_recognition_notification = 0;
|
||||
context->ok_pending = 1;
|
||||
hfp_hf_set_voice_recognition_notification_cmd(context->rfcomm_cid, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (context->hf_activate_voice_recognition_notification){
|
||||
context->hf_activate_voice_recognition_notification = 0;
|
||||
context->ok_pending = 1;
|
||||
hfp_hf_set_voice_recognition_notification_cmd(context->rfcomm_cid, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (context->hf_deactivate_call_waiting_notification){
|
||||
context->hf_deactivate_call_waiting_notification = 0;
|
||||
context->ok_pending = 1;
|
||||
@ -536,13 +617,6 @@ static void hfp_run_for_context(hfp_connection_t * context){
|
||||
return;
|
||||
}
|
||||
|
||||
if (context->hf_send_clip_enable){
|
||||
context->hf_send_clip_enable = 0;
|
||||
context->ok_pending = 1;
|
||||
hfp_hf_send_clip_enable(context->rfcomm_cid);
|
||||
return;
|
||||
}
|
||||
|
||||
if (context->hf_send_chup){
|
||||
context->hf_send_chup = 0;
|
||||
context->ok_pending = 1;
|
||||
@ -696,6 +770,7 @@ static void hfp_handle_rfcomm_event(uint8_t packet_type, uint16_t channel, uint8
|
||||
context->ok_pending = 0;
|
||||
hfp_reset_context_flags(context);
|
||||
hfp_emit_event(hfp_callback, HFP_SUBEVENT_COMPLETE, 1);
|
||||
context->command = HFP_CMD_NONE;
|
||||
break;
|
||||
case HFP_CMD_OK:
|
||||
hfp_hf_switch_on_ok(context);
|
||||
@ -938,13 +1013,6 @@ void hfp_hf_reject_call(bd_addr_t bd_addr){
|
||||
}
|
||||
}
|
||||
|
||||
void hfp_hf_enable_calling_line_identification(bd_addr_t bd_addr){
|
||||
hfp_hf_establish_service_level_connection(bd_addr);
|
||||
hfp_connection_t * connection = get_hfp_connection_context_for_bd_addr(bd_addr);
|
||||
connection->hf_send_clip_enable = 1;
|
||||
hfp_run_for_context(connection);
|
||||
}
|
||||
|
||||
void hfp_hf_dial_number(bd_addr_t bd_addr, char * number){
|
||||
hfp_hf_establish_service_level_connection(bd_addr);
|
||||
hfp_connection_t * connection = get_hfp_connection_context_for_bd_addr(bd_addr);
|
||||
@ -988,3 +1056,94 @@ void hfp_hf_deactivate_call_waiting_notification(bd_addr_t bd_addr){
|
||||
hfp_run_for_context(connection);
|
||||
}
|
||||
|
||||
|
||||
void hfp_hf_activate_calling_line_notification(bd_addr_t bd_addr){
|
||||
hfp_hf_establish_service_level_connection(bd_addr);
|
||||
hfp_connection_t * connection = get_hfp_connection_context_for_bd_addr(bd_addr);
|
||||
|
||||
connection->hf_deactivate_calling_line_notification = 1;
|
||||
hfp_run_for_context(connection);
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief
|
||||
*/
|
||||
void hfp_hf_deactivate_calling_line_notification(bd_addr_t bd_addr){
|
||||
hfp_hf_establish_service_level_connection(bd_addr);
|
||||
hfp_connection_t * connection = get_hfp_connection_context_for_bd_addr(bd_addr);
|
||||
|
||||
connection->hf_deactivate_calling_line_notification = 1;
|
||||
hfp_run_for_context(connection);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* @brief
|
||||
*/
|
||||
void hfp_hf_activate_echo_canceling_and_noise_reduction(bd_addr_t bd_addr){
|
||||
hfp_hf_establish_service_level_connection(bd_addr);
|
||||
hfp_connection_t * connection = get_hfp_connection_context_for_bd_addr(bd_addr);
|
||||
|
||||
connection->hf_deactivate_echo_canceling_and_noise_reduction = 1;
|
||||
hfp_run_for_context(connection);
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief
|
||||
*/
|
||||
void hfp_hf_deactivate_echo_canceling_and_noise_reduction(bd_addr_t bd_addr){
|
||||
hfp_hf_establish_service_level_connection(bd_addr);
|
||||
hfp_connection_t * connection = get_hfp_connection_context_for_bd_addr(bd_addr);
|
||||
|
||||
connection->hf_deactivate_echo_canceling_and_noise_reduction = 1;
|
||||
hfp_run_for_context(connection);
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief
|
||||
*/
|
||||
void hfp_hf_activate_voice_recognition_notification(bd_addr_t bd_addr){
|
||||
hfp_hf_establish_service_level_connection(bd_addr);
|
||||
hfp_connection_t * connection = get_hfp_connection_context_for_bd_addr(bd_addr);
|
||||
|
||||
connection->hf_deactivate_voice_recognition_notification = 1;
|
||||
hfp_run_for_context(connection);
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief
|
||||
*/
|
||||
void hfp_hf_deactivate_voice_recognition_notification(bd_addr_t bd_addr){
|
||||
hfp_hf_establish_service_level_connection(bd_addr);
|
||||
hfp_connection_t * connection = get_hfp_connection_context_for_bd_addr(bd_addr);
|
||||
|
||||
connection->hf_deactivate_voice_recognition_notification = 1;
|
||||
hfp_run_for_context(connection);
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief
|
||||
*/
|
||||
void hfp_hf_set_microphone_gain(bd_addr_t bd_addr, int gain){
|
||||
hfp_hf_establish_service_level_connection(bd_addr);
|
||||
hfp_connection_t * connection = get_hfp_connection_context_for_bd_addr(bd_addr);
|
||||
if (connection->microphone_gain == gain) return;
|
||||
|
||||
connection->microphone_gain = gain;
|
||||
connection->send_microphone_gain = 1;
|
||||
hfp_run_for_context(connection);
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief
|
||||
*/
|
||||
void hfp_hf_set_speaker_gain(bd_addr_t bd_addr, int gain){
|
||||
hfp_hf_establish_service_level_connection(bd_addr);
|
||||
hfp_connection_t * connection = get_hfp_connection_context_for_bd_addr(bd_addr);
|
||||
if (connection->speaker_gain == gain) return;
|
||||
|
||||
connection->speaker_gain = gain;
|
||||
connection->send_speaker_gain = 1;
|
||||
hfp_run_for_context(connection);
|
||||
}
|
||||
|
||||
|
45
src/hfp_hf.h
45
src/hfp_hf.h
@ -164,11 +164,6 @@ void hfp_hf_reject_call(bd_addr_t bd_addr);
|
||||
*/
|
||||
void hfp_hf_terminate_call(bd_addr_t bd_addr);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*/
|
||||
void hfp_hf_enable_calling_line_identification(bd_addr_t bd_addr);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*/
|
||||
@ -194,6 +189,46 @@ void hfp_hf_activate_call_waiting_notification(bd_addr_t bd_addr);
|
||||
*/
|
||||
void hfp_hf_deactivate_call_waiting_notification(bd_addr_t bd_addr);
|
||||
|
||||
/*
|
||||
* @brief
|
||||
*/
|
||||
void hfp_hf_activate_calling_line_notification(bd_addr_t bd_addr);
|
||||
|
||||
/*
|
||||
* @brief
|
||||
*/
|
||||
void hfp_hf_deactivate_calling_line_notification(bd_addr_t bd_addr);
|
||||
|
||||
|
||||
/*
|
||||
* @brief
|
||||
*/
|
||||
void hfp_hf_activate_echo_canceling_and_noise_reduction(bd_addr_t bd_addr);
|
||||
|
||||
/*
|
||||
* @brief
|
||||
*/
|
||||
void hfp_hf_deactivate_echo_canceling_and_noise_reduction(bd_addr_t bd_addr);
|
||||
|
||||
/*
|
||||
* @brief
|
||||
*/
|
||||
void hfp_hf_activate_voice_recognition_notification(bd_addr_t bd_addr);
|
||||
|
||||
/*
|
||||
* @brief
|
||||
*/
|
||||
void hfp_hf_deactivate_voice_recognition_notification(bd_addr_t bd_addr);
|
||||
|
||||
/*
|
||||
* @brief
|
||||
*/
|
||||
void hfp_hf_set_microphone_gain(bd_addr_t bd_addr, int gain);
|
||||
|
||||
/*
|
||||
* @brief
|
||||
*/
|
||||
void hfp_hf_set_speaker_gain(bd_addr_t bd_addr, int gain);
|
||||
|
||||
/* API_END */
|
||||
|
||||
|
@ -125,6 +125,25 @@ static void show_usage(void){
|
||||
printf("k - deactivate call waiting notification\n");
|
||||
printf("K - activate call waiting notification\n");
|
||||
|
||||
printf("l - deactivate calling line notification\n");
|
||||
printf("L - activate calling line notification\n");
|
||||
|
||||
printf("m - deactivate echo canceling and noise reduction\n");
|
||||
printf("M - activate echo canceling and noise reduction\n");
|
||||
|
||||
printf("n - deactivate voice recognition notification\n");
|
||||
printf("N - activate voice recognition notification\n");
|
||||
|
||||
printf("o - Set speaker volume to 0 (minimum)\n");
|
||||
printf("O - Set speaker volume to 9 (default)\n");
|
||||
printf("p - Set speaker volume to 12 (higher)\n");
|
||||
printf("P - Set speaker volume to 15 (maximum)\n");
|
||||
|
||||
printf("q - Set microphone gain to 0 (minimum)\n");
|
||||
printf("Q - Set microphone gain to 9 (default)\n");
|
||||
printf("s - Set microphone gain to 12 (higher)\n");
|
||||
printf("S - Set microphone gain to 15 (maximum)\n");
|
||||
|
||||
printf("t - terminate connection\n");
|
||||
|
||||
printf("---\n");
|
||||
@ -226,6 +245,54 @@ static int stdin_process(struct data_source *ds){
|
||||
printf("Activate call waiting notification\n");
|
||||
hfp_hf_activate_call_waiting_notification(device_addr);
|
||||
break;
|
||||
case 'l':
|
||||
printf("Deactivate calling line notification\n");
|
||||
hfp_hf_deactivate_calling_line_notification(device_addr);
|
||||
break;
|
||||
case 'L':
|
||||
printf("Activate calling line notification\n");
|
||||
hfp_hf_activate_calling_line_notification(device_addr);
|
||||
break;
|
||||
case 'm':
|
||||
printf("Deactivate echo canceling and noise reduction\n");
|
||||
hfp_hf_deactivate_echo_canceling_and_noise_reduction(device_addr);
|
||||
break;
|
||||
case 'M':
|
||||
printf("Activate echo canceling and noise reduction\n");
|
||||
hfp_hf_activate_echo_canceling_and_noise_reduction(device_addr);
|
||||
break;
|
||||
case 'n':
|
||||
printf("Deactivate voice recognition notification\n");
|
||||
hfp_hf_deactivate_voice_recognition_notification(device_addr);
|
||||
break;
|
||||
case 'N':
|
||||
printf("Activate voice recognition notification\n");
|
||||
hfp_hf_activate_voice_recognition_notification(device_addr);
|
||||
break;
|
||||
case 'o':
|
||||
printf("Set speaker gain to 0 (minimum)\n");
|
||||
hfp_hf_set_speaker_gain(device_addr, 0);
|
||||
break;
|
||||
case 'O':
|
||||
printf("Set speaker gain to 9 (default)\n");
|
||||
hfp_hf_set_speaker_gain(device_addr, 9);
|
||||
break;
|
||||
case 'p':
|
||||
printf("Set speaker gain to 12 (higher)\n");
|
||||
hfp_hf_set_speaker_gain(device_addr, 12);
|
||||
break;
|
||||
case 'P':
|
||||
printf("Set speaker gain to 15 (maximum)\n");
|
||||
hfp_hf_set_speaker_gain(device_addr, 15);
|
||||
break;
|
||||
case 'q':
|
||||
printf("Set microphone gain to 0\n");
|
||||
hfp_hf_set_microphone_gain(device_addr, 0);
|
||||
break;
|
||||
case 'Q':
|
||||
printf("Set microphone gain to 9\n");
|
||||
hfp_hf_set_microphone_gain(device_addr, 9);
|
||||
break;
|
||||
default:
|
||||
show_usage();
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user