123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011 |
- #include "includes.h"
- #define APP_IDLE_TIME 3 //如果POC已休眠,APP没有操作一定秒数后休眠
- nwy_osiThread_t *mainThreadPtr=NULL;
- int keyNum=0;
- APP_DEF sutApp;
- static void appDataInit(void){
- memset((unsigned char *)&sutApp, 0, sizeof(APP_DEF));
- appSleepCtl(ASLEEP_POC, 1);
- appSleepCtl(ASLEEP_LCD, 1);
- readInfoNow();
- sysIniRead();
- }
- void dataInit(void){
- appDataInit();
- pocDataInit();
- gpsDataInit();
- uiDataInit();
- }
- static void ledsProCtl(void){
- if(sutApp.gtMode!=0) return;
- if(0==sutPocStatus.logined) uioStatusSet(UIO_INDOFFLINE);
- else if(sutPocStatus.spk>0)uioStatusSet(UIO_INDRX);
- else if(sutPocStatus.mic>0 )uioStatusSet(UIO_INDTX);
- else uioStatusSet(UIO_INDONLINE);
- }
- static void adcRead(void);
- char isKeyPress(void){
- if(keyNum) return keyNum--;
- else return 0;
- }
- static void subTimerCtl(unsigned char sleep_or_not);
- /*APP休眠处理接口
- ctlType, 操作对象
- status,操作值,0 清除 else 设置
- */
- void appSleepCtl(ASLEEP_ENUM ctlType, char status){
- if(status==0) sutApp.appSleepStatus &= ~(1<<ctlType);
- else sutApp.appSleepStatus |= 1<<ctlType;
- }
- /*APP休眠状态接口*/
- char isAppSleepReady(void){
- if(sutApp.appSleepStatus==0) return 1;
- else return 0;
- }
- /*获取指定休眠控制成员锁定的状态
- 0 未锁定 否则锁定,锁定即可以休眠
- */
- char getAppObjStatus(ASLEEP_ENUM ctlType){
- if(sutApp.appSleepStatus & (1<<ctlType)) return 1;
- else return 0;
- }
- /*检测是否APP可以休眠操作*/
- char isSleepReady(void){
- static unsigned int idleCnt=0;
- #ifdef DISABLE_SLEEP
- return 0;//不休眠
- #endif
- if(isAppSleepReady()==0){
- idleCnt=0;
- return 0;
- }
-
- if(++idleCnt>=(APP_IDLE_TIME*1000/APP_SUB_DIV_TIME)){
- idleCnt=0;
- return 1;
- }else return 0;
- }
- /*处理UI操作*/
- static void uiProcess(unsigned int exeInterval){
- if(getAppObjStatus(ASLEEP_PWR) != 0) return;//关机后,不切换菜单,只显示关机页面
- //if(sutApp.gtTMode!=0) return;//GT模式后按键无效
- uiLoop(exeInterval);
- uiResponse(exeInterval);
- }
- static void pwrKeyDetect(unsigned int exeInterval){
- static char pressed=0;
- static int kcnt=0,cnt=0;
- if(sutApp.pwrKeyStatus!=0){//按下了
- appSleepCtl(ASLEEP_PWRKEY, 1);
- if(pressed==0){
- kcnt=1;
- pressed=1;
- cnt=0;
- }
- if(++cnt>=(1000/exeInterval)){
- cnt=0;
- if(++kcnt>=3){
- backLightReset();
- if(sutApp.activePwrShut==0){
- sutApp.activePwrShut=1;
- uISetNextStatus(UIS_MENU_SHUT_UI);
- }
- }
- }
- }else{//放开了
- if(kcnt==1){//短按
- keyToneStart();
- switch(sutUIstatus.Status){
- case UIS_STANDBY:switchBackLight();break;//切换背光
- case UIS_MENU_TASK_SEL:taskSelBackToStandby(false);break;
- case UIS_MENU_TASK_QUERY:taskBackToStandby();break;
- case UIS_MENU_RANK_SEL:rankSelBackToStandby();break;
- case UIS_MENU_RANK_DETAIL:rankBackToStandby();break;
- case UIS_MENU_CLASS_SEL:
- case UIS_MENU_STUDENT_SEL:
- GUBackToStandby();break;
- case UIS_MENU_LOCATION_CLASS:classBackToStandby();break;
- case UIS_MENU_LOCATION_NOTICE:noticeBackToStandby();break;
- case UIS_MENU_LOCATION_NOTICE_DETAIL:noticeDetailBackToStandby();break;
- case UIS_MENU_SHUT_UI:break;
- default:uISetNextStatus(UIS_STANDBY);break;
- }
- }
- pressed=0;
- kcnt=0;
- if(sutApp.activePwrShut==0) appSleepCtl(ASLEEP_PWRKEY, 0);
- }
- }
- void shutSysNow(void){
- msgAtSend("AT+POC=050000\r\n");
- nwy_sleep(200);
- msgAtSend("AT+CPOF\r\n");
- nwy_sleep(200);
- }
- static void antModePwrDet(void){
- static int kcnt=0;
- if(sutApp.pwrKeyStatus!=0){
- if(++kcnt==3){
- guiShowMessageBox("正在关机");
- CTL_LCD_BL(0);
- CTL_POWER_HOLD(0);
- shutSysNow();
- }
- }else kcnt=0;
- }
- void uiShowShutOption(char update){
- if(update){
- guiClearAll(guiGetBackColor());
- guiShowCaption(0,"关机",UI_STATUS_ITEM_Y+1,guiGetBackColor(),guiGetForeColor(),FONT_MODE_12X12);
- guiShowMessageBox("确定关机?");
- uiMenuShowBottomLine();
- uiMenuShowBottomIndacitor("确定", "取消");
- return;
- }
- }
- void uiShowShutOptionResponse(void){
- switch(getKeyValue()){
- case MKEY_VALUE_MENU:
- appSleepCtl(ASLEEP_PWR, 1);
- uISetNextStatus(UIS_STANDBY);
- break;
- case MKEY_VALUE_ESC:
- sutApp.activePwrShut=0;
- uISetNextStatus(UIS_STANDBY);
- break;
- }
- }
- /*触发关机操作*/
- static void pwrShutPro(unsigned int exeInterval){
- static char shutFlag=0;
- pwrKeyDetect(exeInterval);
- if(getAppObjStatus(ASLEEP_PWR) == 0) return;
- CTL_LCD_BL(1);
- msgAtSend("AT+POC=050000\r\n");
- msgAtSend("AT+CFUN=0\r\n");
- if(shutFlag==0){
- //显示关机界面
- if(sutApp.lowPwrMsg==0) guiShowMessageBox("正在关机");
- else guiShowMessageBox("低压关机");
- shutFlag=1;
- nwy_sleep(1000);
- }
- MSG_INFO(1, "Normal PwrOff");
- //msgAtSend("AT+TRB=1\r\n");//normal power off 当前固件先不发模块关机指令,否则断电再上电有可能是起不来的
- nwy_sleep(1000);//一秒后释放电源锁,防止软关机不成功
- CTL_LCD_BL(0);
- MSG_INFO(1, "Release pwr");
- guiFillRect(0,0,GLCD_WIDTH-1,GLCD_HEIGHT-1,guiGetBackColor());//防止下次开机能看到残留
- CTL_POWER_HOLD(0);
- shutSysNow();
- }
- void AntModeRun(void){
- #ifdef ENABLE_ANT_MODE
- guiShowMessageBox("调天线模式");
- for(;;){
- nwy_sleep(2000);
- }
- #endif
- }
- void lcdReConfig(void){
- if(sutApp.lcdReconfigCnt<=3) sutApp.lcdReconfigCnt++;
- if(sutApp.lcdReconfigCnt==3) recoverLightColor();
- }
- static void paProCtl(void);
- /*主要应用程序入口*/
- void appRun(void){
- char cnt=0;
- nwy_osiEvent_t event = {};
- //等待lcd初始化完成
- MSG_INFO(1, "wait lcd init");
- while(sutApp.guiStatus==0){nwy_sleep(50);}//是否检测超时?
- AntModeRun();
- localAuthNow();
- //等待poc启动完成
- MSG_INFO(1, "lcd init done, wait poc start");
- while(sutApp.pocInitStatus==0){
- msgAtSend("AT\r\n");
- nwy_sleep(50);
- }//是否检测超时?
- MSG_INFO(1, "app loop start");
- //设置EQ数据
- modifyEqData();
- //修改音频输出增益配置
- modifyAudioOutGainConfig();
- //设置一下TTS
- msgAtSend("AT+HTTSSPEED=1284,-20000\r\n");//设置TTS音量
- msgAtSend("AT+HTTSSPEED=1282,-5000\r\n");//设置TTS语速
- #if 0
- msgAtSend("AT+HTTSSPEED=0,-30000\r\n");//设置TTS音量
- msgAtSend("AT+HTTSSPEED=1,-5000\r\n");//设置TTS语速
- msgAtSend("AT+HTTSSPEED=4,2\r\n");
- msgAtSend("AT+HTTSSPEED=18, 2\r\n");
- #endif
- msgAtSend("AT+NICEUSE=0\r\n");//不需要快速体验(收话过程抢麦不会跳动话权显示)
- //查询一下POC版本号
- msgAtSend("AT+POC_VER\r\n");
- msgAtSend("AT+GMR\r\n");//查询模块版本
- msgAtSend("AT+MIC=6\r\n");
- #ifdef ENABLE_PTT_VOICE
- msgAtSend("AT+VSW=1\r\n");//打开留音功能
- #endif
- //msgAtSend("AT+CACCP=0,1,0,\"04000B00\"\r\n");
- #ifndef ENABLE_PWM_BEEP
- if(newPara.KeySound!=0) msgAtSend("AT+TONES=1\r\n");
- #endif
- splVolumeSet(newPara.spkVol*10);
- backLightReset();
- if(newPara.ttsMessage[0]!=0){
- if(newPara.ttsCodeType==0) ttsPlay(ENCODE_USER_UNICODE_BE, newPara.ttsMessage);
- else if(newPara.ttsCodeType==1) ttsPlay(ENCODE_USER_GBK, newPara.ttsMessage);
- else MSG_INFO(1, "ttsCodeType:%d not support", newPara.ttsCodeType);
- }else MSG_INFO(1, "tts null");
- //检测卡是否存在
- while(sutApp.cardStatus==0){
- msgAtSend("AT+CPIN?\r\n");
- nwy_sleep(1000);
- if(++cnt>=5){
- MSG_INFO(1, "Check card timeout");
- break;
- }
- }
- for(;;){
- if(sutApp.antMode){
- msgAtSend("AT+POC=050000\r\n");
- cnt=0;
- break;
- }
- lcdReConfig();
- ledsProCtl();
- adcRead();
- uiProcess(APP_SUB_DIV_TIME);
- gpsProCtl(APP_SUB_DIV_TIME);
- pocProCtl(APP_SUB_DIV_TIME);
- HookGroupUserInfo();
- HookVolToutCheck();
- LearnUsrInfoCheck(APP_SUB_DIV_TIME);
- IncomingSMS();
- if(isSleepReady()==0) nwy_sleep(APP_TASK_SLEEP_TIME);
- else if(sutApp.gtMode==0){//正常模式下可以休眠
- MSG_WARN(1, "APP SLEEP");
- stopKeyTimer();
- subTimerCtl(1);//切换为休眠状态定时器
- sutApp.appStatus=1;
- CTL_LED2_GREEN(0);
- CTL_LED1_RED(0);
- #ifdef ENABLE_DEEP_SLEEP
- pwmDeInitToSleep();
- lcdDrvPowerCtl(false);
- nwy_pm_state_set(NWY_ENTRY_SLEEP);
- #endif
- nwy_wait_thead_event(nwy_get_current_thread(), &event,0);
-
- lcdDrv_Init(1);//深度休眠唤醒后重新初始化SPI-LCD
-
- sutApp.appStatus=0;
- subTimerCtl(0);//切换为唤醒状态定时器
- MSG_WARN(1, "APP WAKEUP");
- }
- //检测是否关机,这里要放在唤醒后操作
- pwrShutPro(APP_SUB_DIV_TIME);
- }
- //检测是否关机了
- for(;;){
- antModePwrDet();
- nwy_sleep(900);
- }
- }
- //////////////////////////////////////用于处理非耗时操作,如LED///////////////////////
- nwy_osiTimer_t *pSubtimer_t = NULL;
- unsigned int subTimerInterval=100;//定时器定时的时间
- static void subTimeroutcallback(void *param){
- unsigned int *dlyTime=(unsigned int *)param;
- //处理灯的显示
- uioProctl(*dlyTime);
- //控制功放的关闭
- paProCtl();
- }
- /*创建定时器*/
- void subTask(void *param){
- nwy_osiEvent_t event = {};
- if(NULL == pSubtimer_t) pSubtimer_t = nwy_timer_init(nwy_get_current_thread(), subTimeroutcallback, (void *)&subTimerInterval);
- if(NULL == pSubtimer_t) MSG_WARN(1,"sub timer init failed");
- else nwy_start_timer_periodic(pSubtimer_t,subTimerInterval);
- for(;;){nwy_wait_thead_event(nwy_get_current_thread(), &event,0);}
- }
- /*
- 为了做低功耗,此定时器在休眠时,设置为长时间定时
- 非休眠时,设置为短时间定时
- sleep_or_not:0 未休眠, else 休眠
- */
- static void subTimerCtl(unsigned char sleep_or_not){
- if(NULL==pSubtimer_t){
- MSG_WARN(1, "subTimer null");
- return;
- }
- nwy_stop_timer(pSubtimer_t);
- //打开定时器
- if(sleep_or_not==0) subTimerInterval=100;//未休眠时,100ms
- else subTimerInterval=5000;//休眠时 5000ms
- nwy_start_timer_periodic(pSubtimer_t,subTimerInterval);
- }
- //////////////////////////////////////////////////////////////////////////////////////
- void usbCmdHandler(const char *data,uint32 length){
- static char buf[256];
- static int len=0;
- static char lach;
- char ch;
- int i;
- if(sutApp.authReady==0){
- authRecvPro(data, length);
- return;
- }
-
- for(i=0;i<length;i++){
- ch=data[i];
- if(len<sizeof(buf)-1) buf[len++]=ch;
- else{
- MSG_WARN(1, "USB Buf Over");
- len=0;
- buf[len++]=ch;
- }
- if(lach=='\r' && ch=='\n'){
- buf[len]=0;
- cmdSetting(buf);
- len=0;
- }
- lach=ch;
- }
- }
- //////////////////////////////按键处理接口//////////////////////////
- //普通按键处理
- unsigned char singleKeyInArow=0;
- void keyCheck(unsigned short keyStatus){//定时被调用
- static unsigned short lkey=0;
- static unsigned char keyCtl=0,keyCnt=0;
- unsigned char keyType,needSendKey=0;
- if(keyStatus==KS_ALL_IDLE){
- keyType=0;
- if(keyCtl==1){
- keyCtl=0;
- needSendKey=1;
- }
- }else{
- keyType=1;
- if(lkey != keyStatus) keyCtl=0;//值变化
- if(keyCtl==0){
- lkey=keyStatus;
- keyCtl=1;
- keyCnt=0;
- needSendKey=1;
- }else if(singleKeyInArow!=0){//是否输出持续值
- if(++keyCnt>=(1000/KEY_TIMER_TICK)){//每秒产生持续值
- keyCnt=0;
- needSendKey=1;
- }
- }
- }
- if(needSendKey){
- if(sutApp.enableKey!=0)//延时期间不检测按键
- threadSendEvent(nwy_get_current_thread(),OHPOC_EVENT_KEY_NOR, lkey,keyType,NULL);
- }
- }
- static char micPttPressed=0;
- static char pttPressed=0;
- static void pttHandler(char type, char ctl){
- char needSend=0;
- char mic_spk;
- if(type==0){//ptt
- if(ctl==0){//放开
- if(micPttPressed==0){
- needSend=1;mic_spk=0;
- }
- pttPressed=0;
- }else{//按下
- if(pttPressed==0 && micPttPressed==0){
- needSend=1;mic_spk=1;
- }
- pttPressed=1;
- }
- }else{//mic ptt
- if(ctl==0){//放开
- if(pttPressed==0){
- needSend=1;mic_spk=0;
- }
- micPttPressed=0;
- }else{//按下
- if(pttPressed==0 && micPttPressed==0){
- needSend=1;mic_spk=1;
- }
- micPttPressed=1;
- }
- }
- if(isLearnBusy()==true){
- MSG_WARN(1, "Learn task is busy, skip ptt");
- return;//学习任务正在使用音频,POC不录音
- }
- if(needSend!=0){
- if(mic_spk==0) msgAtSend("AT+POC=0C0000\r\n");
- else msgAtSend("AT+POC=0B0000\r\n");
- }
- }
- /*打印键信息*/
- const char freeSeg[]="Free";
- const char pressSeg[]="Press";
- void showKeyMessage(unsigned short key,unsigned char status){
- char buf[50]="[Key_";
- switch(key){
- case KV_KEY_MIC_PTT: strcat(buf, "MIC_PTT]");break;
- default:return;
- }
- if(status==0) strcat(buf, freeSeg);
- else strcat(buf, pressSeg);
- MSG_INFO(1,buf);
- }
- void keyHandler(unsigned short key,unsigned char status){//普通按键值处理
- tryWakeupApp();//有普通键按下或放开,唤醒休眠的系统
- showKeyMessage(key,status);
- if(status==0){//key free
- switch(key){
- case KV_KEY_MIC_PTT:
- pttHandler(1,0);
- break;
- default:
- break;
- }
- singleKeyInArow=0;
- appSleepCtl(ASLEEP_KEY, 0);
- }else{//key press
- appSleepCtl(ASLEEP_KEY, 1);
- backLightReset();
- if(sutApp.keyLock!=0){
- sutApp.lockShow=1;
- return;
- }
- switch(key){
- case KV_KEY_MIC_PTT:
- singleKeyInArow=1;
- pttHandler(1,1);
- break;
- default:
- break;
- }
- }
- }
- //扫描矩阵按键
- #define MATRIX_KEY_NUMS 2 //最多检测同时两个组合键
- void keyStatusCtlAll(char high_low){
- CTL_KEY_OUT1(high_low);
- CTL_KEY_OUT2(high_low);
- CTL_KEY_OUT3(high_low);
- }
- void keyStatusCtlOne(char outIndex){
- switch(outIndex){
- case 0:CTL_KEY_OUT1(0);
- CTL_KEY_OUT2(1);
- CTL_KEY_OUT3(1);
- break;
- case 1:CTL_KEY_OUT2(0);
- CTL_KEY_OUT1(1);
- CTL_KEY_OUT3(1);
- break;
- case 2:CTL_KEY_OUT3(0);
- CTL_KEY_OUT2(1);
- CTL_KEY_OUT1(1);
- break;
- }
- }
- int keyStatusGetOne(char outIndex){
- int ret=2;
- switch(outIndex){
- case 0:ret=INT_KEY_IN1();break;
- case 1:ret=INT_KEY_IN2();break;
- case 2:ret=INT_KEY_IN3();break;
- }
- return ret;
- }
- unsigned short matrixGetKey(unsigned char out, unsigned char in){
- unsigned short vlaue=0;
-
- if(out >= MKS_KEY_OUS || in >=MKS_KEY_INS) return 0xffff;
- switch(in){
- case 0:
- switch(out){
- case 0:vlaue |= (1<<MKEY_VALUE_1);break;
- case 1:vlaue |= (1<<MKEY_VALUE_2);break;
- case 2:vlaue |= (1<<MKEY_VALUE_3);break;
- default:vlaue=0xffff;break;
- }
- break;
- case 1:
- switch(out){
- case 0:vlaue |= (1<<MKEY_VALUE_4);break;
- case 1:vlaue |= (1<<MKEY_VALUE_5);break;
- case 2:vlaue |= (1<<MKEY_VALUE_6);break;
- default:vlaue=0xffff;break;
- }
- break;
- case 2:
- switch(out){
- case 0:vlaue |= (1<<MKEY_VALUE_7);break;
- case 1:vlaue |= (1<<MKEY_VALUE_8);break;
- case 2:vlaue |= (1<<MKEY_VALUE_9);break;
- default:vlaue=0xffff;break;
- }
- break;
- default:vlaue=0xffff;break;
- }
- return vlaue;
- }
- /*进入GT模式*/
- static void enterGTMode(void){
- if(sutApp.gtMode!=0) return;
- #ifndef ENABLE_PWM_BEEP
- msgAtSend("AT+TONES=1\r\n");
- #endif
- sutApp.gtMode=1;
- uioStatusSet(UIO_INDGT);
- paControl(true);//GT下常开喇叭
- #ifdef ENABLE_PWM_BEEP
- beepStart(TONE_SPECIAL);
- nwy_sleep(50);
- beepStart(TONE_NORMAL);
- nwy_sleep(50);
- beepStart(TONE_SPECIAL);
- #else
- msgAtSend("AT+TONE\r\n");
- nwy_sleep(200);
- msgAtSend("AT+TONE\r\n");
- #endif
- MSG_WARN(1, "Enter GT Mode");
- guiShowMessageBox("GT模式");
- }
- static unsigned short g_usKeyValue=0;
- unsigned short getKeyValue(void){return g_usKeyValue;}
- unsigned char keyInArow=0;//键值是否持续产生
- void mKeyCheck(void){//定时被调用
- unsigned char matrix[MATRIX_KEY_NUMS][2],num;
- unsigned char in,out,i,j,update;
- int value;
- unsigned short keys[MATRIX_KEY_NUMS];
- static unsigned short finalKey=0;
- unsigned short tKey;
- static unsigned char keyCtl=0;
- static unsigned char keyCnt=0;
- unsigned char needSendKey=0;
- for(i=0;i<MATRIX_KEY_NUMS;i++){
- for(j=0;j<2;j++) matrix[i][j]=0xff;
- }
- num=0;
- for(out=0;out<MKS_KEY_OUS;out++){
- keyStatusCtlOne(out);
- for(in=0;in<MKS_KEY_INS;in++){
- if(keyStatusGetOne(in)==0){
- matrix[num][0]=out;
- matrix[num][1]=in;
- if(++num>=MATRIX_KEY_NUMS) goto MATRIX_END;
- }
- }
- }
- MATRIX_END:
- keyStatusCtlAll(0);
- if(num==0){//无键按下
- goto MKEY_NO_KEY;
- }
- for(int w=0;w<num;w++)
- //检测值
- for(i=0;i<MATRIX_KEY_NUMS;i++) keys[i]=matrixGetKey(matrix[i][0],matrix[i][1]);
-
- tKey=0;
- for(i=0;i<MATRIX_KEY_NUMS;i++){
- if(keys[i]!=0xffff) tKey |= keys[i];
- }
- needSendKey=0;
- //得出键值
- if(tKey==MKEY_VALUE_IDLE){//无键按键
- MKEY_NO_KEY:
- if(keyCtl==1){
- keyCtl=0;
- needSendKey=1;
- }
- }else{//有键按下
- if(tKey != g_usKeyValue) keyCtl=0;//值变化
- if(keyCtl==0){
- g_usKeyValue=tKey;
- keyCtl=1;
- keyCnt=0;
- needSendKey=1;
- }else if(keyInArow!=0){//是否输出持续值
- if(++keyCnt>=(1000/KEY_TIMER_TICK)){//每秒产生持续值
- keyCnt=0;
- needSendKey=1;
- }
- }
- }
- if(needSendKey){
- if(sutApp.enableKey!=0)
- threadSendEvent(nwy_get_current_thread(),OHPOC_EVENT_KEY_MAT, keyCtl,NULL,NULL);
- }
- }
- void showKeyMsg(char *info, unsigned char keyCtl){
- char buf[40];
- char *ctl;
- if(keyCtl==0) ctl=freeSeg;
- else ctl=pressSeg;
- snprintf(buf, sizeof(buf),"[Key %s]%s",ctl,info);
- MSG_INFO(1, buf);
- }
- static void lockProcess(void){
- if(sutApp.keyLock==0){
- if(sutApp.activePwrShut!=0) return;//触发了关机界面时,不能加锁键盘
- sutApp.keyLock=1;
- appSleepCtl(ASLEEP_GGROUP, 0);
- appSleepCtl(ASLEEP_GUSER, 0);
- if(sutUIstatus.Status==UIS_STANDBY) guiShowBmp(72,110, "lock.bmp");//锁关/锁开触发时更新状态
- uISetNextStatus(UIS_STANDBY);
- }else{
- sutApp.keyLock=0;
- sutApp.lockShow=0;
- if(sutUIstatus.Status==UIS_STANDBY) guiClearRect(72,110,72+17,110+17,guiGetBackColor());//锁关/锁开触发时更新状态
- }
- }
- void keyToneStart(void){
- if(newPara.KeySound==0) return;
- #ifdef ENABLE_PWM_BEEP
- beepStart(TONE_NORMAL);
- #else
- msgAtSend("AT+TONE\r\n");
- #endif
- }
- void quickUiSwitch(int uistatus){
- if(sutApp.activePwrShut!=0) return;//触发了关机界面时,快捷键无效
- if(sutApp.keyLock!=0) return;//锁了后,快捷键无效
- if(true==isUiSwitchReady()) return;
- uISetNextStatus(uistatus);
- getStackStruct()->FastUiChange=1;
- }
- void mKeyHandler(unsigned char keyCtl){
- static unsigned char gtModeCnt=0;
- static unsigned char lockCnt=0;
- static unsigned char f1Cnt=0;
- static unsigned char f2Cnt=0;
- char lock_but_enable_key=0;//锁键盘后,也能够关机
- if(sutUIstatus.Status==UIS_MENU_SHUT_UI &&
- (MKEY_VALUE_MENU==g_usKeyValue || MKEY_VALUE_ESC==g_usKeyValue)) lock_but_enable_key=1;
- if(sutApp.keyLock!=0 && MKEY_VALUE_PTT!=g_usKeyValue && MKEY_VALUE_P1!=g_usKeyValue && lock_but_enable_key==0){
- sutApp.lockShow=1;
- return;
- }
- if(keyCtl==0){//释放
- switch(g_usKeyValue){
- case MKEY_VALUE_PTT:showKeyMsg("PTT",keyCtl);
- pttHandler(0,0);
- break;
- case MKEY_VALUE_P1:showKeyMsg("P1",keyCtl);
- if(lockCnt==1){
- switch(sutUIstatus.Status){
- case UIS_MENU_TASK_SEL:
- case UIS_MENU_RANK_SEL:
- case UIS_MENU_TASK_QUERY:
- case UIS_MENU_RANK_DETAIL:
- case UIS_MENU_LOCATION_CLASS:
- case UIS_MENU_LOCATION_NOTICE:
- case UIS_MENU_LOCATION_NOTICE_DETAIL:
- break;
- default:quickUiSwitch(UIS_MENU_TASK_SEL);
- }
- }
- lockCnt=0;
- break;
- case MKEY_VALUE_P2:showKeyMsg("P2",keyCtl);
- break;
- case MKEY_VALUE_MENU:showKeyMsg("MENU",keyCtl);
- break;
- case MKEY_VALUE_ESC:showKeyMsg("ESC",keyCtl);
- break;
- case MKEY_VALUE_UP:showKeyMsg("UP",keyCtl);
- break;
- case MKEY_VALUE_DOWN:showKeyMsg("DOWN",keyCtl);
- break;
- case MKEY_VALUE_F1:showKeyMsg("F1",keyCtl);
- if(f1Cnt==1) volAdjAction(0);
- f1Cnt=0;
- break;
- case MKEY_VALUE_F2:showKeyMsg("F2",keyCtl);
- if(f2Cnt==1) volAdjAction(1);
- f2Cnt=0;
- break;
- case MKEY_VALUE_CB_GT:showKeyMsg("CB_GT",keyCtl);
- gtModeCnt=0;
- break;
- case MKEY_VALUE_CB_IP:showKeyMsg("CB_IP",keyCtl);
- break;
- default:MSG_WARN(1,"UnHande Key:%d Free",g_usKeyValue);
- break;
- }
- keyInArow=0;
- appSleepCtl(ASLEEP_MKEY, 0);
- }else{//按下
- if(g_usKeyValue!=MKEY_VALUE_PTT && g_usKeyValue!=MKEY_VALUE_CB_GT) keyToneStart();
- backLightReset();
- appSleepCtl(ASLEEP_MKEY, 1);
- keyNum++;
- switch(g_usKeyValue){
- case MKEY_VALUE_PTT:showKeyMsg("PTT",keyCtl);
- pttHandler(0,1);
- break;
- case MKEY_VALUE_P1:showKeyMsg("P1",keyCtl);
- keyInArow=1;
- if(++lockCnt==3) lockProcess();
- break;
- case MKEY_VALUE_P2:showKeyMsg("P2",keyCtl);
- break;
- case MKEY_VALUE_MENU:showKeyMsg("MENU",keyCtl);
- break;
- case MKEY_VALUE_ESC:showKeyMsg("ESC",keyCtl);
- break;
- case MKEY_VALUE_UP:showKeyMsg("UP",keyCtl);
- break;
- case MKEY_VALUE_DOWN:showKeyMsg("DOWN",keyCtl);
- break;
- case MKEY_VALUE_F1:showKeyMsg("F1",keyCtl);
- keyInArow=1;
- if(++f1Cnt==3) quickUiSwitch(UIS_MENU_CLASS_SEL);
- break;
- case MKEY_VALUE_F2:showKeyMsg("F2",keyCtl);
- keyInArow=1;
- if(++f2Cnt==3) quickUiSwitch(UIS_MENU_STUDENT_SEL);
- break;
- case MKEY_VALUE_CB_GT:showKeyMsg("CB_GT",keyCtl);
- keyInArow=1;
- if(++gtModeCnt==3){
- if(sutApp.gtMode==0){
- enterGTMode();
- }
- }
- break;
- case MKEY_VALUE_CB_IP:
- keyInArow=1;
- showKeyMsg("CB_IP",keyCtl);
- break;
- default:MSG_WARN(1,"UnHande Key:%d Press",g_usKeyValue);
- break;
- }
- }
- }
- //////////////////////////////按键处理结束//////////////////////////
- //////////////////////////////其它处理接口//////////////////////////
- void hpDetStatusChanged(unsigned char hpStatus){
- if(0==hpStatus){
- MSG_WARN(1,"HP plug in");
- }else{
- MSG_WARN(1,"HP plug out");
- }
- }
- //测试主板ADC为:150~1190范围
- //实际使用ADC取:170~1210范围
- /*输入adc值,输出音量等级*/
- #define VOL_LEV_NUM 11 //档位数
- #define VOL_LEV_DEF 10 //抖动上下限
- unsigned char wisdomAdcProcess(int adcValueTmp){
- const unsigned short volAdcTable[VOL_LEV_NUM]={170,200,240,300,400,500,700,900,1100,1140,1170};//中间ADC变化快,两端ADC变化慢
- int i;
- static unsigned char ucVolLev=0;
- for(i=0;i<VOL_LEV_NUM;i++){
- if(ucVolLev==0){
- if(adcValueTmp >= volAdcTable[ucVolLev]+VOL_LEV_DEF) ucVolLev++;
- }else if(ucVolLev<VOL_LEV_NUM-1){
- if(adcValueTmp >= volAdcTable[ucVolLev]+VOL_LEV_DEF) ucVolLev++;
- else if(adcValueTmp < volAdcTable[ucVolLev-1]-VOL_LEV_DEF) ucVolLev--;
- }else{
- if(ucVolLev==VOL_LEV_NUM-1) if(adcValueTmp < volAdcTable[ucVolLev-1]-VOL_LEV_DEF) ucVolLev--;
- }
- }
- return ucVolLev;
- }
- static void adcRead(void){
- #define VBAT_READ_TIME 20
- int adcValueTmp;
- static int siVbat=0;
- static int laSiVbat;
- static unsigned char index=0,lcnt=0;
- int x=(GLCD_WIDTH-16)/2;
- int y=GLCD_HEIGHT-12;
- #if 0//原来是ADC检测耳机接入与否,现在用来检测电压
- //检测音量旋钮电压
- adcValueTmp=nwy_adc_get(NWY_ADC_CHANNEL3, NWY_ADC_SCALE_1V250);
- if(adcValueTmp>0){//15 1227
- if(sutUIstatus.Status==UIS_STANDBY){
- if(adcValueTmp > 1000){
- if(sutApp.earStatus==0){
- sutApp.pcant=2;//FM
- sutApp.earStatus=1;
- MSG_INFO(1, "FM MODE");
- guiShowBmp(x, y, "ear.bmp");
- }
- }else{
- if(sutApp.earStatus!=0){
- sutApp.pcant=4;//mianti
- sutApp.earStatus=0;
- MSG_INFO(1, "MIANTI MODE");
- guiClearRect(x, y, x+16,y+12, guiGetBackColor());
- }
- }
- }else if(sutApp.earStatus != 0) sutApp.earStatus=0;//切到其它菜单后再切回来还能显示
- }
- #endif
- //检测电池电压
- //adcValueTmp=nwy_adc_get(NWY_ADC_CHANNEL4, NWY_ADC_SCALE_5V000);
- adcValueTmp=nwy_adc_get(NWY_ADC_CHANNEL3, NWY_ADC_SCALE_1V250);
- siVbat += adcValueTmp;
- if(++index>=VBAT_READ_TIME){
- siVbat=siVbat / VBAT_READ_TIME / 10;
- sutApp.g_iBAT = siVbat*147/47;
- if(laSiVbat!=sutApp.g_iBAT){
- //MSG_INFO(1, "bat:%d", sutApp.g_iBAT);
- laSiVbat=sutApp.g_iBAT;
- if(sutApp.g_iBAT<=MIN_PWR_LEVEL){
- MSG_WARN(1,"Low power:%d", lcnt++);
- if(lcnt>=10){
- MSG_INFO(1, "Low power ,shut");
- sutApp.lowPwrMsg=1;
- appSleepCtl(ASLEEP_PWR, 1);
- }
- }else lcnt=0;
- }
- siVbat=0;
- index=0;
- }
- }
- void tryWakeupApp(void){
- if(sutApp.appStatus!=0){
- sutApp.appStatus=0;
- if(mainThreadPtr!=NULL){
- sutApp.lcdReconfigCnt=0;
- #ifdef ENABLE_DEEP_SLEEP
- nwy_pm_state_set(NWY_WAKEUP);
- #endif
- threadSendEvent(mainThreadPtr,OHPOC_EVENT_MAIN,NULL,NULL,NULL);
- }
- }
- }
- bool backlightstatus=true;
- /*背光时间到,熄灭*/
- void backLightCb(void *param){
- if(sutApp.gtMode!=0){
- CTL_LCD_BL(1);backlightstatus=true;
- return;
- }
- if(sutPocStatus.firstLogin==0) return;//未登录过,不灭屏
- if(newPara.lcdParaList[newPara.lcdParaDefaultIndex]==0) return;//常亮
- CTL_LCD_BL(0);backlightstatus=false;
- appSleepCtl(ASLEEP_LCD, 0);//可以休眠
- }
- /*点亮背光*/
- void backLightReset(void){
- unsigned short tmp;
- appSleepCtl(ASLEEP_LCD, 1);//不让休眠
- tmp=newPara.lcdParaList[newPara.lcdParaDefaultIndex];
- CTL_LCD_BL(1);backlightstatus=true;
- startBackLightTimer(tmp*1000);
- }
- void switchBackLight(void){
- if(backlightstatus==true){
- if(newPara.lcdParaList[newPara.lcdParaDefaultIndex]==0) return;//常亮
- CTL_LCD_BL(0);backlightstatus=false;
- appSleepCtl(ASLEEP_LCD, 0);//可以休眠
- }else backLightReset();
- }
- void sysPwrLock(void){
- sutApp.pwrLock=1;
- }
- void sysPwrRlease(void){
- sutApp.pwrLock=0;
- }
- //"3132" --> 0x31,0x32
- void StrAsciiToHex(char *src, unsigned char *des){
- unsigned char temp[2],i;
- if(strlen(src)%2) return;
- while(0!=*src)
- {
- for(i=0;i<2;i++)
- {
- temp[i] = *src++;
- if(temp[i] >= '0' && temp[i] <= '9') temp[i] -= 0x30;
- else if(temp[i] >= 'A' && temp[i] <= 'F') temp[i] -= 0x37;
- else temp[i] -= 0x57;
- }
- temp[0] <<= 4;
- temp[0] &= 0xf0;
- *des++=temp[0]|temp[1];
- }
- *des=0;
- }
- /*调节音量,刷新音量进度条*/
- void volAdjAction(char direction){
- if(direction==0){
- if(newPara.spkVol<10) newPara.spkVol++;
- else goto FLASH;
- }else{
- if(newPara.spkVol>0) newPara.spkVol--;
- else goto FLASH;
- }
- splVolumeSet(newPara.spkVol*10);
- MSG_INFO(1,"SPK_VOL:%d",newPara.spkVol*10);
- sysIniSave();
- //刷新进度条
- FLASH:
- volUiFlash(newPara.spkVol);
- }
- //////////////////////////////其它处理结束//////////////////////////
- /////////////////////////////事件发送接口///////////////////////////
- void threadSendEvent(nwy_osiThread_t *threadID, uint32 id, uint32 param1,uint32 param2,uint32 param3){
- nwy_osiEvent_t pEventSend;
- pEventSend.id=id;
- pEventSend.param1=param1;
- pEventSend.param2=param2;
- pEventSend.param3=param3;
- nwy_send_thead_event(threadID, &pEventSend,0);
- }
- void ttsPlay(ENCODE_USER_ENUM type, char *tts){
- char buf[20];
- if(sutApp.skipTTS!=0){
- MSG_WARN(1, "TTS is disable by learning task");
- return;
- }
- MSG_INFO(1, "tts Play:%s",tts);
- paControl(true);
- snprintf(buf, sizeof(buf), "AT+HTTS=%d,\"", type);
- msgAtSend(buf);
- msgAtSend(tts);
- msgAtSend("\"\r\n");
- sutPocStatus.TTS=1;
- }
- static void paProCtl(void){
- //会被定时调用
- if(sutPocStatus.TTS!=0) return;
- if(sutPocStatus.spk!=0) return;
- if(sutPocStatus.TONE!=0) return;
- if(sutPocStatus.beep!=0) return;
- if(sutApp.gtMode!=0) return;
- paControl(false);
- //MSG_INFO(1,"spk off");
- }
- void splVolumeSet(unsigned char level){
- char info[30];
- snprintf(info, sizeof(info), "AT+SPK=%d\r\n", level);
- msgAtSend(info);
- }
- /////////////////////////////事件发送结束///////////////////////////
|