hfp_hf: avoid sending voice activation multiple times

This commit is contained in:
Matthias Ringwald 2024-02-01 20:04:14 +01:00
parent 8cb805e6fa
commit cd7fdf75ad

View File

@ -553,7 +553,6 @@ static int hfp_hf_voice_recognition_state_machine(hfp_connection_t * hfp_connect
if (hfp_connection->state < HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED) { if (hfp_connection->state < HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED) {
return 0; return 0;
} }
int done = 0;
if (hfp_connection->ok_pending == 1){ if (hfp_connection->ok_pending == 1){
return 0; return 0;
@ -600,34 +599,24 @@ static int hfp_hf_voice_recognition_state_machine(hfp_connection_t * hfp_connect
hfp_connection->command = HFP_CMD_NONE; hfp_connection->command = HFP_CMD_NONE;
} }
switch (hfp_connection->vra_state_requested){ switch (hfp_connection->vra_state_requested){
case HFP_VRA_W2_SEND_VOICE_RECOGNITION_OFF: case HFP_VRA_W2_SEND_VOICE_RECOGNITION_OFF:
done = hfp_hf_set_voice_recognition_notification_cmd(hfp_connection->rfcomm_cid, 0); hfp_connection->vra_state_requested = HFP_VRA_W4_VOICE_RECOGNITION_OFF;
if (done != 0){ hfp_connection->ok_pending = 1;
hfp_connection->vra_state_requested = HFP_VRA_W4_VOICE_RECOGNITION_OFF; hfp_hf_set_voice_recognition_notification_cmd(hfp_connection->rfcomm_cid, 0);
hfp_connection->ok_pending = 1;
}
return 1; return 1;
case HFP_VRA_W2_SEND_VOICE_RECOGNITION_ACTIVATED: case HFP_VRA_W2_SEND_VOICE_RECOGNITION_ACTIVATED:
done = hfp_hf_set_voice_recognition_notification_cmd(hfp_connection->rfcomm_cid, 1); hfp_connection->vra_state_requested = HFP_VRA_W4_VOICE_RECOGNITION_ACTIVATED;
if (done != 0){ hfp_connection->ok_pending = 1;
hfp_connection->vra_state_requested = HFP_VRA_W4_VOICE_RECOGNITION_ACTIVATED; hfp_hf_set_voice_recognition_notification_cmd(hfp_connection->rfcomm_cid, 1);
hfp_connection->ok_pending = 1; return 1;
return 1;
}
break;
case HFP_VRA_W2_SEND_ENHANCED_VOICE_RECOGNITION_READY_FOR_AUDIO: case HFP_VRA_W2_SEND_ENHANCED_VOICE_RECOGNITION_READY_FOR_AUDIO:
done = hfp_hf_set_voice_recognition_notification_cmd(hfp_connection->rfcomm_cid, 2); hfp_connection->vra_state_requested = HFP_VRA_W4_ENHANCED_VOICE_RECOGNITION_READY_FOR_AUDIO;
if (done != 0){ hfp_connection->ok_pending = 1;
hfp_connection->vra_state_requested = HFP_VRA_W4_ENHANCED_VOICE_RECOGNITION_READY_FOR_AUDIO; hfp_hf_set_voice_recognition_notification_cmd(hfp_connection->rfcomm_cid, 2);
hfp_connection->ok_pending = 1; return 1;
return 1;
}
break;
case HFP_VRA_W4_VOICE_RECOGNITION_OFF: case HFP_VRA_W4_VOICE_RECOGNITION_OFF:
hfp_connection->vra_state = HFP_VRA_VOICE_RECOGNITION_OFF; hfp_connection->vra_state = HFP_VRA_VOICE_RECOGNITION_OFF;
@ -673,7 +662,7 @@ static int hfp_hf_voice_recognition_state_machine(hfp_connection_t * hfp_connect
default: default:
break; break;
} }
return done; return 0;
} }
@ -742,8 +731,8 @@ static int call_setup_state_machine(hfp_connection_t * hfp_connection){
if (hfp_connection->ok_pending) return 0; if (hfp_connection->ok_pending) return 0;
if (hfp_connection->hf_answer_incoming_call){ if (hfp_connection->hf_answer_incoming_call){
hfp_hf_cmd_ata(hfp_connection->rfcomm_cid);
hfp_connection->hf_answer_incoming_call = 0; hfp_connection->hf_answer_incoming_call = 0;
hfp_hf_cmd_ata(hfp_connection->rfcomm_cid);
return 1; return 1;
} }
return 0; return 0;
@ -854,6 +843,9 @@ static void hfp_hf_run_for_context(hfp_connection_t * hfp_connection){
rfcomm_request_can_send_now_event(hfp_connection->rfcomm_cid); rfcomm_request_can_send_now_event(hfp_connection->rfcomm_cid);
return; return;
} }
// we can send at least an RFCOMM packet or a HCI Command now
int done = hfp_hf_run_for_context_service_level_connection(hfp_connection); int done = hfp_hf_run_for_context_service_level_connection(hfp_connection);
if (!done){ if (!done){
done = hfp_hf_run_for_context_service_level_connection_queries(hfp_connection); done = hfp_hf_run_for_context_service_level_connection_queries(hfp_connection);