123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358 |
- #include "includes.h"
- #include "hook.h"
- //////////低功耗控制钩子功能/////////////////////
- unsigned int pwrSaveTick;
- unsigned char sendEnableNow=0;
- unsigned char QueryTime=10;//查询时间 QueryTime/2
- unsigned char QueryTick=0;//查询时间计时
- signed char Chargeing;
- const short HGSSendAtLv[10] = {0,25,35,45,55,60,65,70,75,80};
- const short BNDSendAtLv[10] = {0,25,35,45,55,65,75,80,85,90};
- const short ERRSendAtLv[10] = {0,25,35,45,55,65,75,85,90,100};
- ASSIST_DEF uiAssist;
- void enableDataSend(void)
- {
- //此刻可以发GPS数据啦,我们让接下来2秒内可以发心跳或GPS位置包,我们只限制这两个就好了
- uTimerStart(&pwrSaveTick,200);
- sendEnableNow=1;
- SlwTrace(INF, "Send enable",1);
- }
- char isSendDataEnable(void)
- {
- if(hgs_poc_type == POC_BND) return 1;//西安POC的话,就一直返回yes,不存在低功耗操作
- if(newPara.pwrMode == 1) return 1;//常规模式就一直返回yes
- if(sendEnableNow==0) return 0;
- else return 1;
- }
- void powerSaveHandle(void)
- {
- if(sendEnableNow==0) return;
- if(uTimerExpired(&pwrSaveTick)==0) return; //未超时返回
- sendEnableNow=0;
- SlwTrace(INF, "Send disable",1);
- }
- void SwitchGroupCtrl(void)
- {
- if(m_GroupSwitch)
- {
- if(++m_GroupSwitchCnt >=5)
- {
- //MeSpeak(ENCODE_ASCII, "CDCBB3F6", 0);
- if(sutUIstatus.Status == UIS_STANDBY)
- ShowButton(1,107,"菜单");
- m_GroupSwitch=0;
- SlwTrace(INF, "QuitGroupSel",1);
- }
- }
- }
- void SwitchGroupPre(void)
- {
- //让菜单变成:确定
- ShowButton(1,107,"确定");
- m_GroupSwitch=1;
- m_GroupSwitchCnt=0;
- }
- void SwitchVoicePre(char type)
- {
- char buf[20];
- //GuiDrawRect(29,110,128,126,1);
- GuiClearRect(29,110,90,126);
- switch(m_VoiceStep)
- {
- case 0:
- m_VoiceStep=1;
- break;
- case 1:
- if(type)
- {
- if(newPara.VolumLv<8&&(hgs_poc_type==POC_OWN))newPara.VolumLv++;
- if(newPara.VolumLv<9&&(hgs_poc_type==POC_BND))newPara.VolumLv++;
- }else{
- if(newPara.VolumLv>0){
- newPara.VolumLv--;
- // if(m_VoiceSwitchCnt<=2)GuiFillRect(29+1+newPara.VolumLv*10,110+1,127,126-1,COLOR_WHITE_BACK);
- // printf("newPara.VolumLv===%d\r\n",newPara.VolumLv);
- }
- }
- break;
- }
- //GuiFillRect(29,110+1,29+newPara.VolumLv*10-1,126-1,COLOR_BLUE);
- GuiShowBmp(29,110,"volume.bmp");
- snprintf(buf,sizeof(buf),"音量 %d",newPara.VolumLv);
- GuiShowStr(45,110,buf,1,0);
- snprintf(buf,sizeof(buf),"AT+CLVL=%d\r\n",newPara.VolumLv*10);
- ModemSendAt(buf);
-
- if(hgs_poc_type==POC_OWN){
- snprintf(buf,sizeof(buf),"AT+CRSL=%d\r\n",newPara.VolumLv*10);
- ModemSendAt(buf);
- }else {
- if(newPara.KeySound!=0){
- snprintf(buf,sizeof(buf),"AT+POC=tonevol=%d\r\n",newPara.VolumLv);
- ModemSendAt(buf);
- }
- snprintf(buf,sizeof(buf),"AT+POC=ttsvol=%d\r\n",(newPara.VolumLv));
- ModemSendAt(buf);
- }
- m_VoiceSwitch=1;
- m_VoiceSwitchCnt=0;
- }
- void SwitchVoiceCtrl(void)
- {
- if(m_VoiceSwitch)
- {
- if(++m_VoiceSwitchCnt >=2)
- {
- if(sutUIstatus.Status == UIS_STANDBY){
- //GuiClearRect(29,110,128,126);//GuiDrawRect(29,50+50,128,66+50,1);
- GuiClearRect(29,110,90,126);
- ModifyConfigureFile(0);
- m_VoiceSwitch=0;
- m_VoiceStep=0;
- SlwTrace(INF, "QuitVoiceSel",1);
- }
- }
- }
- }
- char SpkerLvlProcess(char update)
- {
-
- short templv=0;
- static char LastTemplv=0;
- static unsigned char Lastnum=0;//0
- static short SpkCnt=0;
- unsigned char i=0;
- char buf[30];
- const unsigned short VolArr[VOL_LEV_NUM]={100,410,820,1230,1640,2050,2460,3000,3500,4090};//,4090}; //,200
-
- templv=GetPowerVbat();
-
- LastTemplv=Lastnum;
- for(i=0;i<VOL_LEV_NUM;i++)
- {
- if(LastTemplv==0){
- if(LastTemplv==0)if(templv>VolArr[LastTemplv]+VOL_LEV_DEF)LastTemplv++;
- }else if(LastTemplv<VOL_LEV_NUM-1){
- if(templv>=VolArr[LastTemplv]+VOL_LEV_DEF)LastTemplv++;
- else if(templv<VolArr[LastTemplv-1]-VOL_LEV_DEF)LastTemplv--;
- }else {
- if(LastTemplv==VOL_LEV_NUM-1)if(templv<VolArr[LastTemplv-1]-VOL_LEV_DEF)LastTemplv--;
- }
- }
- // printf("templv=%d----num===%d\r\n",templv,LastTemplv);
-
- if(update==1) return LastTemplv;
- if(LastTemplv!=Lastnum||update==2){
- if(LastTemplv!=0)SpeakerEnable();
- printf("templv=%d----num===%d\r\n",templv,LastTemplv);
- if(update==2){
-
- Lastnum=LastTemplv;
- newPara.VolumLv=LastTemplv;
- //FMSetVolume(Lastnum,1);
-
- }
- else{
- if(sutUIstatus.Status==UIS_STANDBY)
- {
-
- GuiClearRect(26,107,100,124);
- GuiShowBmp(60,110,"volume.bmp");
- snprintf(buf,sizeof(buf),"%02d",LastTemplv);
- GuiShowStr(78,110,buf,0x10,0);
- }
- Lastnum=LastTemplv;
- newPara.VolumLv=LastTemplv;
- }
- snprintf(buf,sizeof(buf),"音量 %d",Lastnum);
- printf(buf);
-
- //;
- if(sutPocStatus.HeadSetPtt==1){
- snprintf(buf,sizeof(buf),"AT+CLVL=%d\r\n",ERRSendAtLv[Lastnum]);//10
- }else if(hgs_poc_type==POC_OWN){
- snprintf(buf,sizeof(buf),"AT+CLVL=%d\r\n",HGSSendAtLv[Lastnum]);//10
- }else if(hgs_poc_type==POC_BND){
- snprintf(buf,sizeof(buf),"AT+CLVL=%d\r\n",BNDSendAtLv[Lastnum]);//10
- }
- ModemSendAt(buf);
-
-
- if(hgs_poc_type==POC_OWN){
-
- snprintf(buf,sizeof(buf),"AT+CRSL=%d\r\n",Lastnum*10);//10
- ModemSendAt(buf);
- }else {
- if(newPara.KeySound!=0){
- snprintf(buf,sizeof(buf),"AT+POC=tonevol=%d\r\n",Lastnum);
- ModemSendAt(buf);
- }
- snprintf(buf,sizeof(buf),"AT+POC=ttsvol=%d\r\n",(Lastnum));
- ModemSendAt(buf);
- }
- LCDBackLight(1);
- LcdOnTimeCt=0;
- SpkCnt=300;
-
- }
-
- if(SpkCnt>0){
- if((--SpkCnt==0)&&(sutUIstatus.Status==UIS_STANDBY)){
- GuiClearRect(26,107,100,124);
- if(g_uslockflag==1){
- GuiShowBmp(72,110,"lock.bmp");
- }
- if(sutPocStatus.Speaker==0&&sutPocStatus.TTS==0) SpeakerDisable();
-
- }
- }
-
- return LastTemplv;
-
- }
- void HeadsetProcess(void)
- {
- static signed char HeadsetStatue=0;
- static signed char HeadseLastStatue=0;
- if(INTERNAL_HEADSET==1) return;
-
- if(RESET==GPIO_ReadInputDataBit(HEADSET_PORT,HEADSET_PIN))HeadsetStatue=1;
- else HeadsetStatue=-1;
-
- if(HeadseLastStatue!=HeadsetStatue){
- if(HeadsetStatue==1){
- printf("耳机接入---\r\n");
- //ModemSendAt("AT+AUDCH=1,3\r\n");
- sutPocStatus.HeadSetPtt=1;
- }
- else {
- printf("耳机拔出---\r\n");
- ModemSendAt("AT+AUDCH=0,0\r\n");
- sutPocStatus.HeadSetPtt=0;
-
- }
- uTimerStart(&HeadSetChange,200);
- SpkerLvlProcess(2);
- HeadseLastStatue=HeadsetStatue;
- }
- /*为了规避耳机拔出问题*/
- if(HeadsetPress && sutPocStatus.HeadSetPtt){
-
- if(uTimerExpired(&HeadsetPullPress)){
-
- if(hgs_poc_type==POC_BND)ModemSendAt("AT+POC=ptt,1\r\n");
- else {
- ModemSendAt("AT+POC=0B0000\r\n");
- }
- HeadsetPress=0;
- }
-
- }
-
- }
- //开机后的一些控制
- void onStartCtl(void){
- Chargeing=GPIO_ReadInputDataBit(CHARGE_PORT,CHARGE_PIN);
- KeyCount();
- SwitchGroupCtrl();
- SwitchVoiceCtrl();
- if(newPara.lcdParaList[newPara.lcdParaDefaultIndex]>0){
- if(++LcdOnTimeCt>=newPara.lcdParaList[newPara.lcdParaDefaultIndex]){
- LcdOnTimeCt=0;
- if(sutPocStatus.FirstLogined==0){
- LCDBackLight(1);//没登陆过(刚开机),LCD一直亮着//0
- }else LCDBackLight(0);
- }
- }
- }
- void AtRequest()
- {
- static char step=0;
- switch(step)
- {
- case 0:
- break;
- }
- }
- void UiassistStart(unsigned char type){
- uiAssist.type=type;
- uiAssist.machine=0;
- uiAssist.status=1;
- }
- void UiassistEnd(unsigned char type){
- uiAssist.type=type;
- uiAssist.machine=0;
- uiAssist.status=0;
- assistResult=0;
- }
- unsigned char assistResult=0;
- unsigned char getAssistResult(void){
- unsigned char ret=0;
- ret=assistResult;
- if(assistResult) assistResult=0;
- return ret;
- }
- PT_THREAD (ptUIAssist(struct pt *pt)){
- static timer_t ptTimer;
- PT_BEGIN(pt);
- while(1){
- if(uiAssist.status!=0){
- switch(uiAssist.type){
- case 0: // //刚进入
- switch(uiAssist.machine){
- case 0:
- if(SimpleUserInfoScan(1, 2)){//操作完成了
- printf("获取成功了---\r\n");
- assistResult=1;
- uiAssist.status=0;
- }
- break;
- }
- break;
- case 1: //上翻
- switch(uiAssist.machine){
- case 0:
- if(SimpleUserInfoScan(0,0)){
- assistResult=1;
- uiAssist.status=0;
- }
- break;
- }
- break;
- case 2: //下翻
- switch(uiAssist.machine){
- case 0:
- if(SimpleUserInfoScan(0,1)){
- assistResult=1;
- uiAssist.status=0;
- }
- break;
- }
- break;
- }
- }
- PTTimerStart(&pt_timerPool, &ptTimer, 1);//1
- PT_WAIT_UNTIL(pt, PTTimerIsExpired(&ptTimer));
- }
- PT_END(pt);
- }
|