main.c
上传用户:wealth48
上传日期:2022-06-24
资源大小:1701k
文件大小:33k
- /***************************************************************************
- Copyright (c) 2004-2007 threewater@up-tech.com, All rights reserved.
- by threewter 2004.5.12
- ***************************************************************************/
- /***************************************************************************
- #说明: C main 函数,ucos-ii初始化等定义
- ---------------------------------- Bug --------------------------------------
- ---------------------------------- TODO list --------------------------------------
- ----------------------------------修正--------------------------------------
- 2004-5-12 创建
- ***************************************************************************/
- #include"../ucos-ii/includes.h" /* uC/OS interface */
- #include "../ucos-ii/add/osaddition.h"
- #include "../inc/drivers.h"
- #include "../inc/sys/lib.h"
- #include "menuGUI.h"
- #include "Model.h"
- #include <string.h>
- #include <stdio.h>
- #pragma import(__use_no_semihosting_swi) // ensure no functions that use semihosting
- ///******************任务定义***************///
- OS_STK Main_Stack[STACKSIZE]={0, }; //Main_Test_Task堆栈
- void Main_Task(void *Id); //Main_Test_Task
- #define Main_Task_Prio 12
- OS_STK test_Stack[STACKSIZE]={0, }; //test_Test_Task堆栈
- void test_Task(void *Id); //test_Test_Task
- #define test_Task_Prio 11
- OS_STK star_Stack[STACKSIZE]={0, }; //test_Test_Task堆栈
- void star_Task(void *Id); //test_Test_Task
- #define star_Task_Prio 10
- /**************已经定义的OS任务*************
- #define SYS_Task_Prio 1
- #define Touch_Screen_Task_Prio 9
- #define Main_Task_Prio 12
- #define Key_Scan_Task_Prio 58
- #define Lcd_Fresh_prio 59
- #define Led_Flash_Prio 60
- ***************************************/////////
- ///*****************事件定义*****************///
- /////////////////////////////////////////////////////
- // Main function. //
- ////////////////////////////////////////////////////
- extern U16 LCDBufferII2[480][640];
- extern U16* pbuf;
- extern rLCDADDR1;
- extern U8 *LoadBMPBuf;
- int main(void)
- {
- ARMTargetInit(); // do target (uHAL based ARM system) initialisation //
- OSInit(); // needed by uC/OS-II //
- OSInitUart();
- initOSFile();
- #if USE_MINIGUI==0
- initOSMessage();
- initOSList();
- initOSDC();
- initOSCtrl();
- //LoadFont();
- #endif
- loadsystemParam();
-
- // create the tasks in uC/OS and assign increasing //
- // priorities to them so that Task3 at the end of //
- // the pipeline has the highest priority. //
- LCD_printf("Create task on uCOS-II...n");
- OSTaskCreate(Main_Task, (void *)0, (OS_STK *)&Main_Stack[STACKSIZE-1], Main_Task_Prio);
- OSTaskCreate(test_Task, (void *)0, (OS_STK *)&test_Stack[STACKSIZE-1], test_Task_Prio);
- OSTaskCreate(star_Task, (void *)0, (OS_STK *)&star_Stack[STACKSIZE-1], star_Task_Prio);
- OSAddTask_Init(1);
-
- LCD_printf("Starting uCOS-II...n");
- LCD_printf("Entering graph mode...n");
- LCD_printf("0641301240 wenzhiqiangn");
-
- LCD_printf("0641301236 chenhaiyongn");
-
- LoadBMPBuf = malloc(3 * 640*2000);
-
- OSStart(); // start the OS //
- // never reached //
- return 0;
- }//main
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- void Main_Task(void *Id) //Main_Test_Task
- {
- //-------------------------------
-
- POSMSG pMsg;//定义消息结构
- int X,Y;
- int choiceIndex;
- int i;
-
- int distance;
- unsigned int Get_time,G_time[2];
-
- struct point{
- int x;
- int y;
- };//定义点坐标结构
- struct point scrpoint;//触摸点
- struct point scrpoint2[2];
-
- static char KeyName2[3];
- static int KeyStatue[2]={0,0};
- char * KeyName[16]={"10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25"};
- int count=0;
- int doubleFlag = 1;
- int Flag=0;
- WaitMessage(0);
- //------------------------------------
- InitMenuGUI();
- InitModel();
-
-
- for(;;){
- pMsg=WaitMessage(0);//等待消息
- switch(pMsg->Message){
- case OSM_TOUCH_SCREEN://OSM_TOUCH_SCREEN:
-
- switch(pMsg->LParam){
-
-
- case TCHSCR_ACTION_CLICK:
-
- scrpoint.x=pMsg->WParam&0x0000ffff;
- if(scrpoint.x<1) scrpoint.x=1;
- if(scrpoint.x>639) scrpoint.x=639;
- scrpoint.y=pMsg->WParam>>16;
- if(scrpoint.y<1) scrpoint.y=1;
- if(scrpoint.y>479) scrpoint.y=479;
- Uart_Printf(0,"nx0=%d",scrpoint.x);
- Uart_Printf(0,"y0=%dn",scrpoint.y);
- choiceIndex = ChoiceWhat(scrpoint.x,scrpoint.y);
- Uart_Printf(0,"ChoiceWhat:%dn",choiceIndex);
- if(choiceIndex<25){
- if(getState(choiceIndex) == 0){
- Select(choiceIndex);
- Mark(choiceIndex);
- }
- else {
- Cancal(choiceIndex);
- CancalMark(choiceIndex);
- }
-
- }else{
- if(choiceIndex == 30){
- for(i = 0;i < 32;i++)
- ScrollMenu(-10);
- }//上一页
- if(choiceIndex == 31){
- for(i = 0;i < 32;i++)
- ScrollMenu(10);
- }//下一页
-
- if(choiceIndex == 32){//点菜结束
- EndSelect();
- for(i = 0;i < 25;i++)
- {
- if(getState(i) == 1){
- CancalMark(i);
- }
- }
- InitModel();
- ScrollMenu(0);
- }
- if(choiceIndex == 33){
- CloseImage();
- for(;;){OSTimeDly(2000);}
- }//关闭
- }
- Uart_Printf(0,"total:%d",getTotalPrice());
- ShowNum(450,430,getTotalPrice());
-
- break;
-
-
- case TCHSCR_ACTION_DOWN:
- scrpoint.x=-1;//表示触摸屏按下
-
- //获得触摸点坐标
- scrpoint2[0].x=pMsg->WParam&0x0000ffff;
- if(scrpoint2[0].x<1) scrpoint2[0].x=1;
- if(scrpoint2[0].x>639) scrpoint2[0].x=639;
- scrpoint2[0].y=pMsg->WParam>>16;
- if(scrpoint2[0].y<1) scrpoint2[0].y=1;
- if(scrpoint2[0].y>479) scrpoint2[0].y=479;
-
- G_time[0]=OSTimeGet();//获取系统当前时间
-
-
- Uart_Printf(0,"nx1=%d",scrpoint2[0].x);
- Uart_Printf(0,"y1=%dn",scrpoint2[0].y);
-
- break;
- case TCHSCR_ACTION_MOVE:
- scrpoint2[1].x=pMsg->WParam&0x0000ffff;
- if(scrpoint2[1].x<1) scrpoint2[1].x=1;
- if(scrpoint2[1].x>639) scrpoint2[1].x=639;
- scrpoint2[1].y=pMsg->WParam>>16;
- if(scrpoint2[1].y<1) scrpoint2[1].y=1;
- if(scrpoint2[1].y>479) scrpoint2[1].y=479;
-
-
- G_time[1]=OSTimeGet();//获取系统当前时间
- Get_time= G_time[1]- G_time[0];//获取从按下到移动的时间
- Uart_Printf(0,"移动时间 :%dn",Get_time);
-
-
-
-
- Uart_Printf(0,"nx2=%d",scrpoint2[1].x);
- Uart_Printf(0,"y2=%dn",scrpoint2[1].y);
-
- X=scrpoint2[1].x-scrpoint2[0].x;
- Y=scrpoint2[1].y-scrpoint2[0].y;
-
- distance=sqrt(X*X+Y*Y)*1000;
- Uart_Printf(0,"distance:%d",distance);
-
- scrpoint2[0].x=scrpoint2[1].x;
- scrpoint2[0].y=scrpoint2[1].y;
-
-
-
- Uart_Printf(0,"移动速度 :%dn",distance/Get_time);
-
-
-
- if(X==0 && Y==0)
- {
- //当作单击处理
- Uart_Printf(0,"n...Click...");
-
-
- }
- else
- {
- if(X>0)
- {
- if(Y<0)
- {
- if(abs(Y)<=X)
- {
- //向右滚
-
- Uart_Printf(0,"n...Go to right...");
- }
- else
- {
- //向上滚
- if(distance/Get_time>1000)
- {
- //向上甩
- Uart_Printf(0,"n...Go to top fastly...");
-
- }
-
- else {Uart_Printf(0,"n...Go to top...");
- ScrollMenu(distance/1000);}
- }
- }
- else
- {
- if(Y<=X)
- {
- //向右滚
- Uart_Printf(0,"n...Go to right...");
- }
- else
- {
- //向下滚
- if(distance/Get_time>1000)
- {
- //向下甩
- Uart_Printf(0,"n...Go to bottom fastly...");
-
- }
- else Uart_Printf(0,"n...Go to bottom...");
- ScrollMenu(-distance/1000);
-
- }
-
- }
- }
- else
- {
- if(Y<0)
- {
- if(abs(Y)<=abs(X))
- {
- //向左滚
- Uart_Printf(0,"n...Go to left...");
- }
- else
- {
- //向上滚
- if(distance/Get_time>1000)
- {
- //向上甩
- Uart_Printf(0,"n...Go to top fastly...");
-
- }
-
- else {Uart_Printf(0,"n...Go to top...");
- ScrollMenu(distance/1000);}
- }
- }
- else
- {
- if(Y<=abs(X))
- {
- //向左滚
- Uart_Printf(0,"n...Go to left...");
- }
- else
- {
- //向下滚
- if(distance/Get_time>1000)
- {
- //向下甩
- Uart_Printf(0,"n...Go to bottom fastly...");
-
- }
-
- else {
- Uart_Printf(0,"n...Go to bottom...");
- ScrollMenu(-distance/1000);
- }
- }
-
- }
- }
- }
-
-
-
- break;
- case TCHSCR_ACTION_UP:
- scrpoint2[0].x=0;
- scrpoint2[0].y=0;
- scrpoint2[1].x=0;
- scrpoint2[1].y=0;
-
- break;
-
-
-
- }
-
-
- break;
-
-
-
-
-
- case OSM_KEY:
- Flag++;
- if(Flag==2)
- {
- Uart_Printf(0,"keyn");
- if((pMsg->WParam)=='+')//表示按两个键
- {
- KeyStatue[0]=1;
- KeyStatue[1]=1; //对按键进行标记
- Uart_Printf(0,"touch = + ");
-
-
-
- }
- else if(KeyStatue[0]==1 || KeyStatue[1]==1)
- {
-
- // count++;
-
- if(KeyStatue[0]==1)
- {
- KeyName2[0]=pMsg->WParam;
-
-
- KeyStatue[0]=0;
- Uart_Printf(0,"KeyName2[0]======%cn",KeyName2[0]);
-
-
- }
-
- else //if(count>2)
- {
-
- KeyName2[1]=pMsg->WParam;
- Uart_Printf(0,"KeyName2[1]======%cn",KeyName2[1]);
-
- KeyName2[2]=0;
- Uart_Printf(0,"KeyName2======%sn",KeyName2);
-
- KeyStatue[1]=0;
- // count=0;
-
- }
-
- if(KeyStatue[0]==0 && KeyStatue[1]==0)
- {
- if(strcmp(KeyName2,KeyName[0])==0)
- {
- Uart_Printf(0,"touch=10n");
- doubleFlag =0;
- choiceIndex = 9;
- if(getState(choiceIndex) == 0){
- Select(choiceIndex);
- Mark(choiceIndex);
- }
- else {
- Cancal(choiceIndex);
- CancalMark(choiceIndex);
- }
-
-
-
- }else
- if(strcmp(KeyName2,KeyName[1])==0)
- {
-
- Uart_Printf(0,"touch=11n");
- doubleFlag =0;
- choiceIndex = 10;
- if(getState(choiceIndex) == 0){
- Select(choiceIndex);
- Mark(choiceIndex);
- }
- else {
- Cancal(choiceIndex);
- CancalMark(choiceIndex);
- }
-
-
- }else
- if(strcmp(KeyName2,KeyName[2])==0)
- {
- Uart_Printf(0,"touch=12n");
- doubleFlag =0;
- choiceIndex = 11;
- if(getState(choiceIndex) == 0){
- Select(choiceIndex);
- Mark(choiceIndex);
- }
- else {
- Cancal(choiceIndex);
- CancalMark(choiceIndex);
- }
-
- }else
- if(strcmp(KeyName2,KeyName[3])==0)
- {
- Uart_Printf(0,"touch=13n");
- doubleFlag =0;
- choiceIndex = 12;
- if(getState(choiceIndex) == 0){
- Select(choiceIndex);
- Mark(choiceIndex);
- }
- else {
- Cancal(choiceIndex);
- CancalMark(choiceIndex);
- }
-
-
- }else
- if(strcmp(KeyName2,KeyName[4])==0)
- {
- Uart_Printf(0,"touch=14n");
- doubleFlag =0;
- choiceIndex = 13;
- if(getState(choiceIndex) == 0){
- Select(choiceIndex);
- Mark(choiceIndex);
- }
- else {
- Cancal(choiceIndex);
- CancalMark(choiceIndex);
- }
-
-
- }else
- if(strcmp(KeyName2,KeyName[5])==0)
- {
- Uart_Printf(0,"touch=15n");
- doubleFlag =0;
- choiceIndex = 14;
- if(getState(choiceIndex) == 0){
- Select(choiceIndex);
- Mark(choiceIndex);
- }
- else {
- Cancal(choiceIndex);
- CancalMark(choiceIndex);
- }
-
-
- }else
- if(strcmp(KeyName2,KeyName[6])==0)
- {
- Uart_Printf(0,"touch=16n");
- doubleFlag =0;
- choiceIndex = 15;
- if(getState(choiceIndex) == 0){
- Select(choiceIndex);
- Mark(choiceIndex);
- }
- else {
- Cancal(choiceIndex);
- CancalMark(choiceIndex);
- }
-
-
- }else
- if(strcmp(KeyName2,KeyName[7])==0)
- {
- Uart_Printf(0,"touch=17n");
- doubleFlag =0;
- choiceIndex = 16;
- if(getState(choiceIndex) == 0){
- Select(choiceIndex);
- Mark(choiceIndex);
- }
- else {
- Cancal(choiceIndex);
- CancalMark(choiceIndex);
- }
-
-
- }else
- if(strcmp(KeyName2,KeyName[8])==0)
- {
- Uart_Printf(0,"touch=18n");
- doubleFlag =0;
- choiceIndex = 17;
- if(getState(choiceIndex) == 0){
- Select(choiceIndex);
- Mark(choiceIndex);
- }
- else {
- Cancal(choiceIndex);
- CancalMark(choiceIndex);
- }
-
-
- }else
- if(strcmp(KeyName2,KeyName[9])==0)
- {
- Uart_Printf(0,"touch=19n");
- doubleFlag =0;
- choiceIndex = 18;
- if(getState(choiceIndex) == 0){
- Select(choiceIndex);
- Mark(choiceIndex);
- }
- else {
- Cancal(choiceIndex);
- CancalMark(choiceIndex);
- }
-
-
- }else
- if(strcmp(KeyName2,KeyName[10])==0)
- {
- Uart_Printf(0,"touch=20n");
- doubleFlag =0;
- choiceIndex = 19;
- if(getState(choiceIndex) == 0){
- Select(choiceIndex);
- Mark(choiceIndex);
- }
- else {
- Cancal(choiceIndex);
- CancalMark(choiceIndex);
- }
-
-
- }
- else
- if(strcmp(KeyName2,KeyName[11])==0)
- {
- Uart_Printf(0,"touch=21n");
- doubleFlag =0;
- choiceIndex = 20;
- if(getState(choiceIndex) == 0){
- Select(choiceIndex);
- Mark(choiceIndex);
- }
- else {
- Cancal(choiceIndex);
- CancalMark(choiceIndex);
- }
-
-
- }else
- if(strcmp(KeyName2,KeyName[12])==0)
- {
- Uart_Printf(0,"touch=22n");
- doubleFlag =0;
- choiceIndex = 21;
- if(getState(choiceIndex) == 0){
- Select(choiceIndex);
- Mark(choiceIndex);
- }
- else {
- Cancal(choiceIndex);
- CancalMark(choiceIndex);
- }
-
-
- }else
- if(strcmp(KeyName2,KeyName[13])==0)
- {
- Uart_Printf(0,"touch=23n");
- doubleFlag =0;
- choiceIndex = 22;
- if(getState(choiceIndex) == 0){
- Select(choiceIndex);
- Mark(choiceIndex);
- }
- else {
- Cancal(choiceIndex);
- CancalMark(choiceIndex);
- }
-
-
- }else
- if(strcmp(KeyName2,KeyName[14])==0)
- {
- Uart_Printf(0,"touch=24n");
- doubleFlag =0;
- choiceIndex = 23;
- if(getState(choiceIndex) == 0){
- Select(choiceIndex);
- Mark(choiceIndex);
- }
- else {
- Cancal(choiceIndex);
- CancalMark(choiceIndex);
- }
-
-
- }else
- if(strcmp(KeyName2,KeyName[15])==0)
- {
- Uart_Printf(0,"touch=25n");
- doubleFlag =0;
- choiceIndex = 24;
- if(getState(choiceIndex) == 0){
- Select(choiceIndex);
- Mark(choiceIndex);
- }
- else {
- Cancal(choiceIndex);
- CancalMark(choiceIndex);
- }
-
-
- }
- // doubleFlag =0;
- Flag=0;
-
-
- }
- }
- else if(KeyStatue[0]==0 && KeyStatue[1]==0 )
- {
-
- switch(pMsg->WParam)
- {
- case '1':
- /* if(doubleFlag < 2)
- doubleFlag ++;
- else{*/
- choiceIndex = 0;
- if(getState(choiceIndex) == 0){
- Select(choiceIndex);
- Mark(choiceIndex);
- }
- else {
- Cancal(choiceIndex);
- CancalMark(choiceIndex);
- }
- Uart_Printf(0,"touch=1n");break;
- // }
-
- case '2':
- /* if(doubleFlag < 2)
- doubleFlag ++;
- else{*/
- choiceIndex = 1;
- if(getState(choiceIndex) == 0){
- Select(choiceIndex);
- Mark(choiceIndex);
- }
- else {
- Cancal(choiceIndex);
- CancalMark(choiceIndex);
- }
- Uart_Printf(0,"touch=2n");break;
- //}
- case '3':
- /* if(doubleFlag < 2)
- doubleFlag ++;
- else{*/
- choiceIndex = 2;
- if(getState(choiceIndex) == 0){
- Select(choiceIndex);
- Mark(choiceIndex);
- }
- else {
- Cancal(choiceIndex);
- CancalMark(choiceIndex);
- }
- Uart_Printf(0,"touch=3n");break;
- //}
- case '4':
- /* if(doubleFlag < 2)
- doubleFlag ++;
- else{*/
- choiceIndex = 3;
- if(getState(choiceIndex) == 0){
- Select(choiceIndex);
- Mark(choiceIndex);
- }
- else {
- Cancal(choiceIndex);
- CancalMark(choiceIndex);
- }
- Uart_Printf(0,"touch=4n");break;
- //}
- case '5':
- /* if(doubleFlag < 2)
- doubleFlag ++;
- else{*/
- choiceIndex = 4;
- if(getState(choiceIndex) == 0){
- Select(choiceIndex);
- Mark(choiceIndex);
- }
- else {
- Cancal(choiceIndex);
- CancalMark(choiceIndex);
- }
- Uart_Printf(0,"touch=5n");break;
- //}
- case '6':
- /* if(doubleFlag < 2)
- doubleFlag ++;
- else{*/
- choiceIndex = 5;
- if(getState(choiceIndex) == 0){
- Select(choiceIndex);
- Mark(choiceIndex);
- }
- else {
- Cancal(choiceIndex);
- CancalMark(choiceIndex);
- }
- Uart_Printf(0,"touch=6n");break;
- //}
- case '7':
- /* if(doubleFlag < 2)
- doubleFlag ++;
- else{*/
- choiceIndex = 6;
- if(getState(choiceIndex) == 0){
- Select(choiceIndex);
- Mark(choiceIndex);
- }
- else {
- Cancal(choiceIndex);
- CancalMark(choiceIndex);
- }
- Uart_Printf(0,"touch=7n");break;
- //}
- case '8':
- /* if(doubleFlag < 2)
- doubleFlag ++;
- else{*/
- choiceIndex = 7;
- if(getState(choiceIndex) == 0){
- Select(choiceIndex);
- Mark(choiceIndex);
- }
- else {
- Cancal(choiceIndex);
- CancalMark(choiceIndex);
- }
- Uart_Printf(0,"touch=8n");break;
- //}
- case '9':
- /* if(doubleFlag < 2)
- doubleFlag ++;
- else{*/
- choiceIndex = 8;
- if(getState(choiceIndex) == 0){
- Select(choiceIndex);
- Mark(choiceIndex);
- }
- else {
- Cancal(choiceIndex);
- CancalMark(choiceIndex);
- }
- Uart_Printf(0,"touch=9n");break;
- //}
-
- default:
- break;
-
-
-
-
- }
-
- }
- ShowNum(450,430,getTotalPrice());
- Flag = 0;
- break;
- }
-
-
- }
-
- DeleteMessage(pMsg);//删除消息
- // OSTimeDly(10);
- }
-
-
-
-
-
- //-------------------------------
- for(;;){
-
- }
- }
- void star_Task(void *Id){
- Uart_Printf(0,"star_Task start!");
- LCD_ChangeMode(DspGraMode);
- start1BMP = malloc(2 * 640 * 480);
- LoadBMP(start1BMP,"/sys/ucos/e-menu/star1.bmp",640,480);
- pbuf = start1BMP;
- kLCD_Refresh();
- for(;;){
- OSTimeDly(10000);
- }
- }
- void test_Task(void *Id){
- int i = 0;
- Uart_Printf(0,"test_Task start!");
- startBMP = malloc(2 * 640 * 480);
- bootBMP[0] = malloc(2 * 72 * 32);
- bootBMP[1] = malloc(2 * 72 * 32);
- bootBMP[2] = malloc(2 * 72 * 32);
- bootBMP[3] = malloc(2 * 72 * 32);
- LoadBMP(startBMP,"/sys/ucos/e-menu/start.bmp",640,480);
- pbuf = startBMP;
- LoadBMP(bootBMP[0],"/sys/ucos/e-menu/boot0.bmp",72,30);
- LoadBMP(bootBMP[1],"/sys/ucos/e-menu/boot1.bmp",72,30);
- LoadBMP(bootBMP[2],"/sys/ucos/e-menu/boot2.bmp",72,30);
- LoadBMP(bootBMP[3],"/sys/ucos/e-menu/boot3.bmp",72,30);
-
- kLCD_Refresh();
- for(;bootFlag == 1;){
- PaintBMP(pbuf,bootBMP[i],437,247,72,30);
- kLCD_Part_Refresh(437,247,509,277);
- i++;
- if(i == 4)i = 0;
- OSTimeDly(200);
- }
- for(;;){
- OSTimeDly(10000);
- }
- }