/*****************************************************************************
 * Module    : Task
 * File      : task_bt.c
 * Author    : Hanny
 * Function  : 蓝牙任务流程
 *****************************************************************************/
#include "include.h"
#if TASK_BTHID_EN
#include "task.h"

void test_bt(void);
bool btdec_load_code(u16 addr, u8 segnum);
void task_bt_sta_update(void);
extern IAR_BIT_A bool flag_btmode;            //为1时启用完整的蓝牙功能
extern IAR_BIT_A bool scoflag;  //for nokia 5000 use sco play music
extern u8 work_sta_interrupt;          //电话中断标志
extern void power_down_enter(void);
void bt_play_continue(void);
#pragma constseg="TASK_BT_SEG_CONST"
IAR_CONST char str_show_task_bthid[] = "task_bthid\n";
IAR_CONST char str_show_task_bthid_exit[] = "task_bthid_exit\n";
#pragma constseg=default


void task_bt_enter(void);
void task_bt_event(void);
void task_bt_display(void);
void task_bt_hid_deal_msg(u8 msg);
void bt_close(void);
void task_bt_exit(void);
void tasksub_bt_test(void);


void task_bt_hid_enter(void)
{
    task_hid_flag = 1;
    task_bt_enter();
}

//#pragma location="TASK_BTEVENT_SEG"
void task_bt_hid_loop(void)
{
    u8 msg;
    while ((task_ctl.work_sta == TASK_BT_HID || sys_ctl.bt_sta >= BT_STA_INCOMING)
           && (task_ctl.work_sta != TASK_POWEROFF))
    {
        task_bt_event();
        while (msg = get_msg()) {
            task_bt_hid_deal_msg(msg);

#if WARNING_LOWPOWER    // 低电时跳出手机响铃
            if(task_ctl.work_sta == TASK_POWEROFF) {
                break;
            }
#endif

        }
        task_bt_display();
    }
}

void task_bt_hid_exit(void)
{
    task_bt_exit();
    task_hid_flag = 0;
}

//蓝牙任务
#pragma location="TASK_BT_SEG"
void task_bt_hid(void)
{
    printf(str_show_task_bthid);
    task_bt_hid_enter();
    task_bt_hid_loop();
    task_bt_hid_exit();
    printf(str_show_task_bthid_exit);
}
#endif
