www.pudn.com > 03_touchscreen_input.rar > touch.c


#ifndef __INTELPXA255_TS_CAL_C
#define __INTELPXA255_TS_CAL_C

#include 
#include 
#include 
#include 
#include 
#include 
#include "touch.h"

int touchscreen_fd = 0;							/* touch screen device handle */				
ts_event_t	ts_CalPoints[CAL_POINT_NUM];	/* touch screen calibration pBuffer */

// Retrieve an average data from touch screen input device
int Cal_DataAvg(int ts_handler, ts_event_t * ts_avg, unsigned short max_num)
{
	ts_event_t *tmpDataArr;
	ts_event_t tmpData;
	unsigned short bp, i;
	unsigned short count;
	long tempX, tempY;
	int ret;
   
  static int curr_x = 0, curr_y = 0, curr_p = 0;
	static int got_curr_x = 0, got_curr_y = 0;
	int got_curr_p = 0;
	int next_x, next_y;
	int got_next_x = 0, got_next_y = 0;
	//int got_tstamp = 0;
   
  struct input_event ev;


	// Allocate a buffer for input data
	
	tmpDataArr = (ts_event_t *)malloc(max_num * sizeof(ts_event_t));
	if (tmpDataArr == NULL)
	{
		printf("Error: malloc failed.\n");
		return -1;
	}

//printf("malloc ok.\n");
	for (i = 0; i < max_num; i++)
	{
		tmpDataArr[i].x = 0;
		tmpDataArr[i].y = 0;
		tmpDataArr[i].pressure = 0;
		tmpDataArr[i].flag = -1;
	}
	// Read a set of data into buffer
//printf("x = tempX / count;
	ts_avg->y = tempY / count;
	ts_avg->pressure = 0xffff;

	// Release
	free(tmpDataArr);
}

int main()
{
	char * tsconf_name;
	Point Screen_Point[CAL_POINT_NUM];
	unsigned short x_max, y_max;
	unsigned short i;
  	FILE * fp;
	i = 0;
	
	touchscreen_fd = open(TOUCHSCREEN_DEV, O_RDONLY);
	if (touchscreen_fd < 0)
	{
		fprintf (stderr, "Cannot open touch screen device [%s].\n", TOUCHSCREEN_DEV);
        return -1;
    }
	else
		{
		fprintf (stderr, "the  touch screen device [%s]is opened.\n", TOUCHSCREEN_DEV);
             fprintf (stderr, "please touch the screen to test the driver is working \n");
	}
	
	while (1)
	{
		Cal_DataAvg(touchscreen_fd, &ts_CalPoints[i], 10);
		printf("ts_CalPoints[%d].x = %d\n", i, ts_CalPoints[i].x);
		printf("ts_CalPoints[%d].y = %d\n", i, ts_CalPoints[i].y);
		i++;
		if(i==10)
			i=0;
	}
	close(touchscreen_fd);
	return 0;
}

#endif	// __INTELPXA255_TS_CAL_C