hpocapp.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /* Copyright (C) 2018 RDA Technologies Limited and/or its affiliates("RDA").
  2. * All rights reserved.
  3. *
  4. * This software is supplied "AS IS" without any warranties.
  5. * RDA assumes no responsibility or liability for the use of the software,
  6. * conveys no license or title under any patent, copyright, or mask work
  7. * right to the product. RDA reserves the right to make changes in the
  8. * software without notification. RDA also make no representation or
  9. * warranty that such application will be suitable for the specified use
  10. * without further testing or modification.
  11. */
  12. //#define OSI_LOG_TAG OSI_MAKE_LOG_TAG()
  13. #include "includes.h"
  14. /*
  15. appimg_exit
  16. 仅在程序退出时打印
  17. */
  18. void appimg_exit(void){
  19. LSAPI_Log_Debug("application image exit");
  20. }
  21. #define HANDSET_THREAD_STACK 4*1024
  22. void handsetStatusOutput(unsigned char status){
  23. char info[30];
  24. snprintf(info,sizeof(info),"+HEADSET:%d\r\n",status);
  25. MSG_INFO(0,"%s",info);
  26. //outterInfo(info, strlen(info));
  27. switch(status){
  28. case 0://HEADSET CONNECT
  29. sutApp.earLev=0;
  30. // msgAtSend("AT+AUDCH=0,0\r\n");
  31. sutApp.pcant=4;
  32. break;//HEADSET DISCONNECTED
  33. case 1:
  34. sutApp.earLev=1;
  35. // msgAtSend("AT+AUDCH=1,3\r\n");
  36. sutApp.pcant=2;
  37. break;//HEADSET BTN PRESS
  38. case 2:
  39. micPttHandler(1);
  40. break;//HEADSET BTN RELEASED
  41. case 3:
  42. micPttHandler(0);
  43. break;
  44. }
  45. }
  46. void prvHeadSetDetectCallback(void *ctx, LSAPI_HeadSetDetectId_t id, uint32_t param)
  47. {
  48. MSG_INFO(1,"prvHeadSetDetectCallback_t(id:%d,param:%d)",id, param);
  49. switch(id){
  50. case LSAPI_HEADSET_PLUGIN:
  51. MSG_INFO(1,"--->>headset plugin");
  52. handsetStatusOutput(0);
  53. break;
  54. case LSAPI_HEADSET_PLUGOUT:
  55. MSG_INFO(1,"--->>headset plugout");
  56. handsetStatusOutput(1);
  57. break;
  58. case LSAPI_HEADSET_BTN_DOWN:
  59. MSG_INFO(1,"--->>headset btn_dwon(volt:%dmV)",param);
  60. handsetStatusOutput(2);
  61. break;
  62. case LSAPI_HEADSET_BTN_UP:
  63. MSG_INFO(1,"--->>headset btn_up(volt:%dmV)",param);
  64. handsetStatusOutput(3);
  65. break;
  66. default:
  67. break;
  68. }
  69. }
  70. void handSetThread(void *param){
  71. LSAPI_OSI_Event_t waitevent;
  72. LSAPI_HeadSetStatus_t status;
  73. static unsigned char FristHeadDet=0;
  74. MSG_INFO(1,"handSetThread start");
  75. switch (FristHeadDet)
  76. {
  77. case 0:
  78. status= LSAPI_Device_HeadSetGetStatus();//0628 首次需要用户判定
  79. if(status == LSAPI_HEADSET_DISCONNECT)
  80. {
  81. // MSG_INFO(1,"headset_disconnect");
  82. handsetStatusOutput(1);
  83. }
  84. else if(status == LSAPI_HEADSET_CONNECT)
  85. {
  86. //MSG_INFO(1," headset_connect");
  87. handsetStatusOutput(0);
  88. }
  89. else
  90. {
  91. //MSG_INFO(1,"unknow state");
  92. }
  93. FristHeadDet=1;
  94. break;
  95. }
  96. if(LSAPI_Device_HeadSetSetDetectCB(prvHeadSetDetectCallback)) MSG_INFO(1,"Handset cb ok");
  97. else MSG_INFO(1,"Handset cb failed!!!");
  98. for(;;){
  99. LSAPI_OSI_EventWait(LSAPI_OSI_ThreadCurrent(), &waitevent);
  100. }
  101. }
  102. void handSetInit(void){
  103. if(NULL==LSAPI_OSI_ThreadCreate("handset", handSetThread, NULL, LSAPI_OSI_PRIORITY_NORMAL, HANDSET_THREAD_STACK, 4)) MSG_INFO(1,"handset thread failed");
  104. }
  105. //LSAPI_AUD_CusToneV2
  106. /*! \brief This function is used to player custom tone V2
  107. *
  108. * \param[in] low_freq tone lower frequecy, range in [1, 9000]
  109. *
  110. * \param[in] high_freq tone high frequecy, range in [1, 9000]
  111. *
  112. * \param[in] duration tone duration, uint: millisecond, [100,1000].
  113. *
  114. * \param[in] gain see:LSAPI_AUD_CusToneGain_t
  115. *
  116. * \param[in] silence tone silence, uint: millisecond,[0,100].
  117. *
  118. *
  119. * \return enum: LSAPI_Status_t
  120. */
  121. //LSAPI_AUD_CusToneGain_t
  122. LSAPI_OSI_Thread_t * ToneThreadPtr=NULL;
  123. void ToneThread(void *param){
  124. LSAPI_OSI_Event_t waitevent;
  125. for(;;){
  126. LSAPI_OSI_EventWait(LSAPI_OSI_ThreadCurrent(), &waitevent);
  127. if(sutPocStatus.mic==1||sutPocStatus.spk==1)continue;
  128. MSG_INFO(1, "TONE satrt");
  129. msgAtSend("AT+POC=4C00000001037003700150\r\n");
  130. }
  131. }
  132. void ToneInit(void){
  133. ToneThreadPtr=LSAPI_OSI_ThreadCreate("tonedet", ToneThread, NULL, LSAPI_OSI_PRIORITY_NORMAL, HANDSET_THREAD_STACK, 4);
  134. if(ToneThreadPtr==NULL)MSG_INFO(1,"tone thread failed");
  135. }
  136. void startSubTask(void);
  137. void startSubTask(void){
  138. if(NULL==LSAPI_OSI_ThreadCreate("sub", subTask, NULL, LSAPI_OSI_PRIORITY_NORMAL, SUB_TASK_THREAD_STACK, 10)){
  139. MSG_ERR(1, "sub task failed");
  140. }else MSG_ERR(1, "sub task ok");
  141. }
  142. static void mainTask(void *param){
  143. //LSAPI_OSI_ThreadSleep(5000);
  144. handSetInit();
  145. ToneInit();
  146. dataInit();
  147. boardInit();
  148. startSubTask();//线程会调用外设接口,必须在boardInit后启动
  149. appRun();//应用主程序(pt)
  150. }
  151. /*
  152. appimg_enter
  153. cat one入口函数
  154. */
  155. LSAPI_OSI_Thread_t * mainThreadPtr=NULL;
  156. int appimg_enter(void *param){
  157. if(NULL==(mainThreadPtr=LSAPI_OSI_ThreadCreate("main", mainTask, NULL, LSAPI_OSI_PRIORITY_NORMAL, PT_THREAD_STACK, 5))){
  158. for(;;){
  159. LSAPI_Log_Debug("main task failed");
  160. LSAPI_OSI_ThreadSleep(1000);
  161. }
  162. }
  163. return 0;
  164. }