extern struct audio_adc_hdl adc_hdl;
extern u8 bt_connect;
-static uint8_t BT_state = 0;
-static uint8_t local_audio_state = 0;
+uint8_t BT_state = 0;
+uint8_t local_audio_state = 0;
//采样率
#define ALINK_DEMO_SAMPLE_RATE 16000
void open_bt_audio(void)//打开蓝牙通话
{
+ BT_state = 1;
__set_bt_esco_by_watch(1);
user_emitter_cmd_prepare(USER_CTRL_CONN_SCO,0,NULL);
user_emitter_cmd_prepare(USER_CTRL_HFP_CALL_LAST_NO,0,NULL);
// {}
}
}
+//清楚蓝牙耳机连接记录
+void clear_earphone_record(void){
+ if(bt_connect){
+ user_emitter_cmd_prepare(USER_CTRL_DISCONNECTION_HCI, 0, NULL);
+ }
+ emitter_delete_remote_all();
+ uart_send_clear_earphoneok();
+
+}
+int uart_send_clear_earphoneok(void)
+{
+ //{"event":"AI_PWR_PRESS"}
+ cJSON *root = cJSON_CreateObject();
+ if (root == NULL) {
+ printf( "Failed to create JSON object\n");
+ return -1;
+ }
+ // 添加字符串字段 "event"
+ cJSON_AddStringToObject(root, "event", "clear_earphone_record_ok");
+ // 将JSON对象转换为字符串
+ char *json_string = cJSON_Print(root);
+ if (json_string == NULL) {
+ printf( "Failed to print JSON\n");
+ cJSON_Delete(root);
+ return -1;
+ }
+ read_ack_flag=0;
+ printf("JSON数据: %s\n", json_string);
+ bk_uart_send_smg(BK_UART_WRITE_DATA,json_string,strlen(json_string));
+ cJSON_free(json_string);
+ cJSON_Delete(root);
+ int count = 50;
+ while(count--)
+ {
+ if(read_ack_flag == 1)
+ {
+ break;
+ }
+ os_time_dly(1);
+ }
+ return 0;
+}
////*************解析****************//////
extern u8 is_bredr_close(void);
extern void bt_init_bredr();
printf("获取当前版本");
uart_send_versions();
}
+ if(!strcmp(event->valuestring,"clear_earphone_record")) {
+ printf("清楚所有的蓝牙耳机连接记录");
+
+ clear_earphone_record();
+ }
if(error_flag == 0 && ack_flag == 1)
{
ack_flag = 0;
int uart_send_bt_state(u8 bt_state);
int uart_send_kws(void);
void auto_switch_local_mic(void);
+void clear_earphone_record(void);
+int uart_send_clear_earphoneok(void);
+
#endif
}
return ret;
}
+extern u8 esco_flag;
+extern u8 BT_state;
u16 AI_VC_1S_id = 0;
u16 AI_VC_sleep_count = 0;
void AI_VC_1S_cb(void *p)
}
void AI_VC_1S_event(void)
{
-
int cat1_io = gpio_read(IO_PORTA_10) ;
- printf("AI_VC_1S_cb:%d",cat1_io);
+ printf("AI_VC_1S_cb:%d %d %d",cat1_io,BT_state,esco_flag);
+ if(BT_state)
+ {
+ if(esco_flag ==0 ){
+ bk_app_send_smg(OPEN_CALL,NULL,0);//会关闭定时器 open_bt_audio(0)
+ }
+
+ }
+
+
#if(USR_KWS_ALG != 0)
if(cat1_io == 0 && AI_start_flag == 1)//cat1退出唤醒,进入休眠
{
gpio_write(IO_PORTB_03,0);
bk_app_send_smg(AI_CLOSE,NULL,0);//会关闭定时器
}
+ if(cat1_io == 1 && AI_start_flag == 0)
+ {
+ bk_app_send_smg(AI_OPEN,NULL,0);//会关闭定时器
+ }
#endif
}
+extern uint8_t BT_state;
+extern uint8_t local_audio_state;
+void disconnect_error(void)
+{
+ if(AI_start_flag != 0)
+ {
+ AI_start_flag = 0;
+ BT_state=0;
+ local_audio_state=1;
+ }
+}
//vc开始
void AI_VC_start(void)
{
AI_start_flag = 0;
}
}
+int get_ai_start(void)
+{
+ int cat1_io = gpio_read(IO_PORTA_10) ;
+ if(cat1_io == 1 && AI_start_flag == 1)
+ return 1;
+ else
+ return 0;
+}
void bk_app_send_smg(bk_app_msg_event event,char *data,int data_len)
{
char *data_tmp =NULL;
case BT_State_Change_CB:
BT_State_Change_cb();
break;
+ case BT_DISCONNEECT_EVENT:
+ key_bt_hangup_CB();
+ break;
default:
break;
}
os_taskq_post_msg("bk_ALG_task", 3, event,(int)data_tmp, data_len);
}
-extern u8 esco_flag;
+
+//蓝牙耳机切换事件回调
void BT_State_Change_cb(void)
{
os_time_dly(100);
- if(esco_flag){
+ if(esco_flag == 1){
bk_app_send_smg(CLOSE_BT_AUDIO_EVENT,NULL,0);
}
bk_app_send_smg(AI_CLOSE,NULL,0);
bk_app_send_smg(AI_OPEN,NULL,0);
+ // bk_app_send_smg(AI_KEY_PRESS,NULL,0);
+}
+extern u8 bt_connect;
+//蓝牙耳机主动断开当前通话
+void key_bt_hangup(void){
+ bk_app_send_smg(BT_DISCONNEECT_EVENT,NULL,0);
+}
+void key_bt_hangup_CB(void){
+ os_time_dly(30);
+ printf("esco_flag end:%d %d",esco_flag,bt_connect);
+ if(bt_connect ==0) //蓝牙耳机已断开
+ return;
+ bk_app_send_smg(AI_KEY_PRESS,NULL,0);
+}
+//蓝牙耳机所有按键触发AI对话
+void all_key_bt_ai(void) //蓝牙耳机已连接不在通话中
+{
+ printf("all_key_bt_ai end:%d %d",esco_flag,AI_start_flag);
+ if(esco_flag){
+ return;
+ }
+ bk_app_send_smg(AI_KEY_PRESS,NULL,0);
}
//#include "rtc.h"
//void read_sys_time(struct sys_time *curr_time);
AI_VC_1S_EVENT,
CLOSE_BT_AUDIO_EVENT,
BT_State_Change_CB,//蓝牙连接状态切换
- OPEN_CALL
+ OPEN_CALL,
+ BT_DISCONNEECT_EVENT,
}bk_app_msg_event;
typedef enum
int bk_key_switch(int key_event,int key_value);
char get_ai_state(void);
void BT_State_Change_cb(void);
+void disconnect_error(void);
+int get_ai_start(void);
+void key_bt_hangup(void);
+void key_bt_hangup_CB(void);
+void all_key_bt_ai(void);
#endif
\ No newline at end of file
#define TCFG_USER_ESCO_SLAVE_MUTE 1 //对箱通话slave出声音
#else
#if TCFG_USER_EMITTER_ENABLE //emitter功能使能
-#define TCFG_BD_NUM 2 //连接设备个数配置
+#define TCFG_BD_NUM 1 //连接设备个数配置
#else
#define TCFG_BD_NUM 1 //连接设备个数配置
#endif
#include "message_vm_cfg.h"
#include "watch_common.h"
-
+#include "bk_app.h"
#if TCFG_UI_ENABLE_MOTO
#include "ui/ui_sys_param.h"
#endif /* #if TCFG_UI_ENABLE_MOTO */
#endif /* #if TCFG_UI_ENABLE_PHONEBOOK */
break;
case BT_STATUS_PHONE_ACTIVE:
- log_info("BT_STATUS_PHONE_ACTIVE\n");
+ log_info("BT_STATUS_PHONE_ACTIVE:%d\n",__this->smartbox_watch_upgrade_flag);
//当手机app与手表传输过程中不能响应通话事件
if (__this->smartbox_watch_upgrade_flag) {
break;
UI_MSG_POST("phone_active:status=%4", 1);
break;
case BT_STATUS_PHONE_HANGUP:
+ printf("AI对话不需要耳机按键关闭");
+ printf("BT_STATUS_PHONE_HANGUP:%d",is_key_hangup);
+ // if(!is_key_hangup) //按耳机键不能挂断当前对话
+ // {
+
+ // break;
+ // }
+
log_info(" BT_STATUS_PHONE_HANGUP\n");
//当手机app与手表传输过程中不能响应通话事件
if (__this->smartbox_watch_upgrade_flag) {
bt_status_a2dp_media_stop(bt);
break;
case BT_STATUS_SCO_STATUS_CHANGE:
+
+
log_info(" BT_STATUS_SCO_STATUS_CHANGE");
log_info(" ui_moto_run 0");
#if TCFG_UI_ENABLE_MOTO
{
esco_flag = 0;
}
+ if( bt->value == 0xff){
+ if(get_ai_start() == 1)//不是设备主动关闭
+ {
+ key_bt_hangup();
+ // break;
+ }
+ }
break;
case BT_STATUS_CALL_VOL_CHANGE:
log_info(" BT_STATUS_CALL_VOL_CHANGE ");
#include "ui/ui_style.h"
#include "media/file_decoder.h"
#include "ble_protocol.h"
+#include "bk_app.h"
#define AUTO_POWER_ON_SCANE_ENABLE 0
#if TCFG_APP_BT_EN
//"Fineblue Clip"
//"X7"
//"JBL GO",
- "Deep Gen2 Max",
+ //"Deep Gen2 Max",
};
#endif
蓝牙库里面定义的是weak函数,直接再定义一个同名可获取信息
*/
/*----------------------------------------------------------------------------*/
+
void emitter_rx_avctp_opid_deal(u8 cmd, u8 id)
{
log_debug("avctp_rx_cmd:%x\n", cmd);
printf(" curr is upate, can not opt \n");
return;
}
-
+ all_key_bt_ai();
switch (cmd) {
case AVCTP_OPID_NEXT:
log_info("AVCTP_OPID_NEXT\n");
void emitter_rx_vol_change(u8 vol)
{
log_info("vol_change:%d \n", vol);
+ all_key_bt_ai();
}
typedef struct _EMITTER_INFO {
u16 id = CFG_REMOTE_DN_00;
while (1) {
syscfg_read(id, &remote_n, sizeof(struct remote_name));
+ printf("remote_n:%02x %02x %02x %02x %02x %02x",remote_n.addr[0],remote_n.addr[1],remote_n.addr[2],remote_n.addr[3],remote_n.addr[4],remote_n.addr[5]);
if (remote_n.crc == CRC16((u8 *)&remote_n.addr, sizeof(struct remote_name) - 2)) {
memset(&remote_n, 0xff, sizeof(struct remote_name));
syscfg_write(id, &remote_n, sizeof(struct remote_name));
void emitter_get_vm_device()
{
memset(remote_addr, 0, sizeof(remote_addr));
- u8 flag = restore_remote_device_info_opt(&remote_addr, 20, get_remote_dev_info_index());
+ u8 flag = restore_remote_device_info_opt(&remote_addr, 1, get_remote_dev_info_index());
for (u8 i = 0; i < 20; i++) {
- log_debug("----- \n");
+ log_debug("emitter_get_vm_device ----- \n");
log_debug_hexdump(remote_addr[i], 6);
}
}