hpocapp.c 5.2 KB

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