⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 choose.h

📁 it is about embeded system
💻 H
字号:
#ifndef _CHOOSE_H
#define _CHOOSE_H
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<stdlib.h>
#include<stdio.h>
#define  MAX_ANGLE  10 //allow max warp angle  unit :angle
#define MAX_ALARMANGLE 3 //allow max warp angle when alarm  unit angle
#define  INTERVAL_TIME 5000  //interval  of note time/  unit :ms
#define MAX_TIME 2000     //times of found correct angle ,0.1s one time 
volatile int g_speech_touch;
int  touch_position();  //返回触摸屏数据1~5
#include<sys/types.h>
#include<sys/stat.h>
#include <asm/arch/hardware.h>
#include <asm/irq.h>
#include<fcntl.h>
#include<time.h>
#include<stdlib.h>
#include<stdio.h>

#include<stdio.h>
#include<stdlib.h>
#include<pthread.h>

#define TS_DEVICE_NAME "/dev/touchscreen/0raw"
#define MAXX	3400 
#define MAXY	3600
#define MINX	240
#define MINY	450
#define LFA	(MINX+(MAXX-MINX)/6)
#define RFA	(MINX+(MAXX-MINX)*5/6)
#define MYA     (MINY+(MAXY-MINY)/2)
#define TYA	(MINY+(MAXY-MINY)*9/10)
#define BYA	(MINY+(MAXY-MINY)/10)
#define MXA    	(MINX+(MAXX-MINX)/2)



int touch_in_which_area(TS_RET *p)
{/*判断点了触摸屏具体位置*/
	if(p->x<LFA)
	{
		if(p->y>MYA)
			return 1;
		return 2;
	}
	if(p->x>RFA)
	{
		if(p->y>MYA)
			return 4;
		return 3;
	}
	return 5;
	
}

int  touch_position()
{
	int ts_fd,top_ret;
	TS_RET ts_ret;
	ts_fd=open(TS_DEVICE_NAME,O_RDONLY);
	if(ts_fd<0)
	{
		printf("open device error!!");
		exit(1);
	}
	printf("ts_fd=%d\n",ts_fd);
	printf("start touch\n");
	while(1)
	{
		read(ts_fd,&ts_ret,1);
		if(ts_ret.pressure==0)
			break;
	}
	printf("end touch\n");
	top_ret=touch_in_which_area(&ts_ret);
	
	close(ts_fd);

	return top_ret;
}

void * touch_op(void *data)
{
	pthread_t *th_speech_back=(pthread_t *)data;
	
	g_speech_touch=touch_position();
	
	if(*th_speech_back)
		pthread_cancel(*th_speech_back);
}
void *SpeechBack(void *data)
{
   char get_speech;
   int speechback;
 pthread_t *th_touch_op=(pthread_t *)data;
	     get_speech=speech(0x01);
		 printf("data back 0x%x",get_speech);
	
	 if (get_speech==0x01)
	  speechback=1;
	  else
	 if (get_speech==0x02)
	   speechback=2;
	   else if (get_speech==0x03)
	         speechback=3;
			 else if (get_speech==0x04)
			         speechback=4;
					 else if(get_speech==0x05)
	                       speechback=5;
						   else speechback=11;
	 g_speech_touch=speechback;
	 if(*th_touch_op)
		pthread_cancel(*th_touch_op);
					
}
void SlectBack()
 {
   void *retval;
     pthread_t th_touch_op=-1,th_speech_back=-1;
   	 pthread_create(&th_touch_op, NULL, touch_op, (void *)&th_speech_back);
	 pthread_create(&th_speech_back, NULL, SpeechBack,(void *)&th_touch_op);
//	 printf("***********%d\n",g_speech_touch);
	 pthread_join(th_touch_op, &retval);
     pthread_join(th_speech_back, &retval);
	 printf("__tp%d\n",th_touch_op);
     printf("__sb%d\n",th_speech_back);
 } 

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -