static void get_sample (calibration *cal,
			int index, int x, int y, char *name)
{
	static int last_x = -1, last_y;

//	if (last_x != -1) {
//#define NR_STEPS 10
//		int dx = ((x - last_x) << 16) / NR_STEPS;
//		int dy = ((y - last_y) << 16) / NR_STEPS;
//		int i;
//		last_x <<= 16;
//		last_y <<= 16;
//		for (i = 0; i < NR_STEPS; i++) {
//			put_cross (last_x >> 16, last_y >> 16, 2 | XORMODE);
//			uDelay (1000);
//			put_cross (last_x >> 16, last_y >> 16, 2 | XORMODE);
//			last_x += dx;
//			last_y += dy;
//		}
//	}

	put_cross(x, y, 2 | XORMODE);
	getxy (&cal->x [index], &cal->y [index]);
	put_cross(x, y, 2 | XORMODE);
//	Delay (300);

	last_x = cal->xfb [index] = x;
	last_y = cal->yfb [index] = y;

	printf("%s : LCD X = %4d Y = %4d\n\r", name, cal->xfb [index], cal->yfb [index]);
	printf("%s : X = %4d Y = %4d\n\r", name, cal->x [index], cal->y [index]);
}
Beispiel #2
0
static int verify(int xres, int yres)
{
	struct lcd_s *lcd = lcd_get(NULL);
	int x, y, ret, event = PDE_NONE;
	dot_t p;

	//mid point
	xres >>= 1;
	yres >>= 1;
	yres -= 32;
	
	//output red&green cross
	lcd_set_fgcolor(lcd, RED);
	put_cross(lcd, xres-32, yres);
	lcd_set_fgcolor(lcd, GREEN);
	put_cross(lcd, xres+32, yres);
	lcd_set_fgcolor(lcd, LCD_FGCOLOR_DEF);
	
	x = 0;
	y = 0;
	while(1) {
		event = pd_GetEvent(&p);
		if(event == PDE_NONE)
			continue;
		
		if(x + y != 0) {
			clr_cross(lcd, x, y);
		}
		
		x = p.x;
		y = p.y;
		
		if(y > yres - 16 && y < yres + 16) {
			//red cross is pressed?
			if(x > xres - 32 - 16 && x < xres - 32 + 16) {
				ret = -1;
				break;
			}
		
			//green cross is pressed?
			if(x > xres + 32 - 16 && x < xres + 32 + 16) {
				ret = 0;
				break;
			}
		}
		
		//display cross at the touch point
		put_cross(lcd, x, y);
		printf("pd test: %d %d\n", x, y);
	}
	
	return ret;
}
Beispiel #3
0
static void get_sample (pdl_cal_t *cal, int index, int x, int y, char *name)
{
	struct lcd_s *lcd = lcd_get(NULL);
	put_cross (lcd, x, y);
	getxy (&cal->x [index], &cal->y [index]);
	clr_cross(lcd, x, y);
	mdelay(1000);

	cal->xfb [index] = x;
	cal->yfb [index] = y;
	printf ("%s : (%4d,%4d)->(%4d,%4d)\n", name, x, y, cal->x [index], cal->y [index]);
}
int main()
{
	struct tsdev *ts;
	int x, y;
	unsigned int i;
	unsigned int mode = 0;

	char *tsdevice=NULL;

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

	if ((tsdevice = getenv("TSLIB_TSDEVICE")) == NULL) {
#ifdef USE_INPUT_API
		tsdevice = strdup ("/dev/input/event0");
#else
		tsdevice = strdup ("/dev/touchscreen/ucb1x00");
#endif /* USE_INPUT_API */
        }

	ts = ts_open (tsdevice, 0);

	if (!ts) {
		perror (tsdevice);
		exit(1);
	}

	if (ts_config(ts)) {
		perror("ts_config");
		exit(1);
	}

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

	x = xres/2;
	y = yres/2;

	for (i = 0; i < NR_COLORS; i++)
		setcolor (i, palette [i]);

	/* Initialize buttons */
	memset (&buttons, 0, sizeof (buttons));
	/*buttons [0].w = buttons [1].w = xres / 4;
	buttons [0].h = buttons [1].h = 20;
	buttons [0].x = xres / 4 - buttons [0].w / 2;
	buttons [1].x = (3 * xres) / 4 - buttons [0].w / 2;
	buttons [0].y = buttons [1].y = 10;
	buttons [0].text = "Drag";
	buttons [1].text = "Draw";
	buttons [0].*/

	/*weight height*/
	for(i=1; i<17; i++){
		buttons [i].w = xres / 7;
		buttons [i].h = yres / 5;
	}	

	buttons [0].w = (2*xres/7) + (xres/49);
	buttons [0].h = yres / 5;

	/*result a half of xres and position is center*/
	buttons [17].w = xres / 2;
	buttons [17].h = yres / 5;
	buttons [17].text = "";

	/*value*/
	buttons [0].text = "0";
	buttons [1].text = "1";
	buttons [2].text = "2";
	buttons [3].text = "3";
	buttons [4].text = "4";
	buttons [5].text = "5";
	buttons [6].text = "6";
	buttons [7].text = "7";
	buttons [8].text = "8";
	buttons [9].text = "9";
	buttons [10].text = "+";
	buttons [11].text = "-";
	buttons [12].text = "*";
	buttons [13].text = "/";
	buttons [14].text = "=";
	buttons [15].text = "C";
	buttons [16].text = "D";

	/*
	 *800 * 480 
	 *
	 *such design: the y-blank is yres/25 = 96px, x-blank is xres/49 = 114px; 
	 * */
	
	/*
	 *
	 *	   	17
	 *15 16 10 11 12 13 
	 *1  2  3  4  5  14
	 *6  7  8  9	0  
	 *
	 * */

	/*the x position of buttons*/
	buttons [15].x = buttons [1].x = buttons [6].x = xres / 49;
	buttons [16].x = buttons [2].x = buttons [7].x = (xres/7) + (2*xres/49);
	buttons [10].x = buttons [3].x = buttons [8].x = (2*xres/7) + (3*xres/49);
	buttons [11].x = buttons [4].x = buttons [9].x = (3*xres/7) + (4*xres/49);
	buttons [12].x = buttons [5].x = buttons [0].x = (4*xres/7) + (5*xres/49);
	buttons [13].x = buttons [14].x = (5*xres/7) + (6*xres/49);

	/*the y position of buttons*/
	buttons [15].y =buttons [16].y =buttons [10].y =buttons [11].y =buttons [12].y = buttons [13].y = (yres/5) + (2*yres/25);
	buttons [1].y =buttons [2].y =buttons [3].y =buttons [4].y =buttons [5].y = buttons [14].y = (2*yres/5) + (3*yres/25);
	buttons [6].y =buttons [7].y =buttons [8].y =buttons [9].y =buttons [0].y = (3*yres/5) + (4*yres/25);

	/*result center*/
	buttons [17].x = xres / 4;
	buttons [17].y = yres / 25;

	/*refresh*/
	refresh_screen ();

	while (1) {
		struct ts_sample samp;
		int ret;

		// Show the cross 
		if ((mode & 15) != 1)
			put_cross(x, y, 2 | XORMODE);

		ret = ts_read(ts, &samp, 1);

		// Hide it 
		if ((mode & 15) != 1)
			put_cross(x, y, 2 | XORMODE);

		if (ret < 0) {
			perror("ts_read");
			close_framebuffer();
			exit(1);
		}

		if (ret != 1)
			continue;

		for (i = 0; i < NR_BUTTONS; i++)
			if (button_handle (&buttons [i], &samp))
				switch (i) {
				case 0:
					mode = 0;
					refresh_screen ();
					break;
				case 1:
					mode = 1;
					refresh_screen ();
					break;
				}

		printf("%ld.%06ld: %6d %6d %6d\n", samp.tv.tv_sec, samp.tv.tv_usec,
			samp.x, samp.y, samp.pressure);

		if (samp.pressure > 0) {
			if (mode == 0x80000001)
				line (x, y, samp.x, samp.y, 2);
			x = samp.x;
			y = samp.y;
			mode |= 0x80000000;
		} else
			mode &= ~0x80000000;
	}
	close_framebuffer();
}
Beispiel #5
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();
}
Beispiel #6
0
int main()
{
	struct tsdev *ts;
	int x, y;
	unsigned int i;
	unsigned int mode = 0;

	char *tsdevice=NULL;

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

	if ((tsdevice = getenv("TSLIB_TSDEVICE")) == NULL) {
#ifdef USE_INPUT_API
		tsdevice = strdup ("/dev/input/event0");
#else
		tsdevice = strdup ("/dev/touchscreen/ucb1x00");
#endif /* USE_INPUT_API */
        }

	ts = ts_open (tsdevice, 0);

	if (!ts) {
		perror (tsdevice);
		exit(1);
	}

	if (ts_config(ts)) {
		perror("ts_config");
		exit(1);
	}

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

	x = xres/2;
	y = yres/2;

	for (i = 0; i < NR_COLORS; i++)
		setcolor (i, palette [i]);

	/* Initialize buttons */
	memset (&buttons, 0, sizeof (buttons));
	buttons [0].w = buttons [1].w = xres / 4;
	buttons [0].h = buttons [1].h = 20;
	buttons [0].x = xres / 4 - buttons [0].w / 2;
	buttons [1].x = (3 * xres) / 4 - buttons [0].w / 2;
	buttons [0].y = buttons [1].y = 10;
	buttons [0].text = "Drag";
	buttons [1].text = "Draw";

	refresh_screen ();

	while (1) {
		struct ts_sample samp;
		int ret;

		/* Show the cross */
		if ((mode & 15) != 1)
			put_cross(x, y, 2 | XORMODE);

		ret = ts_read(ts, &samp, 1);

		/* Hide it */
		if ((mode & 15) != 1)
			put_cross(x, y, 2 | XORMODE);

		if (ret < 0) {
			perror("ts_read");
			close_framebuffer();
			exit(1);
		}

		if (ret != 1)
			continue;

		for (i = 0; i < NR_BUTTONS; i++)
			if (button_handle (&buttons [i], &samp))
				switch (i) {
				case 0:
					mode = 0;
					refresh_screen ();
					break;
				case 1:
					mode = 1;
					refresh_screen ();
					break;
				}

		printf("%ld.%06ld: %6d %6d %6d\n", samp.tv.tv_sec, samp.tv.tv_usec,
			samp.x, samp.y, samp.pressure);

		if (samp.pressure > 0) {
			if (mode == 0x80000001)
				line (x, y, samp.x, samp.y, 2);
			x = samp.x;
			y = samp.y;
			mode |= 0x80000000;
		} else
			mode &= ~0x80000000;
	}
	close_framebuffer();
}