#if IS_LCD_DISPLAY

#ifdef TASK_SUB

u8 *bt_tmp = (u8 *)filename;    // 注意：用filename是为了节省ram

#pragma constseg = BT_MENU_DISP_PARAM
string IAR_CONST tbl_bt_menu_const[] = {
    STR_MAIN_BT,
    STR_BT_RECONNECT,
    //STR_BT_LIST_CONNECTED,
    STR_MENU_EQ,
    STR_BT_DEL_PAIRED,
    STR_BT_INFO,
    STR_BACK_MENU,
    STR_MENU_EXIT,
    STR_BT_DISCONNECT,
};
#pragma constseg=default

__no_init __root string tbl_bt_menu[BT_MENU_ITEM_NUM] @ "SbcPaired";

//蓝牙地址转字符串
#pragma location="BT_MENU_DISP"
void addr_to_string(u8 *dst, u8 const *src)
{
    u8 addr_len;
    for(addr_len=6; addr_len>0; addr_len--) {
        *dst++ = hex_to_char(*(src+addr_len-1)>>4);
        *dst++ = hex_to_char(*(src+addr_len-1)&0x0f);
        //*dst++ = ':';
    }
    *dst = '\0';
}

//显示设备信息
#pragma location="BT_MENU_DISP"
void task_bt_display_device(u8 show_time)
{
    draw_clear();
    disp_menu(STR_BT_INFO,0,0, 0,ME_CENTER);
    line_update(0);
    memset(bt_tmp, 0, sizeof(bt_tmp));
    //准备蓝牙名字
    bt_tmp[0]='N';
    bt_tmp[1]='a';
    bt_tmp[2]='m';
    bt_tmp[3]='e';
    bt_tmp[4]=':';
    btinfo_get_name(bt_tmp+5);
    bt_name_to_unicode(bt_tmp);
    move_ctl.name_wide=bt_name_len(bt_name_unicode);
    if(move_ctl.name_wide>96) {
        move_ctl.move_flag=1;
    }else {
        move_ctl.move_flag=0;
    }
    move_ctl.name_x=0;
    //准备蓝牙地址
    bt_tmp[0] = 'A';
    bt_tmp[1] = 'd';
    bt_tmp[2] = 'r';
    bt_tmp[3] = ':';
    btinfo_get_addr(bt_tmp+21);
    addr_to_string(bt_tmp+4, bt_tmp+21);
    line_clear();
    task_bt_disp_name(3);
    disp_text((char *)bt_tmp, 0, 0, 1);
    line_update(5);
    ocx_show_cnt = 0;
    while(1)
    {
        if(move_ctl.move_flag) {
            task_bt_disp_name(3);
        }
        u8 msg = get_msg();
        if(msg == KU_OK || msg == KU_BACK || msg == KU_PREV || msg == KU_NEXT || msg == KU_PLAY_POWER)
            break;
        if(show_time && ocx_show_cnt >= show_time)
            break;
        deal_msg(msg);
        if(msg == KL_PLAY_POWER) {
            task_ctl.work_sta = TASK_EXIT;
            return;
        }
    }
}

//蓝牙菜单显示:param,0,蓝牙未连接时调用，1，蓝牙连接时调用
#pragma location="BT_MENU_DISP"
void task_bt_menu(void)
{
    u8 index;
    u8 param = 0;

    memcpy(tbl_bt_menu,(u8 *)tbl_bt_menu_const,BT_MENU_ITEM_NUM*2);
    if(sys_ctl.bt_sta >= BT_STA_CONNECTED) {   //蓝牙已连接
        tbl_bt_menu[1] = tbl_bt_menu_const[BT_MENU_ITEM_NUM];
        param = 1;
    }
    index = listbox(0, BT_MENU_ITEM_NUM, NULL, (u16)tbl_bt_menu, LIST_TIME);
    switch (index) {
    case ITEM_BT_CON:   //  最近设备重连或断开蓝牙
        if(param == 0) {
            bt_connect();       // 重新连接
        } else {
            bt_disconnect();    // 断开连接
        }
        break;
 /* case ITEM_BT_LIST:  //连接设备历史列表

        break;*/
    case ITEM_BT_EQ:    //EQ调节
        index = listbox(sys_ctl.eq_num, MUSIC_EQ_ITEM_NUM, LB_EQ, (u16)tbl_music_eq, LIST_TIME);
        user_set_eq(index);
        music_eq(sys_ctl.eq_num);
        break;
    case ITEM_BT_DEL_PAIRED:    //删除配对信息
        bt_get_linkaddr(bt_tmp);
        bt_delete_link(bt_tmp);
        break;
    case ITEM_BT_INFO:          //设备信息
        task_bt_display_device(LIST_TIME);
        break;
    case ITEM_BTMENU_BACK:
        task_ctl.work_sta = TASK_EXIT;      //退出
        break;
    }
    t_bt.updata_flag = 1;
}

#pragma location="BT_MENU_DISP"
void tasksub_bt_menu_enter(void)
{

}

#pragma location="BT_MENU_DISP"
void tasksub_bt_menu_exit(void)
{

}

#pragma location="BT_MENU_DISP"
void tasksub_bt_menu_event(void)
{

}

#pragma location="BT_MENU_DISP"
void task_bt_menu_deal_msg(u8 msg)
{

}

#pragma location="BT_MENU_DISP"
void tasksub_bt_menu_loop(void)
{
    task_bt_menu();
}

#pragma location="BT_MENU_DISP"
void tasksub_bt_menu(void)
{
   // printf("tasksub_bt_menu\n");
    tasksub_bt_menu_enter();
    tasksub_bt_menu_loop();
    tasksub_bt_menu_exit();
    //printf("tasksub_bt_menu exit\n");
}

#endif
#endif
