hook.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. #include "includes.h"
  2. #include "hook.h"
  3. //////////低功耗控制钩子功能/////////////////////
  4. unsigned int pwrSaveTick;
  5. unsigned char sendEnableNow=0;
  6. unsigned char QueryTime=10;//查询时间 QueryTime/2
  7. unsigned char QueryTick=0;//查询时间计时
  8. signed char Chargeing;
  9. const short HGSSendAtLv[10] = {0,25,35,45,55,60,65,70,75,80};
  10. const short BNDSendAtLv[10] = {0,25,35,45,55,65,75,80,85,90};
  11. const short ERRSendAtLv[10] = {0,25,35,45,55,65,75,85,90,100};
  12. ASSIST_DEF uiAssist;
  13. void enableDataSend(void)
  14. {
  15. //此刻可以发GPS数据啦,我们让接下来2秒内可以发心跳或GPS位置包,我们只限制这两个就好了
  16. uTimerStart(&pwrSaveTick,200);
  17. sendEnableNow=1;
  18. SlwTrace(INF, "Send enable",1);
  19. }
  20. char isSendDataEnable(void)
  21. {
  22. if(hgs_poc_type == POC_BND) return 1;//西安POC的话,就一直返回yes,不存在低功耗操作
  23. if(newPara.pwrMode == 1) return 1;//常规模式就一直返回yes
  24. if(sendEnableNow==0) return 0;
  25. else return 1;
  26. }
  27. void powerSaveHandle(void)
  28. {
  29. if(sendEnableNow==0) return;
  30. if(uTimerExpired(&pwrSaveTick)==0) return; //未超时返回
  31. sendEnableNow=0;
  32. SlwTrace(INF, "Send disable",1);
  33. }
  34. void SwitchGroupCtrl(void)
  35. {
  36. if(m_GroupSwitch)
  37. {
  38. if(++m_GroupSwitchCnt >=5)
  39. {
  40. //MeSpeak(ENCODE_ASCII, "CDCBB3F6", 0);
  41. if(sutUIstatus.Status == UIS_STANDBY)
  42. ShowButton(1,107,"菜单");
  43. m_GroupSwitch=0;
  44. SlwTrace(INF, "QuitGroupSel",1);
  45. }
  46. }
  47. }
  48. void SwitchGroupPre(void)
  49. {
  50. //让菜单变成:确定
  51. ShowButton(1,107,"确定");
  52. m_GroupSwitch=1;
  53. m_GroupSwitchCnt=0;
  54. }
  55. void SwitchVoicePre(char type)
  56. {
  57. char buf[20];
  58. //GuiDrawRect(29,110,128,126,1);
  59. GuiClearRect(29,110,90,126);
  60. switch(m_VoiceStep)
  61. {
  62. case 0:
  63. m_VoiceStep=1;
  64. break;
  65. case 1:
  66. if(type)
  67. {
  68. if(newPara.VolumLv<8&&(hgs_poc_type==POC_OWN))newPara.VolumLv++;
  69. if(newPara.VolumLv<9&&(hgs_poc_type==POC_BND))newPara.VolumLv++;
  70. }else{
  71. if(newPara.VolumLv>0){
  72. newPara.VolumLv--;
  73. // if(m_VoiceSwitchCnt<=2)GuiFillRect(29+1+newPara.VolumLv*10,110+1,127,126-1,COLOR_WHITE_BACK);
  74. // printf("newPara.VolumLv===%d\r\n",newPara.VolumLv);
  75. }
  76. }
  77. break;
  78. }
  79. //GuiFillRect(29,110+1,29+newPara.VolumLv*10-1,126-1,COLOR_BLUE);
  80. GuiShowBmp(29,110,"volume.bmp");
  81. snprintf(buf,sizeof(buf),"音量 %d",newPara.VolumLv);
  82. GuiShowStr(45,110,buf,1,0);
  83. snprintf(buf,sizeof(buf),"AT+CLVL=%d\r\n",newPara.VolumLv*10);
  84. ModemSendAt(buf);
  85. if(hgs_poc_type==POC_OWN){
  86. snprintf(buf,sizeof(buf),"AT+CRSL=%d\r\n",newPara.VolumLv*10);
  87. ModemSendAt(buf);
  88. }else {
  89. if(newPara.KeySound!=0){
  90. snprintf(buf,sizeof(buf),"AT+POC=tonevol=%d\r\n",newPara.VolumLv);
  91. ModemSendAt(buf);
  92. }
  93. snprintf(buf,sizeof(buf),"AT+POC=ttsvol=%d\r\n",(newPara.VolumLv));
  94. ModemSendAt(buf);
  95. }
  96. m_VoiceSwitch=1;
  97. m_VoiceSwitchCnt=0;
  98. }
  99. void SwitchVoiceCtrl(void)
  100. {
  101. if(m_VoiceSwitch)
  102. {
  103. if(++m_VoiceSwitchCnt >=2)
  104. {
  105. if(sutUIstatus.Status == UIS_STANDBY){
  106. //GuiClearRect(29,110,128,126);//GuiDrawRect(29,50+50,128,66+50,1);
  107. GuiClearRect(29,110,90,126);
  108. ModifyConfigureFile(0);
  109. m_VoiceSwitch=0;
  110. m_VoiceStep=0;
  111. SlwTrace(INF, "QuitVoiceSel",1);
  112. }
  113. }
  114. }
  115. }
  116. char SpkerLvlProcess(char update)
  117. {
  118. short templv=0;
  119. static char LastTemplv=0;
  120. static unsigned char Lastnum=0;//0
  121. static short SpkCnt=0;
  122. unsigned char i=0;
  123. char buf[30];
  124. const unsigned short VolArr[VOL_LEV_NUM]={100,410,820,1230,1640,2050,2460,3000,3500,4090};//,4090}; //,200
  125. templv=GetPowerVbat();
  126. LastTemplv=Lastnum;
  127. for(i=0;i<VOL_LEV_NUM;i++)
  128. {
  129. if(LastTemplv==0){
  130. if(LastTemplv==0)if(templv>VolArr[LastTemplv]+VOL_LEV_DEF)LastTemplv++;
  131. }else if(LastTemplv<VOL_LEV_NUM-1){
  132. if(templv>=VolArr[LastTemplv]+VOL_LEV_DEF)LastTemplv++;
  133. else if(templv<VolArr[LastTemplv-1]-VOL_LEV_DEF)LastTemplv--;
  134. }else {
  135. if(LastTemplv==VOL_LEV_NUM-1)if(templv<VolArr[LastTemplv-1]-VOL_LEV_DEF)LastTemplv--;
  136. }
  137. }
  138. // printf("templv=%d----num===%d\r\n",templv,LastTemplv);
  139. if(update==1) return LastTemplv;
  140. if(LastTemplv!=Lastnum||update==2){
  141. if(LastTemplv!=0)SpeakerEnable();
  142. printf("templv=%d----num===%d\r\n",templv,LastTemplv);
  143. if(update==2){
  144. Lastnum=LastTemplv;
  145. newPara.VolumLv=LastTemplv;
  146. //FMSetVolume(Lastnum,1);
  147. }
  148. else{
  149. if(sutUIstatus.Status==UIS_STANDBY)
  150. {
  151. GuiClearRect(26,107,100,124);
  152. GuiShowBmp(60,110,"volume.bmp");
  153. snprintf(buf,sizeof(buf),"%02d",LastTemplv);
  154. GuiShowStr(78,110,buf,0x10,0);
  155. }
  156. Lastnum=LastTemplv;
  157. newPara.VolumLv=LastTemplv;
  158. }
  159. snprintf(buf,sizeof(buf),"音量 %d",Lastnum);
  160. printf(buf);
  161. //;
  162. if(sutPocStatus.HeadSetPtt==1){
  163. snprintf(buf,sizeof(buf),"AT+CLVL=%d\r\n",ERRSendAtLv[Lastnum]);//10
  164. }else if(hgs_poc_type==POC_OWN){
  165. snprintf(buf,sizeof(buf),"AT+CLVL=%d\r\n",HGSSendAtLv[Lastnum]);//10
  166. }else if(hgs_poc_type==POC_BND){
  167. snprintf(buf,sizeof(buf),"AT+CLVL=%d\r\n",BNDSendAtLv[Lastnum]);//10
  168. }
  169. ModemSendAt(buf);
  170. if(hgs_poc_type==POC_OWN){
  171. snprintf(buf,sizeof(buf),"AT+CRSL=%d\r\n",Lastnum*10);//10
  172. ModemSendAt(buf);
  173. }else {
  174. if(newPara.KeySound!=0){
  175. snprintf(buf,sizeof(buf),"AT+POC=tonevol=%d\r\n",Lastnum);
  176. ModemSendAt(buf);
  177. }
  178. snprintf(buf,sizeof(buf),"AT+POC=ttsvol=%d\r\n",(Lastnum));
  179. ModemSendAt(buf);
  180. }
  181. LCDBackLight(1);
  182. LcdOnTimeCt=0;
  183. SpkCnt=300;
  184. }
  185. if(SpkCnt>0){
  186. if((--SpkCnt==0)&&(sutUIstatus.Status==UIS_STANDBY)){
  187. GuiClearRect(26,107,100,124);
  188. if(g_uslockflag==1){
  189. GuiShowBmp(72,110,"lock.bmp");
  190. }
  191. if(sutPocStatus.Speaker==0&&sutPocStatus.TTS==0) SpeakerDisable();
  192. }
  193. }
  194. return LastTemplv;
  195. }
  196. void HeadsetProcess(void)
  197. {
  198. static signed char HeadsetStatue=0;
  199. static signed char HeadseLastStatue=0;
  200. if(INTERNAL_HEADSET==1) return;
  201. if(RESET==GPIO_ReadInputDataBit(HEADSET_PORT,HEADSET_PIN))HeadsetStatue=1;
  202. else HeadsetStatue=-1;
  203. if(HeadseLastStatue!=HeadsetStatue){
  204. if(HeadsetStatue==1){
  205. printf("耳机接入---\r\n");
  206. //ModemSendAt("AT+AUDCH=1,3\r\n");
  207. sutPocStatus.HeadSetPtt=1;
  208. }
  209. else {
  210. printf("耳机拔出---\r\n");
  211. ModemSendAt("AT+AUDCH=0,0\r\n");
  212. sutPocStatus.HeadSetPtt=0;
  213. }
  214. uTimerStart(&HeadSetChange,200);
  215. SpkerLvlProcess(2);
  216. HeadseLastStatue=HeadsetStatue;
  217. }
  218. /*为了规避耳机拔出问题*/
  219. if(HeadsetPress && sutPocStatus.HeadSetPtt){
  220. if(uTimerExpired(&HeadsetPullPress)){
  221. if(hgs_poc_type==POC_BND)ModemSendAt("AT+POC=ptt,1\r\n");
  222. else {
  223. ModemSendAt("AT+POC=0B0000\r\n");
  224. }
  225. HeadsetPress=0;
  226. }
  227. }
  228. }
  229. //开机后的一些控制
  230. void onStartCtl(void){
  231. Chargeing=GPIO_ReadInputDataBit(CHARGE_PORT,CHARGE_PIN);
  232. KeyCount();
  233. SwitchGroupCtrl();
  234. SwitchVoiceCtrl();
  235. if(newPara.lcdParaList[newPara.lcdParaDefaultIndex]>0){
  236. if(++LcdOnTimeCt>=newPara.lcdParaList[newPara.lcdParaDefaultIndex]){
  237. LcdOnTimeCt=0;
  238. if(sutPocStatus.FirstLogined==0){
  239. LCDBackLight(1);//没登陆过(刚开机),LCD一直亮着//0
  240. }else LCDBackLight(0);
  241. }
  242. }
  243. }
  244. void AtRequest()
  245. {
  246. static char step=0;
  247. switch(step)
  248. {
  249. case 0:
  250. break;
  251. }
  252. }
  253. void UiassistStart(unsigned char type){
  254. uiAssist.type=type;
  255. uiAssist.machine=0;
  256. uiAssist.status=1;
  257. }
  258. void UiassistEnd(unsigned char type){
  259. uiAssist.type=type;
  260. uiAssist.machine=0;
  261. uiAssist.status=0;
  262. assistResult=0;
  263. }
  264. unsigned char assistResult=0;
  265. unsigned char getAssistResult(void){
  266. unsigned char ret=0;
  267. ret=assistResult;
  268. if(assistResult) assistResult=0;
  269. return ret;
  270. }
  271. PT_THREAD (ptUIAssist(struct pt *pt)){
  272. static timer_t ptTimer;
  273. PT_BEGIN(pt);
  274. while(1){
  275. if(uiAssist.status!=0){
  276. switch(uiAssist.type){
  277. case 0: // //刚进入
  278. switch(uiAssist.machine){
  279. case 0:
  280. if(SimpleUserInfoScan(1, 2)){//操作完成了
  281. printf("获取成功了---\r\n");
  282. assistResult=1;
  283. uiAssist.status=0;
  284. }
  285. break;
  286. }
  287. break;
  288. case 1: //上翻
  289. switch(uiAssist.machine){
  290. case 0:
  291. if(SimpleUserInfoScan(0,0)){
  292. assistResult=1;
  293. uiAssist.status=0;
  294. }
  295. break;
  296. }
  297. break;
  298. case 2: //下翻
  299. switch(uiAssist.machine){
  300. case 0:
  301. if(SimpleUserInfoScan(0,1)){
  302. assistResult=1;
  303. uiAssist.status=0;
  304. }
  305. break;
  306. }
  307. break;
  308. }
  309. }
  310. PTTimerStart(&pt_timerPool, &ptTimer, 1);//1
  311. PT_WAIT_UNTIL(pt, PTTimerIsExpired(&ptTimer));
  312. }
  313. PT_END(pt);
  314. }