#if 1
u8 TWS_CONN_STATUS=0;
enum
{
BT_NOCONN_PHONE_AND_TWS=0, ///当前音箱既没有连接手机也没有连接上 TWS
BT_CURRENT_CONN_PHONE=1, //当前只有手机连接上
BT_CURRENT_CONN_STEREO_MASTER, //当前主机连接从成功,没有手机连接
BT_CURRENT_CONN_STEREO_SALVE,//从机与主机连接成功
BT_CURRENT_CONN_STEREO_MASTER_PHONE,//当前连接的是手机,并且对箱从已经连接上
BT_CURRENT_CONN_STEREO_PHONE_MASTER,//当前主机连接从成功,同时手机已连接
};
extern u8 get_bt_current_conn_type();
u8 get_bt_current_conn_type()
{
u8 tws_role;
tws_role = get_tws_device_role();
if(tws_role == TWS_ROLE_MASTER) ///是主机
{
switch(TWS_CONN_STATUS)
{
case 0x04:
log_printf(“master 0x04,BT_CURRENT_CONN_STEREO_SALVE\n”);
return BT_CURRENT_CONN_STEREO_SALVE;
case 0x08: ///主从机连接上,没有连接手机
log_printf(“master 0x08,BT_CURRENT_CONN_STEREO_MASTER\n”);
return BT_CURRENT_CONN_STEREO_MASTER;
case 0x0a:
log_printf(“master 0x0a,BT_CURRENT_CONN_STEREO_PHONE_MASTER\n”);
return BT_CURRENT_CONN_STEREO_PHONE_MASTER;
default:
return BT_CURRENT_CONN_PHONE;
}
}
else if(tws_role == TWS_ROLE_SLAVE) ///是从机
{
switch(TWS_CONN_STATUS)
{
case 0x04:
log_printf(“slave 0x04,BT_CURRENT_CONN_STEREO_SALVE\n”);
return BT_CURRENT_CONN_STEREO_SALVE;
default:
return BT_CURRENT_CONN_PHONE;
}
}
else
{
// 如果 TWS 没有连接,直接返回
//主机有些按键消息,从机不需要同步实现
switch(TWS_CONN_STATUS)
{
case 0x02:
log_printf(“master 0x02,BT_CURRENT_CONN_PHONE\n”);
return BT_CURRENT_CONN_PHONE; ///仅连接上手机
default:
return BT_NOCONN_PHONE_AND_TWS;
}
}
return BT_NOCONN_PHONE_AND_TWS;
}
void stereo_led_deal()
{
u8 get_bt_status=0;
get_bt_status = get_bt_current_conn_type();
switch(get_bt_status)
{
case BT_NOCONN_PHONE_AND_TWS:
log_printf(“BT_NOCONN_PHONE_AND_TWS\n”);
break;
case BT_CURRENT_CONN_PHONE:
log_printf(“BT_CURRENT_CONN_PHONE\n”);
break;
case BT_CURRENT_CONN_STEREO_MASTER:
log_printf(“BT_CURRENT_CONN_STEREO_MASTER\n”);
break;
case BT_CURRENT_CONN_STEREO_SALVE:
log_printf(“BT_CURRENT_CONN_STEREO_SALVE\n”);
break;
case BT_CURRENT_CONN_STEREO_MASTER_PHONE:
log_printf(“BT_CURRENT_CONN_STEREO_MASTER_PHONE\n”);
break;
case BT_CURRENT_CONN_STEREO_PHONE_MASTER:
log_printf(“BT_CURRENT_CONN_STEREO_PHONE_MASTER\n”);
break;
default:
log_printf(“BT_NOCONN_PHONE_AND_TWS\n”);
break;
}
}
#endif
在Task_bt.c这里如下截图对应加入TWS_CONN_ATATUS变量赋值,同时定义变量 u8 TWS_CONN_STATUS。
在 Bt_tws.c 加入上面的代码
杰里之获取对箱配对前后的状态篇
最新推荐文章于 2024-06-13 08:48:51 发布