耳机本地播放说明
📎 原始文档:https://www.kdocs.cn/l/cpvj3e36bBSX 耳机本地播放说明
1、彩屏仓耳机本地播放协议
增加两条指令

同步仓的经典蓝牙地址给耳机、耳机同步给对耳
void sys_smartstore_event_deal(struct sys_event *event)
{
u8 *data = event->u.smartstore.args;
u8 len = event->u.smartstore.data_len;
log_info("sys_smartstore_event_handle");
...
case CUSTOM_EDR_CONTRAL_CONN:
log_info("CUSTOM_EDR_CONTRAL_CONN\n");
custom_ctrle_edr_conn(data[0]);
break;
case CUSTOM_EDR_SYNC_INFO://仓的地址
log_info("CUSTOM_EDR_CONTRAL_CONN\n");
custom_ctrle_emitter_info(data,len);
break;
....
}
耳机接收到仓的地址、同步给副耳同时清除配对信息
static void custom_ctrle_emitter_info(u8 *data, u16 len)
{
log_info("%s[line:%d, len:%d]\n",__func__,__LINE__, len);
memcpy(&emitter_info, data, len);
// put_buf(emitter_info.emitter_addr, 6);
sync_emitter_addr();
sync_clear_last_info();
clear_last_info();
}
//相关函数
static void remote_emitter_addr(u8 *data, u16 len)
u8* get_remote_emitter_addr(void)
对耳连接后同步仓的地址
相关函数
//发命令同步仓的地址
void sync_emitter_addr(void)
//副耳接收到同步地址的回调函数
static void earphone_sync_sbox_setting_receive(void *_data, u16 len, bool rx)
{
...
case SYNC_CMD_EMITTER_ADDR:
remote_emitter_addr(&data[1], len-1);
break;
...
}
- 仓发命令连接耳机还是回连手机
void sys_smartstore_event_deal(struct sys_event *event)
{
u8 *data = event->u.smartstore.args;
u8 len = event->u.smartstore.data_len;
log_info("sys_smartstore_event_handle");
...
case CUSTOM_EDR_CONTRAL_CONN: //控制耳机连接仓还是手机
log_info("CUSTOM_EDR_CONTRAL_CONN\n");
custom_ctrle_edr_conn(data[0]);
break;
case CUSTOM_EDR_SYNC_INFO:
log_info("CUSTOM_EDR_CONTRAL_CONN\n");
custom_ctrle_emitter_info(data,len);
break;
....
}
void custom_ctrle_edr_conn(u8 cmd)
{
u8 phone_mac[6];
u8 mac_addr[6];
u8 flag = 0;
g_printf("%s[line:%d, cmd:%d]\n",__func__,__LINE__, cmd);
switch (cmd)
{
case 1: /* 如果连接手机先断开手机。然后处于可发现可连接状态 */
delete_link_key(get_remote_emitter_addr(), 1);
if ((BT_STATUS_CONNECTING == get_bt_connect_status()) ||
(BT_STATUS_TAKEING_PHONE == get_bt_connect_status()) ||
(BT_STATUS_PLAYING_MUSIC == get_bt_connect_status())) {
user_send_cmd_prepare(USER_CTRL_DISCONNECTION_HCI, 0, NULL);
get_current_poweron_memory_search_index(phone_mac);
put_buf(phone_mac, 6);
}else {
bt_wait_phone_connect_control(1);
}
break;
case 2: /*发射器断开耳机、同时耳机清除仓的配对记录、如果之前连接过手机回连手机 */
clear_last_info();
// conn_emitter_addr[5] = ~conn_emitter_addr[5];
sync_clear_last_info();
flag = restore_remote_device_info_opt(mac_addr, 1, get_remote_dev_info_index());
if(flag){
printf("%s[line:%d] connected last mac\n",__func__,__LINE__);
put_buf(mac_addr,6);
memcpy(bt_user_priv_var.auto_connection_addr, mac_addr, 6);
sys_timeout_add(NULL, sw_connect_last_device_from_vm, 1000);
}
// sys_timeout_add(NULL, sw_connect_last_device_from_vm, 8000);
// conn_earphone_count = SWITCH_CONN_EARPHINE_COUNT;
default:
break;
}
}
//相关函数
//清除本地与仓的配对信息
void clear_last_info(void)
//通知副耳清除与仓的配对信息
void sync_clear_last_info(void)