📄 main.c.bak
字号:
/***************************************************************************\
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 "../src/gui/gui.h"
#include <string.h>
#include <stdio.h>
#include "inc/sys/tchScr.h"
#include "uhal/uhal.h"
#pragma import(__use_no_semihosting_swi) // ensure no functions that use semihosting
///******************任务定义***************///
/*OS_STK SYS_Task_Stack[STACKSIZE]= {0, }; //system task刷新任务堆栈
#define SYS_Task_Prio 1
void SYS_Task(void *Id);*/
OS_STK task1_Stack[STACKSIZE]={0, }; //Main_Test_Task堆栈
void Task1(void *Id); //Main_Test_Task
#define Task1_Prio 12
#define GPFDAT (*(volatile unsigned *)0x56000054)
#define ADS7843_PIN_PEN (1<<5)
#define TCHSCR_IsPenNotDown (GPFDAT&ADS7843_PIN_PEN)
extern OS_EVENT *pevent;
extern int x,y;
extern U32 mode;
extern void TchScr_GetScrXY(int *x, int *y);
extern void TchScr_init(void);
extern void irq_TCHSCR(void);
extern void LCD_Init(void);
extern void draw_gra(void);
extern void clearscreen(void);
void TchScr_Test(void);
U32 TchScr_GetOSXY(int *x, int *y);
void getkey(int x,int y);
///*****************事件定义*****************///
/////////////////////////////////////////////////////
// Main function. //
////////////////////////////////////////////////////
int main(void)
{
ARMTargetInit(); // do target (uHAL based ARM system) initialisation //
OSInit(); // needed by uC/OS-II //
LCD_Init();
clearscreen();
draw_gra();
TchScr_init();
OSTaskCreate(Task1, (void *)0, (OS_STK *)&task1_Stack[STACKSIZE-1], Task1_Prio);
pevent=OSMboxCreate((void*)NULL);
OSAddTask_Init(1);
OSStart(); // start the OS //
return 0;
}//main
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Task1(void *Id)
{
U16 timeout=0;
U8 err;
for(;;){
OSMboxPend(pevent,timeout,&err);
TchScr_Test();
getkey(x,y);
OSTimeDly(1000);
}
}
U32 TchScr_GetOSXY(int *x, int *y)
{//获得触摸点坐标并返回触摸动作
static U32 mode=0;
static int oldx,oldy;
int i,j;
for(;;){
if((mode!=TCHSCR_ACTION_DOWN) && (mode!=TCHSCR_ACTION_MOVE)){
if(!TCHSCR_IsPenNotDown){//有触摸动作
TchScr_GetScrXY(x, y);//得到触摸点坐标
for(i=0;i<40;i++){
if(TCHSCR_IsPenNotDown)//抬起
break;
//Delay(100);
hudelay(20);
}
if(i<40){ //在规定的双击时间之内抬起,检测是不是及时按下
for(i=0;i<60;i++){
if(!TCHSCR_IsPenNotDown){
if (i<10) {i=60;break;}//如果单击后很短时间内按下,不视为双击
mode=TCHSCR_ACTION_DBCLICK;
for(j=0;j<40;j++) hudelay(50);//检测到双击后延时,防止拖尾
break;
}
hudelay(20);
// Delay(100);
}
if(i==60) //没有在规定的时间内按下
mode=TCHSCR_ACTION_CLICK;
}
else{ //没有在规定的时间内抬起
mode=TCHSCR_ACTION_DOWN;
}
break;
}
}
else{
if(TCHSCR_IsPenNotDown){ //抬起
mode=TCHSCR_ACTION_UP;
*x=oldx;
*y=oldy;
return mode;
}
else{
TchScr_GetScrXY(x, y);
if(ABS(oldx-*x)>25 ||ABS( oldy-*y)>25){//有移动动作
mode=TCHSCR_ACTION_MOVE;
break;
}
}
}
//Delay(50);
hudelay(10);
}
oldx=*x;
oldy=*y;
return mode;
}
void TchScr_Test()
{
U32 mode;
int x,y;
Uart_Printf(0,"please touch the screen\n");
for(;;){
mode=TchScr_GetOSXY(&x, &y);
switch(mode){
case TCHSCR_ACTION_CLICK:
Uart_Printf(0,"Action=click:x=%d,\ty=%d\n",x,y);
break;
case TCHSCR_ACTION_DBCLICK:
Uart_Printf(0,"Action=double click:x=%d,\ty=%d\n",x,y);
break;
case TCHSCR_ACTION_DOWN:
Uart_Printf(0,"Action=down:x=%d,\ty=%d\n",x,y);
break;
case TCHSCR_ACTION_UP:
Uart_Printf(0,"Action=up:x=%d,\ty=%d\n",x,y);
break;
case TCHSCR_ACTION_MOVE:
Uart_Printf(0,"Action=move:x=%d,\ty=%d\n",x,y);
break;
}
hudelay(1000);
}
}
void getkey(int x,int y)
{
if((x>1)&(x<50)&(y>80)&(y<150))
{
Uart_SendByte(0,'1');
}
if((x>50)&(x<90)&(y>80)&(y<120))
{
Uart_SendByte(0,'2');
}
if((x>60)&(x<100)&(y>70)&(y<120))
{
Uart_SendByte(0,'3');
}
if((x>100)&(x<140)&(y>120)&(y<150))
{
Uart_SendString(0,"F1");
}
if((x>1)&(x<40)&(y>120)&(y<140))
{
Uart_SendByte(0,'4');
}
if((x>50)&(x<90)&(y>120)&(y<140))
{
Uart_SendByte(0,'5');
}
if((x>60)&(x<100)&(y>120)&(y<140))
{
Uart_SendByte(0,'6');
}
if((x>120)&(x<150)&(y>40)&(y<90))
{
Uart_SendString(0,"F2");
}
if((x>-5)&(x<50)&(y>80)&(y<100))
{
Uart_SendByte(0,'7');
}
if((x>60)&(x<80)&(y>60)&(y<90))
{
Uart_SendByte(0,'8');
}
if((x>110)&(x<130)&(y>25)&(y<40))
{
Uart_SendByte(0,'9');
}
if((x>140)&(x<200)&(y>15)&(y<30))
{
Uart_SendString(0,"F3");
}
if((x>25)&(x<60)&(y>35)&(y<70))
{
Uart_SendByte(0,'0');
}
if((x>70)&(x<120)&(y>25)&(y<50))
{
Uart_SendByte(0,'*');
}
if((x>125)&(x<150)&(y>0)&(y<20))
{
Uart_SendByte(0,'#');
}
if((x>150)&(x<200)&(y>-10)&(y<20))
{
Uart_SendString(0,"F4");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -