全部博文(395)
分类: C/C++
2011-05-21 08:50:54
/*
*********************************************************************************************************
* File : MainTask.c
* Purpose : Application program in windows simulator
*********************************************************************************************************
*/
#include "GUI.h"
#include "GUI_Protected.h"
#include
#include
#include
extern const GUI_BITMAP bmMicriumLogo;
extern const GUI_BITMAP bmMicriumLogo_1bpp;
/*
*******************************************************************
*
* main()
*
*******************************************************************
*/
//函数实现的功能是每按下一次seclect键,图标会变色选中某个选项,此时时钟停止,进入调试阶段
//按下7次secl键后时钟重新运行,当按下add键时,对应的选项曾一,按下red键时,对应选型减一
//(说明,由于技术有限,在每次按下键后都要重新按一下图标旁的空白处才能算是按键有效)
void MainTask(void) {
int num1=0;
int flag=0;
int second=51,minute=52,hour=14,day=22,month=5,year=2010,secondm=0;
GUI_Init();
GUI_CURSOR_Show();
GUI_CURSOR_Select(&GUI_CursorCrossL);
GUI_SetBkColor(GUI_WHITE);
GUI_SetColor(GUI_BLACK);
GUI_Clear();
// LCD_L0_FillRect(240, 90, 320, 130);
GUI_SetFont(&GUI_Font24_ASCII);
GUI_SetColor(GUI_BLACK);
GUI_SetBkColor(GUI_WHITE);
GUI_SetColor(GUI_YELLOW);
LCD_L0_FillRect(10, 200, 80, 240);
GUI_SetBkColor(GUI_GRAY);
GUI_DispStringHCenterAt("Sel", 45, 210);
LCD_L0_FillRect(90, 200, 160, 240);
GUI_DispStringHCenterAt("Add", 120, 210);
LCD_L0_FillRect(170, 200, 250, 240);
GUI_DispStringHCenterAt("Red", 220, 210);
// GUI_DispStringHCenterAt("200", 280, 100);
while (1){
GUI_PID_STATE TouchState;
GUI_TOUCH_GetState(&TouchState); /* Get the touch position in pixel */
//time=GUI_GetTime(); //获取系统时间
if(flag==0){ //为了使时间停止,设置一个标志
GUI_SetFont(&GUI_Font32_ASCII); //设置字体大小
GUI_SetColor(GUI_BLACK);
GUI_DispDecAt( second, 220,155,2); //显示数字函数
GUI_DispDecAt( minute, 120,155,2);
GUI_DispDecAt( hour, 20,155,2);
GUI_DispDecAt( day, 220,55,2);
GUI_DispDecAt(month, 120,55,2);
GUI_DispDecAt( year, 20,55,4);
secondm=GUI_GetTime()/100; //由于没有定时器,这一下操作不得不用延时
secondm%=10; //直接导致的后果是鼠标不是闪烁,还会出现鼠标的十字光标,
} //并且更严重的是时钟不准确(误差的太大)
if(secondm==9){
second++;
GUI_Delay(100);
}
if(second>=60){
minute++;second=0;
}
if(minute>=60){
hour++;minute=0;
}
if(hour>=24){
day++;hour=0;
}
if(day>=30){
month++;day=0;
}
if(month>=12) {
year++;month=0;
}
if(year>2100){
year=2010;
}
//加入点击了第一个按钮,进行计数器加一操作
if((TouchState.x>10)&&(TouchState.x<80)&&(TouchState.y>200)&&(TouchState.y<240)){
num1++;
flag=1;
GUI_TOUCH_GetState(&TouchState); //重新获得鼠标坐标值
while((TouchState.x>10)&&(TouchState.x<80)&&(TouchState.y>200)&&(TouchState.y<240))
GUI_TOUCH_GetState(&TouchState); //用于消抖(此时要点击空白处才算有效)
if(num1==7){
num1=0;
flag=0; //光标移动7次后,调试完毕,时钟重新运行
}
switch(num1){ //此处switch用处是对selct的光标进行特殊高亮显示
case 1:
GUI_SetColor(GUI_GREEN);
GUI_DispDecAt( year, 20,55,4);
break;
case 2:
GUI_SetColor(GUI_BLACK);
GUI_DispDecAt( year, 20,55,4);
GUI_SetColor(GUI_GREEN);
GUI_DispDecAt(month, 120,55,2);
break;
case 3:
GUI_SetColor(GUI_BLACK);
GUI_DispDecAt(month, 120,55,2);
GUI_SetColor(GUI_GREEN);
GUI_DispDecAt( day, 220,55,2);
break;
case 4:
GUI_SetColor(GUI_BLACK);
GUI_DispDecAt( day, 220,55,2);
GUI_SetColor(GUI_GREEN);
GUI_DispDecAt( hour, 20,155,2);
break;
case 5:
GUI_SetColor(GUI_BLACK);
GUI_DispDecAt( hour, 20,155,2);
GUI_SetColor(GUI_GREEN);
GUI_DispDecAt( minute, 120,155,2);
break;
case 6:
GUI_SetColor(GUI_BLACK);
GUI_DispDecAt( minute, 120,155,2);
GUI_SetColor(GUI_GREEN);
GUI_DispDecAt( second, 220,155,2);
break;
}
}
//点击add按键
if((TouchState.x>90)&&(TouchState.x<160)&&(TouchState.y>200)&&(TouchState.y<240){
switch(num1){
case 1:
year++;
if(year==2100)
year=2010;
GUI_DispDecAt( year, 20,55,4);
break;
case 2:
month++;
if(month==13)
month=1;
GUI_DispDecAt(month, 120,55,2);
break;
case 3:
day++;
if(day==31)
day=1;
GUI_DispDecAt( day, 220,55,2);
break;
case 4:
hour++;
if(hour==24)
hour=1;
GUI_DispDecAt( hour, 20,155,2);
break;
case 5:
minute++;
if(minute==60)
minute=1;
GUI_DispDecAt( minute, 120,155,2);
break;
case 6:
second++;
if(second==60)
second=1;
GUI_DispDecAt( second, 220,155,2);
break;
default:
break;
}
GUI_TOUCH_GetState(&TouchState);
while((TouchState.x>90)&&(TouchState.x<160)&&(TouchState.y>200)&&(TouchState.y<240))
GUI_TOUCH_GetState(&TouchState);
}
//点击red键
if((TouchState.x>170)&&(TouchState.x<250)&&(TouchState.y>200)&&(TouchState.y<240)){
switch(num1){
case 1:
year--;
if(year==2000)
year=2010;
GUI_DispDecAt( year, 20,55,4);
break;
case 2:
month--;
if(month==0)
month=12;
GUI_DispDecAt(month, 120,55,2);
break;
case 3:
day--;
if(day==0)
day=30;
GUI_DispDecAt( day, 220,55,2);
break;
case 4:
hour--;
if(hour==0)
hour=23;
GUI_DispDecAt( hour, 20,155,2);
break;
case 5:
minute--;
if(minute==0)
minute=59;
GUI_DispDecAt( minute, 120,155,2);
break;
case 6:
second--;
if(second==0)
second=59;
GUI_DispDecAt( second, 220,155,2);
break;
default:
break;
}
GUI_TOUCH_GetState(&TouchState);
while((TouchState.x>170)&&(TouchState.x<250)&&(TouchState.y>200)&&(TouchState.y<240))
GUI_TOUCH_GetState(&TouchState);
}
}
}
显示效果如下:
可以看到,功能实现了,不过关于鼠标的操作还是有点问题(其中由于对时钟处理有些问题(因为函数中稚只能使用getsystemtime类似的函数得到系统运行是的时间,所以用来定时很麻烦(也不知道这个系统有没有系统自带的定时器函数,呵呵)导致其中不得不加上延时函数,看到的鼠标顿一下又顿一下的))