hpocapp.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. LSAPI_OSI_Thread_t * ToneThreadPtr=NULL;
  22. #define HANDSET_THREAD_STACK 4*1024
  23. void ToneThread(void *param){
  24. LSAPI_OSI_Event_t waitevent;
  25. for(;;){
  26. LSAPI_OSI_EventWait(LSAPI_OSI_ThreadCurrent(), &waitevent);
  27. if(sutPocStatus.beep==1){
  28. MSG_INFO(1, "TONE satrt");
  29. if(sutPocStatus.spk==0){
  30. LSAPI_AUD_CusToneV2(TONEFRE,TONEFRE,100,LSAPI_CUSTONE_GAIN_NEGA_24,0);//24
  31. LSAPI_AUD_SetPlayVolumeLevel(newPara.spkVol*6);//10
  32. }
  33. sutPocStatus.beep=0;
  34. }
  35. }
  36. }
  37. void ToneInit(void){
  38. ToneThreadPtr=LSAPI_OSI_ThreadCreate("tonedet", ToneThread, NULL, LSAPI_OSI_PRIORITY_NORMAL, HANDSET_THREAD_STACK, 4);
  39. if(ToneThreadPtr==NULL)MSG_INFO(1,"tone thread failed");
  40. }
  41. static void StartSubPTH(void)
  42. {
  43. if(NULL==LSAPI_OSI_ThreadCreate("sub", subTask, NULL, LSAPI_OSI_PRIORITY_NORMAL, SUB_TASK_THREAD_STACK, 10)){
  44. for(;;){
  45. LSAPI_Log_Debug("sub task failed");
  46. LSAPI_OSI_ThreadSleep(1000);
  47. }
  48. }
  49. }
  50. #define HANDSET_THREAD_STACK 4*1024
  51. void handsetStatusOutput(unsigned char status){
  52. char info[30];
  53. // return;
  54. snprintf(info,sizeof(info),"+HEADSET:%d\r\n",status);
  55. MSG_INFO(0,"%s",info);
  56. //outterInfo(info, strlen(info));
  57. switch(status){
  58. case 0://HEADSET CONNECT
  59. sutApp.earLev=1;
  60. msgAtSend("AT+AUDCH=1,3\r\n");
  61. sutApp.pcant=2;
  62. break;//HEADSET DISCONNECTED
  63. case 1:
  64. sutApp.earLev=0;
  65. msgAtSend("AT+AUDCH=0,0\r\n");
  66. sutApp.pcant=4;
  67. break;//HEADSET BTN PRESS
  68. case 2:
  69. micPttHandler(1);
  70. break;//HEADSET BTN RELEASED
  71. case 3:
  72. micPttHandler(0);
  73. break;
  74. }
  75. }
  76. void prvHeadSetDetectCallback(void *ctx, LSAPI_HeadSetDetectId_t id, uint32_t param)
  77. {
  78. MSG_INFO(1,"prvHeadSetDetectCallback_t(id:%d,param:%d)",id, param);
  79. switch(id){
  80. case LSAPI_HEADSET_PLUGIN:
  81. MSG_INFO(1,"--->>headset plugin");
  82. handsetStatusOutput(0);
  83. break;
  84. case LSAPI_HEADSET_PLUGOUT:
  85. MSG_INFO(1,"--->>headset plugout");
  86. handsetStatusOutput(1);
  87. break;
  88. case LSAPI_HEADSET_BTN_DOWN:
  89. MSG_INFO(1,"--->>headset btn_dwon(volt:%dmV)",param);
  90. handsetStatusOutput(2);
  91. break;
  92. case LSAPI_HEADSET_BTN_UP:
  93. MSG_INFO(1,"--->>headset btn_up(volt:%dmV)",param);
  94. handsetStatusOutput(3);
  95. break;
  96. default:
  97. break;
  98. }
  99. }
  100. void handSetThread(void *param){
  101. LSAPI_OSI_Event_t waitevent;
  102. LSAPI_HeadSetStatus_t status;
  103. static unsigned char FristHeadDet=0;
  104. MSG_INFO(1,"handSetThread start");
  105. switch (FristHeadDet)
  106. {
  107. case 0:
  108. status= LSAPI_Device_HeadSetGetStatus();//0628
  109. if(status == LSAPI_HEADSET_DISCONNECT)
  110. {
  111. MSG_INFO(1,"headset_disconnect");
  112. handsetStatusOutput(1);
  113. }
  114. else if(status == LSAPI_HEADSET_CONNECT)
  115. {
  116. MSG_INFO(1," headset_connect");
  117. handsetStatusOutput(0);
  118. }
  119. else
  120. {
  121. MSG_INFO(1,"unknow state");
  122. }
  123. FristHeadDet=1;
  124. break;
  125. }
  126. if(LSAPI_Device_HeadSetSetDetectCB(prvHeadSetDetectCallback)) MSG_INFO(1,"Handset cb ok");
  127. else MSG_INFO(1,"Handset cb failed!!!");
  128. for(;;){
  129. LSAPI_OSI_EventWait(LSAPI_OSI_ThreadCurrent(), &waitevent);
  130. }
  131. }
  132. void handSetInit(void){
  133. if(NULL==LSAPI_OSI_ThreadCreate("handset", handSetThread, NULL, LSAPI_OSI_PRIORITY_NORMAL, HANDSET_THREAD_STACK, 4)) MSG_INFO(1,"handset thread failed");
  134. }
  135. static void mainTask(void *param){
  136. #if 1
  137. handSetInit();
  138. ToneInit();
  139. dataInit();
  140. boardInit();
  141. StartSubPTH();//线程会调用外设接口,必须在boardInit后启势
  142. appRun();//应用主程庿pt)
  143. #else
  144. //LSAPI_OSI_ThreadSleep(10000);
  145. //StartSubPTH();
  146. //subTimerCtl(1);
  147. newPara.newold_plam=1;
  148. open_bnd_app();
  149. while(1){
  150. LSAPI_OSI_ThreadSleep(5000);
  151. }
  152. #endif
  153. }
  154. /*
  155. appimg_enter
  156. cat one入口函数
  157. */
  158. LSAPI_OSI_Thread_t * mainThreadPtr=NULL;
  159. int appimg_enter(void *param){
  160. if(NULL==(mainThreadPtr=LSAPI_OSI_ThreadCreate("main", mainTask, NULL, LSAPI_OSI_PRIORITY_BELOW_NORMAL, PT_THREAD_STACK, 5))){
  161. for(;;){
  162. LSAPI_Log_Debug("main task failed");
  163. LSAPI_OSI_ThreadSleep(1000);
  164. }
  165. }
  166. return 0;
  167. }