/* Copyright (C) 2018 RDA Technologies Limited and/or its affiliates("RDA"). * All rights reserved. * * This software is supplied "AS IS" without any warranties. * RDA assumes no responsibility or liability for the use of the software, * conveys no license or title under any patent, copyright, or mask work * right to the product. RDA reserves the right to make changes in the * software without notification. RDA also make no representation or * warranty that such application will be suitable for the specified use * without further testing or modification. */ //#define OSI_LOG_TAG OSI_MAKE_LOG_TAG() #include "includes.h" /* appimg_exit 仅在程序退出时打印 */ void appimg_exit(void){ LSAPI_Log_Debug("application image exit"); } #define HANDSET_THREAD_STACK 4*1024 void handsetStatusOutput(unsigned char status){ char info[30]; snprintf(info,sizeof(info),"+HEADSET:%d\r\n",status); MSG_INFO(0,"%s",info); //outterInfo(info, strlen(info)); switch(status){ case 0://HEADSET CONNECT sutApp.earLev=0; // msgAtSend("AT+AUDCH=0,0\r\n"); sutApp.pcant=4; break;//HEADSET DISCONNECTED case 1: sutApp.earLev=1; // msgAtSend("AT+AUDCH=1,3\r\n"); sutApp.pcant=2; break;//HEADSET BTN PRESS case 2: micPttHandler(1); break;//HEADSET BTN RELEASED case 3: micPttHandler(0); break; } } void prvHeadSetDetectCallback(void *ctx, LSAPI_HeadSetDetectId_t id, uint32_t param) { MSG_INFO(1,"prvHeadSetDetectCallback_t(id:%d,param:%d)",id, param); switch(id){ case LSAPI_HEADSET_PLUGIN: MSG_INFO(1,"--->>headset plugin"); handsetStatusOutput(0); break; case LSAPI_HEADSET_PLUGOUT: MSG_INFO(1,"--->>headset plugout"); handsetStatusOutput(1); break; case LSAPI_HEADSET_BTN_DOWN: MSG_INFO(1,"--->>headset btn_dwon(volt:%dmV)",param); handsetStatusOutput(2); break; case LSAPI_HEADSET_BTN_UP: MSG_INFO(1,"--->>headset btn_up(volt:%dmV)",param); handsetStatusOutput(3); break; default: break; } } void handSetThread(void *param){ LSAPI_OSI_Event_t waitevent; LSAPI_HeadSetStatus_t status; static unsigned char FristHeadDet=0; MSG_INFO(1,"handSetThread start"); switch (FristHeadDet) { case 0: status= LSAPI_Device_HeadSetGetStatus();//0628 首次需要用户判定 if(status == LSAPI_HEADSET_DISCONNECT) { // MSG_INFO(1,"headset_disconnect"); handsetStatusOutput(1); } else if(status == LSAPI_HEADSET_CONNECT) { //MSG_INFO(1," headset_connect"); handsetStatusOutput(0); } else { //MSG_INFO(1,"unknow state"); } FristHeadDet=1; break; } if(LSAPI_Device_HeadSetSetDetectCB(prvHeadSetDetectCallback)) MSG_INFO(1,"Handset cb ok"); else MSG_INFO(1,"Handset cb failed!!!"); for(;;){ LSAPI_OSI_EventWait(LSAPI_OSI_ThreadCurrent(), &waitevent); } } void handSetInit(void){ if(NULL==LSAPI_OSI_ThreadCreate("handset", handSetThread, NULL, LSAPI_OSI_PRIORITY_NORMAL, HANDSET_THREAD_STACK, 4)) MSG_INFO(1,"handset thread failed"); } //LSAPI_AUD_CusToneV2 /*! \brief This function is used to player custom tone V2 * * \param[in] low_freq tone lower frequecy, range in [1, 9000] * * \param[in] high_freq tone high frequecy, range in [1, 9000] * * \param[in] duration tone duration, uint: millisecond, [100,1000]. * * \param[in] gain see:LSAPI_AUD_CusToneGain_t * * \param[in] silence tone silence, uint: millisecond,[0,100]. * * * \return enum: LSAPI_Status_t */ //LSAPI_AUD_CusToneGain_t LSAPI_OSI_Thread_t * ToneThreadPtr=NULL; void ToneThread(void *param){ LSAPI_OSI_Event_t waitevent; for(;;){ LSAPI_OSI_EventWait(LSAPI_OSI_ThreadCurrent(), &waitevent); if(sutPocStatus.mic==1||sutPocStatus.spk==1)continue; MSG_INFO(1, "TONE satrt"); msgAtSend("AT+POC=4C00000001037003700150\r\n"); } } void ToneInit(void){ ToneThreadPtr=LSAPI_OSI_ThreadCreate("tonedet", ToneThread, NULL, LSAPI_OSI_PRIORITY_NORMAL, HANDSET_THREAD_STACK, 4); if(ToneThreadPtr==NULL)MSG_INFO(1,"tone thread failed"); } void startSubTask(void); void startSubTask(void){ if(NULL==LSAPI_OSI_ThreadCreate("sub", subTask, NULL, LSAPI_OSI_PRIORITY_NORMAL, SUB_TASK_THREAD_STACK, 10)){ MSG_ERR(1, "sub task failed"); }else MSG_ERR(1, "sub task ok"); } static void mainTask(void *param){ //LSAPI_OSI_ThreadSleep(5000); handSetInit(); ToneInit(); dataInit(); boardInit(); startSubTask();//线程会调用外设接口,必须在boardInit后启动 appRun();//应用主程序(pt) } /* appimg_enter cat one入口函数 */ LSAPI_OSI_Thread_t * mainThreadPtr=NULL; int appimg_enter(void *param){ if(NULL==(mainThreadPtr=LSAPI_OSI_ThreadCreate("main", mainTask, NULL, LSAPI_OSI_PRIORITY_NORMAL, PT_THREAD_STACK, 5))){ for(;;){ LSAPI_Log_Debug("main task failed"); LSAPI_OSI_ThreadSleep(1000); } } return 0; }