Exemple #1
0
/*******************************************************************************
*	Description		:
*	Argurments		:
*	Return value	:
*	Modify			:
*	warning			:
*******************************************************************************/
int running_touch_calibrarion( void* ctx_t )
{

	struct NCA_TOUCH_CTX *ctx;

	if( ctx_t == NULL )
		return -1;
	else
		ctx = ctx_t;
	
	struct tsdev *ts;
	calibration cal;
	int cal_fd;
	char cal_buffer[256];
	char *tsdevice = NULL;
	char *calfile = NULL;
	unsigned int i;

	unsigned int x_fb_res = LCD_HEIGHT;
	unsigned int y_fb_res = LCD_WIDTH;

	unsigned int x_scr_res = LCD_WIDTH;
	unsigned int y_scr_res = LCD_HEIGHT;

	unsigned int x_margin = 50;
	unsigned int y_margin = 50;

	ts = ctx->dev;
	if(ts)
	{
		NC_RECT r = (NC_RECT){ 0, 0, LCD_WIDTH, LCD_HEIGHT };
		
		///////////////////////////////////////////////////////////////////////////////////
		
		printf("start Top Left\n");
		do
		get_sample (ts, &cal, 1, x_fb_res - x_margin, y_margin, "Top Left");
		while( !(cal.x [1] < 800 && cal.y [1] > 3200) );
		///////////////////////////////////////////////////////////////////////////////////
		
		printf("start Top right\n");
		do
			get_sample (ts, &cal, 2, x_fb_res-x_margin, y_fb_res-y_margin, "Top right");
		while( !(cal.x [2] < 800 && cal.y [2] < 800) );
		///////////////////////////////////////////////////////////////////////////////////

		printf("start Bot left\n");
		do
			get_sample (ts, &cal, 0, 50, 50, "Bot left");
		while( !(cal.x [0] > 3200 && cal.y [0] > 3200) );
		///////////////////////////////////////////////////////////////////////////////////

		printf("start Bot Right\n");
		do
			get_sample (ts, &cal, 3, 50, y_fb_res - 50, "Bot Right");
		while( !(cal.x [3] > 3200 && cal.y [3] < 800) );
		///////////////////////////////////////////////////////////////////////////////////

		printf("start Center\n");
		do
			get_sample (ts, &cal, 4, x_fb_res / 2,  y_fb_res / 2, "Center");
		while( !((cal.x [4] > 1500 && cal.x [4] < 2500) && (cal.y [4] > 1500 && cal.y [4] < 2500)) );
		///////////////////////////////////////////////////////////////////////////////////

		if( perform_calibration(&cal) )
		{
			mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
			printf ("Calibration constants: ");
			for (i = 0; i < 7; i++) printf("%d ", cal.a [i]);
			printf("\n");
			if ((calfile = getenv("TSLIB_CALIBFILE")) != NULL)
			{
				cal_fd = open (calfile, O_CREAT | O_RDWR, mode);
			}
			else
			{
				cal_fd = open ("/etc/pointercal", O_CREAT | O_RDWR, mode);
			}
			sprintf (cal_buffer,"%d %d %d %d %d %d %d",
								 cal.a[1], cal.a[2], cal.a[0],
								 cal.a[4], cal.a[5], cal.a[3], cal.a[6]);
			
			int size = strlen(cal_buffer) + 1;
			int wt	 = write( cal_fd, cal_buffer, size );			
			fprintf( stdout, "[%s:%d] %s. create touch calibration file\n", __FILE__, __LINE__, wt==size ? "SUCCESS" : "FAIL" );
			close( cal_fd );

			system("sync");
		}
		else
		{
			printf("Calibration failed.\n");
			return -1;
		}
		
	}
	else
	{
		printf("not ts open \n");
		return -1;
	}
	return 0;
}
static void calibration_data_post(rt_uint16_t x, rt_uint16_t y)
{
    if (calibration_ptr == RT_NULL)
        return;

    switch (calibration_ptr->step)
    {
    case CALIBRATION_STEP_LEFTTOP:
        cal_data->xfb[0] = CALIBRATION_WIDTH;
        cal_data->yfb[0] = CALIBRATION_HEIGHT;
        cal_data->x[0] = x;
        cal_data->y[0] = y;
        break;

    case CALIBRATION_STEP_RIGHTTOP:
        cal_data->xfb[1] = calibration_ptr->width - CALIBRATION_WIDTH;
        cal_data->yfb[1] =  CALIBRATION_HEIGHT;
        cal_data->x[1] = x;
        cal_data->y[1] = y;
        break;

    case CALIBRATION_STEP_LEFTBOTTOM:
        cal_data->xfb[3] = CALIBRATION_WIDTH;
        cal_data->yfb[3] = calibration_ptr->height - CALIBRATION_HEIGHT;
        cal_data->x[3] = x;
        cal_data->y[3] = y;
        break;

    case CALIBRATION_STEP_RIGHTBOTTOM:
        cal_data->xfb[2] = calibration_ptr->width - CALIBRATION_WIDTH;
        cal_data->yfb[2] = calibration_ptr->height - CALIBRATION_HEIGHT;
        cal_data->x[2] = x;
        cal_data->y[2] = y;
        break;

    case CALIBRATION_STEP_CENTER:
        /* calibration done */
    {
        rt_uint8_t i;
        struct rtgui_event_command ecmd;
        RTGUI_EVENT_COMMAND_INIT(&ecmd);
        ecmd.wid = calibration_ptr->win;
        ecmd.command_id = TOUCH_WIN_CLOSE;
        cal_data->xfb[4] = (calibration_ptr->width >> 1);
        cal_data->yfb[4] = (calibration_ptr->height >> 1);
        cal_data->x[4] = x;
        cal_data->y[4] = y;
        for (i = 0; i < 5; i++)
        {
            rt_kprintf("xfb[%d]:%d,yfb[%d]:%d,x[%d]:%d,y[%d]:%d\r\n", i, cal_data->xfb[i], i, cal_data->yfb[i], i, cal_data->x[i], i, cal_data->y[i]);
        }
        perform_calibration(cal_data);
        rtgui_send(calibration_ptr->app, &ecmd.parent, sizeof(struct rtgui_event_command));
    }
    calibration_ptr->step = 0;
    return;
    }

    calibration_ptr->step++;

    /* post command event */
    {
        struct rtgui_event_command ecmd;
        RTGUI_EVENT_COMMAND_INIT(&ecmd);
        ecmd.wid = calibration_ptr->win;
        ecmd.command_id = TOUCH_WIN_UPDATE;

        rtgui_send(calibration_ptr->app, &ecmd.parent, sizeof(struct rtgui_event_command));
    }
}
Exemple #3
0
int main()
{
	struct tsdev *ts;
	int fd;
	calibration cal;
	int cal_fd;
	char cal_buffer[256];
	char *tsdevice = NULL;
	char *calfile = NULL;
	int i;

	signal(SIGSEGV, sig);
	signal(SIGINT, sig);
	signal(SIGTERM, sig);

	if( (tsdevice = getenv("TSLIB_TSDEVICE")) != NULL ) {
		ts = ts_open(tsdevice,0);
	} else {
#if 0
#ifdef USE_INPUT_API
		ts = ts_open("/dev/input/event0", 0);
#else
		ts = ts_open("/dev/touchscreen/ucb1x00", 0);
#endif /* USE_INPUT_API */
#else
	ts = ts_open("/dev/input/event2", 0);
#endif
	}

	if (!ts) {
		perror("ts_open");
		exit(1);
	}
#if 0
	if (ts_config(ts)) {
		perror("ts_config");
		exit(1);
	}
#endif

	if (open_framebuffer()) {
		close_framebuffer();
		exit(1);
	}
	close_framebuffer();
	if (open_framebuffer()) {
		close_framebuffer();
		exit(1);
	}

	setcolors(0x48ff48,0x880000);

	put_string(xres/2,yres/4,"TSLIB calibration utility",1);
	put_string(xres/2,yres/4 + 20,"Touch crosshair to calibrate",1);

	printf("xres = %d, yres = %d\n",xres,yres);

// Read a touchscreen event to clear the buffer
	//getxy(ts, 0, 0);

// Now paint a crosshair on the upper left and start taking calibration
// data
	put_cross(50,50,1);
	getxy(ts, &cal.x[0], &cal.y[0]);
	put_cross(50,50,0);

	cal.xfb[0] = 50;
	cal.yfb[0] = 50;

	printf("Top left : X = %4d Y = %4d\n", cal.x[0], cal.y[0]);

	put_cross(xres - 50, 50, 1);
	getxy(ts, &cal.x[1], &cal.y[1]);
	put_cross(xres - 50, 50, 0);

	cal.xfb[1] = xres-50;
	cal.yfb[1] = 50;

	printf("Top right: X = %4d Y = %4d\n", cal.x[1], cal.y[1]);

	put_cross(xres - 50, yres - 50, 1);
	getxy(ts, &cal.x[2], &cal.y[2]);
	put_cross(xres - 50, yres - 50, 0);

	cal.xfb[2] = xres-50;
	cal.yfb[2] = yres-50;

	printf("Bot right: X = %4d Y = %4d\n", cal.x[2], cal.y[2]);

	put_cross(50, yres - 50, 1);
	getxy(ts, &cal.x[3], &cal.y[3]);
	put_cross(50, yres - 50, 0);

	cal.xfb[3] = 50;
	cal.yfb[3] = yres-50;

	printf("Bot left : X = %4d Y = %4d\n", cal.x[3], cal.y[3]);

	put_cross(xres/2, yres/2, 1);
	getxy(ts, &cal.x[4], &cal.y[4]);
	put_cross(xres/2, yres/2, 0);

	cal.xfb[4] = xres/2;
	cal.yfb[4] = yres/2;

	printf("Middle: X = %4d Y = %4d\n", cal.x[4], cal.y[4]);

	if(perform_calibration(&cal)) {
		printf("Calibration constants: ");
		for(i=0;i<7;i++) printf("%d ",cal.a[i]);
		printf("\n");
		if( (calfile = getenv("TSLIB_CALIBFILE")) != NULL) {
			cal_fd = open(calfile,O_CREAT|O_RDWR);
		} else {
			cal_fd = open("/etc/pointercal",O_CREAT|O_RDWR);
		}
		sprintf(cal_buffer,"%d %d %d %d %d %d %d\n",cal.a[1],cal.a[2],cal.a[0],cal.a[4],cal.a[5],cal.a[3],cal.a[6]);
		write(cal_fd,cal_buffer,strlen(cal_buffer)+1);
		close(cal_fd);	
	} else {
		printf("Calibration failed.\n");
	}

//	while (1) {
//		struct ts_sample samp;
//
//		if (ts_read_raw(ts, &samp, 1) < 0) {
//			perror("ts_read");
//			exit(1);
//		}
//
//		printf("%ld.%06ld: %6d %6d %6d\n", samp.tv.tv_sec, samp.tv.tv_usec,
//			samp.x, samp.y, samp.pressure);
//	}
	close_framebuffer();
}
int ts_test()
{
//	struct tsdev *ts;
	calibration cal;
	int cal_fd;
	char cal_buffer[256];
	char *tsdevice = NULL;
	char *calfile = NULL;
	unsigned int i;

	int xtemp,ytemp;
	int x,y;

  /* Clear the LCD */ 
  LCD_Clear(LCD_COLOR_WHITE);
	get_sample (&cal, 0, 50,        50,        "Top left");
//	clearbuf(ts);
  /* Clear the LCD */ 
//  LCD_Clear(LCD_COLOR_WHITE);
	get_sample (&cal, 1, XRES - 50, 50,        "Top right");
//	clearbuf(ts);
  /* Clear the LCD */ 
//  LCD_Clear(LCD_COLOR_WHITE);
	get_sample (&cal, 2, XRES - 50, YRES - 50, "Bot right");
//	clearbuf(ts);
  /* Clear the LCD */ 
//  LCD_Clear(LCD_COLOR_WHITE);
	get_sample (&cal, 3, 50,        YRES - 50, "Bot left");
//	clearbuf(ts);
  /* Clear the LCD */ 
//  LCD_Clear(LCD_COLOR_WHITE);
	get_sample (&cal, 4, XRES / 2,  YRES / 2,  "Center");

	if (perform_calibration (&cal)) {
		printf ("Calibration constants: ");
		for (i = 0; i < 7; i++) printf("%d ", cal.a [i]);
		printf("\n\r");
//		if ((calfile = getenv("TSLIB_CALIBFILE")) != NULL) {
//			cal_fd = open (calfile, O_CREAT | O_RDWR);
//		} else {
//			cal_fd = open ("/etc/pointercal", O_CREAT | O_RDWR);
//		}
		sprintf (cal_buffer,"%d %d %d %d %d %d %d",
			 cal.a[0], cal.a[1], cal.a[2],
			 cal.a[3], cal.a[4], cal.a[5], cal.a[6]);
		printf ("%d %d %d %d %d %d %d",
			 cal.a[1], cal.a[2], cal.a[0],
			 cal.a[4], cal.a[5], cal.a[3], cal.a[6]);
//		write (cal_fd, cal_buffer, strlen (cal_buffer) + 1);
//		close (cal_fd);
                i = 0;
	} else {
		printf("Calibration failed.\n\r");
		i = -1;
	}
	while(1)
	{
	getxy (&cal.x[0], &cal.y[0]);
	printf("before Calibration x = %d y=%d\n\r",cal.x[0],cal.y[0]);
	   		xtemp = cal.x[0];
			ytemp = cal.y[0];
			x = 	(int)(( cal.a[0] +
					cal.a[1]*xtemp + 
					cal.a[2]*ytemp ) / cal.a[6]);
			y =		(int)(( cal.a[3] +
					cal.a[4]*xtemp +
					cal.a[5]*ytemp ) / cal.a[6]);
	printf("after Calibration x = %d y=%d\n\r",x,y);
        LCD_Clear(LCD_COLOR_WHITE);
        LCD_DispNum(0,0,x,5,0);
        LCD_DispNum(0,16,y,5,0);
	}

//	close_framebuffer();
	return i;
}