hpocapp.c 5.1 KB

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