hook.c 7.1 KB

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