//����ȫ���¼����κ�ҳ���£����ᴥ���¼��Ĵ�����SysEventHandler //����Sys_PreGotoPage������ void Q_EnableGobalPeripEvent(PERIP_EVT PeripEvt,PeripheralsHandlerFunc PeripEvtHandler) { u8 i; if(PeripEvtHandler==NULL) return; //���Ƿ����ظ���¼ for(i=0;i<MAX_GOBAL_SYSEVT;i++) { if((gGobalPeripEvtRecord[i].PeripEvt==PeripEvt)&&(gGobalPeripEvtRecord[i].GobalPeripEvtHandler==PeripEvtHandler)) return; } //�ҿ�λ�� for(i=0;i<MAX_GOBAL_SYSEVT;i++) { if(gGobalPeripEvtRecord[i].PeripEvt==0)break; } if(i==MAX_GOBAL_SYSEVT) { Q_ErrorStopScreen("MAX_GOBAL_SYSEVT is small!!! pls reset it!"); } gGobalPeripEvtRecord[i].PeripEvt=PeripEvt; gGobalPeripEvtRecord[i].GobalPeripEvtHandler=PeripEvtHandler; SetBit(gGobalPeripEvtBitFlag,PeripEvt); }
//系统全局数据初始化 static void QSYS_DataInit(void) { u16 i; MemSet(PageTracks,0,MAX_PAGE_TRACK_NUM);//清空页面跳转痕迹 gCurTrackIdx=0; MemSet(PageLayers,0,MAX_PAGE_LAYER_NUM+1);//清空页面层级记录 gCurLayerNum=0; MemSet(gEntriesOfPage,0,PAGE_TOTAL);//清空页面进入次数记录 //复制所有页面的事件掩码到记录 for(i=0;i<PAGE_TOTAL;i++) { gPagePeripEvtFlag[i]=AllPage[i].pPage->PeripEvtInitMask; //顺便检查页面合法性 if((AllPage[i].pPage->SysEvtHandler==NULL)||(AllPage[i].pPage->ButtonHandler==NULL) ||(AllPage[i].pPage->PeripEvtHandler==NULL)) Q_ErrorStopScreen("Page SysEvtHandler & TchEvtHandler no allow be NULL!"); } MemSet(gGobalPeripEvtRecord,0,MAX_GOBAL_SYSEVT*sizeof(GOBAL_PERIPEVT_RECORD));//清空全局事件记录 gGobalPeripEvtBitFlag=0; ControlObjInit(); }
//得到指定层的页面索引 //LayerNum=1,得到顶层 //LayerNum=2,得到第二层 u8 GetPageIdxByLayer(u8 LayerNum) { if(LayerNum>MAX_PAGE_LAYER_NUM) { Debug("GetPageIdxByLayer error! LayerNum=%d\n\r",LayerNum); Q_ErrorStopScreen("GetPageIdxByLayer error! "); } return gPageLayers[LayerNum]; }
//新建一层 static void InsertPageLayer(u8 PageIdx) { OS_DeclareCritical(); OS_EnterCritical(); if(++gCurLayerNum<=MAX_PAGE_LAYER_NUM)//判断存储空间够不够 gPageLayers[gCurLayerNum]=PageIdx; else { Q_ErrorStopScreen("Layer is overflow,pls set marco MAX_PAGE_LAYER_NUM\n\r"); } OS_ExitCritical(); }
//得到相对当前页面Local步的页面索引 //Local=0,返回当前页面索引 //Local=1,返回前一页面索引 //Local=2,3,4...以此类推 u8 GetPageIdxByTrack(u8 Local) { if(Local>=MAX_PAGE_TRACK_NUM)//检查范围 { Debug("GetPageIdxByTrack error!(%d>=?%d)\n\r",Local,MAX_PAGE_TRACK_NUM); Q_ErrorStopScreen("GetPageIdxByTrack error!"); } Local=sizeof(gPageTracks)+gCurTrackIdx-Local; while(Local>=sizeof(gPageTracks)) { Local-=sizeof(gPageTracks); } return gPageTracks[Local]; }
//����ϵͳ�¼���Ӧλ void Q_SetPeripEvt(PAGE_RID RegID,u32 PeripEvtCon) { u8 PageIdx; OS_DeclareCritical(); if(RegID) { if(FindPage("",RegID,&PageIdx)!=SM_State_OK) //�˴�״̬��ʧ� { Q_ErrorStopScreen("Can't find page!\n\r"); } } else //���RegIDΪ0�����ص�ǰҳ����¼���־ { PageIdx=GetPageIdxByTrack(0); } OS_EnterCritical(); gPagePeripEvtFlag[PageIdx]|=PeripEvtCon; OS_ExitCritical(); }
static SYS_MSG GotoPageHandler(INPUT_EVT_TYPE EventType,u16 PageIdx,int IntParam, void *pSysParam) { u32 TimeMsRecord; u8 i; OS_DeclareCritical(); //关闭触摸和外部按键输入,保证在换页面或者程序的过程中忽略所有输入 Q_DisableInput(); //在无输入状态下Clean页面 if(gpCurrentPage) { if((!(gCurrSysMsg&SM_NoPageClean)) //Q_GotoPage返回值告诉系统不要执行Sys_PageClean或Sys_PreSubPage事件 && (GetPageByIdx(PageIdx)->Type != POP_PAGE)) //如果是pop页面,也不需要clean gCurrSysMsg|=OldPageClean(EventType,PageIdx); Debug("∧∧∧∧∧∧ Leave %s ∧∧∧∧∧∧\n\r",gpCurrentPage->Name); } else //没有上一个页面 { } //4--------------------------数据处理----------------------------- OS_EnterCritical();//目前,只有一个线程操作这些全局变量,所以临界区并不是必须的。 //记录页面Tarck InsertPageTrack(PageIdx); //记录页面层级 if(EventType==Input_GotoSubPage) //如果是进入子页面 { PushPageCtrlObjData();//保存前层的数据内容 CleanPageCtrlObjData();//清除页面数据 InsertPageLayer(PageIdx);//增加一层 } else if(EventType==Input_SubPageReturn) { DeletePageLayer(1);//删除一层 PopPageCtrlObjData(FALSE);//还原前层的数据内容 } else if(EventType==Input_GotoNewPage) { DeletePageLayer(0xff);//删除所有层 PopPageCtrlObjData(TRUE);//删除所有存储的数据内容 CleanPageCtrlObjData();//清除页面数据 InsertPageLayer(PageIdx);//增加一层 //页面堆检查 if(gPageHeapRecord) { Debug("gPageHeapRecord:%d\n\r",gPageHeapRecord); Q_ErrorStopScreen("!!!Warnning!!! Page momery don't be freed!"); } } else if(EventType==Input_SubPageTranslate) { DeletePageLayer(1);//删除一层 CleanPageCtrlObjData();//清除页面数据 InsertPageLayer(PageIdx);//增加一层 } //更换主指针 gpCurrentPage=Q_GetPageByTrack(0); gEntriesOfPage[PageIdx]++;//进页面一次自加一次 PageSwithcCtrlObjDataHandler(gpCurrentPage);//控件数据处理 OS_ExitCritical(); //4-------------------------数据处理完成-------------------------- TimeMsRecord=OS_GetCurrentSysMs(); Debug("\n\r∨∨∨∨∨∨ Goto %s ∨∨∨∨∨∨\n\r",gpCurrentPage->Name); Debug("##Author:%s\n\r",gpCurrentPage->Author); Debug("##Description:%s\n\r",gpCurrentPage->Description); Debug("##Page Layers:"); for(i=1;i<GetCurLayerNum();i++) Debug("%s->",GetPageByIdx(PageLayers[i])->Name); Debug("%s\n\r",GetPageByIdx(PageLayers[i])->Name); if((!(gCurrSysMsg&SM_NoPageInit)) //Q_GotoPage返回值告诉系统不要执行page init &&(Q_GetPageByTrack(1)->Type!=POP_PAGE)) //从pop页面返回,也不需要page init gCurrSysMsg|=CurrentPageInit(EventType,IntParam,pSysParam); if((!(gCurrSysMsg&SM_NoTouchInit))//Q_GotoPage或页面SystemEventHandler函数返回值告诉系统不需要touch init &&(Q_GetPageByTrack(1)->Type!=POP_PAGE)) //从pop页面返回,也不需要touch init gCurrSysMsg|=CurrPageCtrlObjInit(EventType,IntParam,pSysParam); if(!(gCurrSysMsg&SM_NoPopReturn)//从前面的函数返回掩码 &&(Q_GetPageByTrack(1)->Type==POP_PAGE))//前一个页面是pop页面 gCurrSysMsg|=gpCurrentPage->SysEvtHandler(Sys_PopPageReturn,IntParam,pSysParam); switch(GetRegIdByIdx(GetPageIdxByTrack(1)))//判断从哪个页面返回 { case PRID_NumCtrlObjPage: //从num控件页返回 { NUM_CTRL_OBJ *pNumCtrlObj=pSysParam; if(gpCurrentPage->NumCtrlObjHander) gpCurrentPage->NumCtrlObjHander(pNumCtrlObj->ObjID,pNumCtrlObj->Value,pSysParam); else Debug("!!!Not Define Handler Function In Page Struct!!!\n\r"); }break; case PRID_StrCtrlObjPage: //从Str控件页返回 { STR_CTRL_OBJ *pStrCtrlObj=pSysParam; STR_BOX_OBJ *pStrBoxObj=pSysParam; STR_ENUM_OBJ *pStrEnumObj=pSysParam; if(gpCurrentPage->StrCtrlObjHandler) { if(pStrCtrlObj->Type == SCOT_StrBox) gpCurrentPage->StrCtrlObjHandler(pStrBoxObj->ObjID,0,pStrBoxObj->pStrBuf,pSysParam); else if(pStrCtrlObj->Type == SCOT_StrEnum) gpCurrentPage->StrCtrlObjHandler(pStrEnumObj->ObjID,pStrEnumObj->pStrEnumBuf[pStrEnumObj->Idx],&pStrEnumObj->pStrEnumBuf[pStrEnumObj->Idx+1],pSysParam); } else Debug("!!!Not Define Handler Function In Page Struct!!!\n\r"); }break; defalut: while((OS_GetCurrentSysMs()-TimeMsRecord)<300) OS_TaskDelayMs(50);//循环延时300ms,以避免触摸响应混乱 } Q_EnableInput(); Input_Debug("%s end: %s\n\r",__FUNCTION__,gpCurrentPage->Name); return gCurrSysMsg; }
void QSYS_Init(void) { u8 *ptr1; u8 *ptr2; // FIL *ptr3; OS_CPU_SysTickInit();//Initialize the SysTick. #if OS_USE_UCOS CPU_IntSrcPrioSet(CPU_INT_PENDSV,15); CPU_IntSrcPrioSet(CPU_INT_SYSTICK,15); #endif SetupHardware(); Debug("sizeof(INPUT_EVENT)=%d\n\r",sizeof(INPUT_EVENT));//for debug by karlno Debug("sizeof(PAGE_ATTRIBUTE)=%d\n\r",sizeof(PAGE_ATTRIBUTE));//for debug by karlno Debug("sizeof(IMG_BUTTON_OBJ)=%d\n\r",sizeof(IMG_BUTTON_OBJ));//for debug by karlno Debug("sizeof(CHAR_BUTTON_OBJ)=%d\n\r",sizeof(CHAR_BUTTON_OBJ));//for debug by karlno Debug("sizeof(MUSIC_EVENT)=%d\n\r",sizeof(MUSIC_EVENT));//for debug by karlno //Debug("sizeof(QSYS_MSG_BOX)=%d\n\r",sizeof(QSYS_MSG_BOX));//for debug by karlno if(SysEvt_MaxNum>32) { Debug("Error:SysEvt_MaxNum(%d) is too big!!!\n\r",SysEvt_MaxNum); Q_ErrorStopScreen("Error:SysEvt_MaxNum is too big!!!\n\r"); } gLCD_Mutex=OS_MutexCreate(); //创建触摸输入中断发生信号量 gTouchHandler_Sem=OS_SemaphoreCreate(0); gAllowTchHandler_Sem=OS_SemaphoreCreate(0); gVsDreq_Sem=OS_SemaphoreCreate(0); gRfRecvHandler_Sem=OS_SemaphoreCreate(0); //创建事件传递数据 gInputHandler_Queue=OS_MsgBoxCreate("Input Event",sizeof(INPUT_EVENT),16); gMusicHandler_Queue=OS_MsgBoxCreate("MusicKV Event",sizeof(MUSIC_EVENT),8); #if 0//debug OS_TaskCreate((void (*) (void *)) T1_Task,(void *) 0, (OS_STK *) &T1_TaskStack[OS_MINIMAL_STACK_SIZE - 1],T1_TASK_pRIORITY); //OS_TaskCreate(T2_Task , ( signed OS_CHAR * ) "T2 Handler", OS_MINI_STACK_SIZE, NULL, MUSIC_HANDLER_TASK_PRIORITY, NULL ); OS_TaskDelete(SYSTEM_TASK_PRIORITY); #endif #if 1 //首次下载完成后可关闭此处代码,防止误下载 Debug("\n\r-------------------SPI FLASH DOWNLOAD FROM SD------------------\n\r"); ptr1=(u8 *)Q_Mallco(CfgFileSize); ptr2=(u8 *)Q_Mallco(SPI_FLASH_PAGE_SIZE); SpiFlashDownFromSD(FALSE,"System/Down.cfg",ptr1,ptr2); Q_Free(ptr2); Q_Free(ptr1); Debug("-------------------SPI FLASH DOWNLOAD FROM SD------------------\n\r\n\r"); #endif Debug("----------------DATABASE SETTING INITIALIZATION----------------\n\r"); DB_Init(); Debug("----------------DATABASE SETTING INITIALIZATION----------------\n\r\n\r"); RTC_SetUp(); Gui_Init(); //图像库初始化 Gui_SetBgLight(Q_DB_GetValue(Setting_BgLightScale,NULL));//设置背光亮度 OS_TaskCreate(MusicHandler_Task,"Music",OS_MINIMAL_STACK_SIZE*8,NULL,MUSIC_TASK_PRIORITY,&MusicHandler_Task_Handle); OS_TaskCreate(TouchHandler_Task,"Touch",OS_MINIMAL_STACK_SIZE*3,NULL,TOUCH_TASK_PRIORITY,&TouchHandler_Task_Handle); OS_TaskCreate(KeysHandler_Task,"Keys",OS_MINIMAL_STACK_SIZE*2,NULL,KEYS_TASK_PRIORITY,&KeysHandler_Task_Handle); OS_TaskCreate(QWebHandler_Task,"QWeb",OS_MINIMAL_STACK_SIZE*8,NULL,RF_DATA_TASK_PRIORITY,&QWebHandler_Task_Handle); OS_TaskDelay(100); OS_TaskStkCheck(FALSE); if(GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_2)==0) //如果没按下Key-PE2,就正常启动串口中断 { #if !QXW_RELEASE_VER//for debug USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);//release版本请关掉此句,免得不懂的用户说板卡老死机。 USART_ITConfig(USART3, USART_IT_RXNE, ENABLE); #endif } }
//ת��ijҳ��,���ô˺�����InputHandler���߳�����ɵ�ǰ����Ὺʼת������ //return TRUE :����ת�� //return FALSE : ������ת�� //ҳ����ҳ��֮��IJ������ݿ���pInfoParamָ�� SYS_MSG Q_GotoPage(PAGE_ACTION PageAction, u8 *Name, int IntParam, void *pSysParam) { INPUT_EVENT InEventParam; u8 PageIdx; u8 Result; if(GetCurrPage()) UA_Debug("%s : %s->%s\n\r",__FUNCTION__,GetCurrPage()->Name,Name); else UA_Debug("%s : NULL->%s\n\r",__FUNCTION__,Name); //���Ҷ�Ӧҳ�� if(PageAction==SubPageReturn) //�������ҳ�淵�أ����ҵ���һ��ҳ�� { gCurrSysMsg=SM_State_OK; PageIdx=GetPageIdxByLayerOffset(1); } else { gCurrSysMsg=FindPage(Name,0,&PageIdx);//��ʼ��ҳ��ش���Ϣ if(gCurrSysMsg!=SM_State_OK)//û�ҵ���Ӧҳ�� { return gCurrSysMsg; } } if(GetPageByIdx(PageIdx)->Type==POP_PAGE)//Ҫ�����ҳ����popҳ�� if((PageAction!=GotoSubPage)&&(PageAction!=SubPageReturn)) { Q_ErrorStopScreen("Pop Page not allow entry by \"GotoNewPage\" & \"SubPageTranslate\" param!"); return SM_State_Faile; } //POPҳ��ֻ��������ҳ�淵�ص���ʽ�˳� if((Q_GetPageByTrack(0)->Type==POP_PAGE)&&(PageAction!=SubPageReturn)) { Q_ErrorStopScreen("Pop Page only allow quit by \"SubPageReturn\" param!"); return SM_State_Faile; } if(Q_GetPageByTrack(0)->Type!=POP_PAGE) //�����popҳ�淵�أ���ô����Ҫִ�����goto case gCurrSysMsg=GetPageByIdx(PageIdx)->SysEvtHandler(Sys_PreGotoPage, IntParam,pSysParam); //Debug("GotoPage Return 0x%x\n\r",SysMsg); if(gCurrSysMsg&SM_NoGoto)//ҳ���Sys_Goto_Page���ݻص���Ϣ {//��ҳ���Sys_PreGotoPage���ݻ�SM_NoGoto��Ϣ��ʾ����Ҫ�����ҳ���ˡ� return gCurrSysMsg; } else { InEventParam.uType=Sync_Type; switch(PageAction) { case GotoNewPage: InEventParam.EventType=Input_GotoNewPage;break; case GotoSubPage: InEventParam.EventType=Input_GotoSubPage;break; case SubPageReturn: InEventParam.EventType=Input_SubPageReturn;break; } InEventParam.Num=PageIdx; InEventParam.Info.SyncInfo.IntParam=IntParam; InEventParam.Info.SyncInfo.pParam=pSysParam; //Debug("New Page Index:%d\n\r",PageIdx); if((Result=OS_MsgBoxSend(gInputHandler_Queue,&InEventParam,100,FALSE))==OS_ERR_NONE) { return gCurrSysMsg; } else { Debug("GotoPage Send Msg Error!%d\n\r",Result); return SM_State_Faile; } } }