Пример #1
0
bool FrameBuffer::open(void)
{
    if (!open_framebuffer())
        return false;

    if (!open_console())
        return false;

    return true;
}
Пример #2
0
int main()
{
	struct tsdev *ts;
	unsigned int i;
	int ret,count;
	int connect = 0;
	char buff[10]="";
	char myaddr[16] = "";
	char *fbuff;
	pthread_t ts_thread;
	char *tsdevice = "/dev/ts0";
	int read_flag;

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

	//open touchscreen device
	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);
	}

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

	/* button settings for server program 
	 * server program only have clear and exit button.
	 */
	memset(&buttons,0,sizeof(buttons));
	buttons[0].w  = 70;
	buttons[0].h  = 20;
	buttons[0].x = 40; buttons[0].y = 200;
	buttons[0].text = "Clear";
	buttons[1].w = 20;
	buttons[1].h = 20;
	buttons[1].x = 280; buttons[1].y = 20;
	buttons[1].text = "Exit";

	refresh_screen();
	//sleep(30);
	reset_ipaddr();
	//strcpy(myaddr,ipaddr[mylocation]);
	strcpy(myaddr,my_ipaddr);
#ifdef DEBUG
	printf("ipaddr[mylocation] : %s\n",ipaddr[mylocation]);
	printf("my_ipaddr : %s\n",my_ipaddr);
	printf("myaddr : %s\n",myaddr);
#endif

	serv_sock = tcp_server_listen(ip2port(myaddr,7777),2);
	if(serv_sock < 0)
	{
		perror("tcp_server_listen");
		close_framebuffer();
		exit(1);
	}
	else
	{
		printf("server started!!! Ip: %s Port : %d\n",myaddr,ip2port(myaddr,7777));
	}

	pthread_create(&ts_thread, NULL, read_ts,ts);
	while(1)
	{

		clnt_sock = tcp_server_accept(serv_sock);
		if(clnt_sock <0)
		{
			perror("tcp_server_accept");
			exit(1);
		}
		else{
			//connect = 1;
#ifdef DEBUG
			printf("accept successful!!\n");
#endif
		}

		while(1)
		{
			ret = read(clnt_sock,buff,10);
#ifdef DEBUG
			printf("buff = %s\n",buff);
#endif

			if(!strcmp(buff,"Merge"))
			{
				//merge mode
				buff[0] = '\0';
#ifdef DEBUG
				printf("Merge mode on\n");
				printf("is buff cleared ? : %s\n",buff);
#endif
				ret = write(clnt_sock,fbuffer,fix.smem_len);

				if(ret<=0)
				{
					perror("write");
					exit(1);
				}
#ifdef DEBUG
				else
				{
					printf("server sent : %d\n",ret);
				}
				sleep(1);
#endif
			}
			/*
			   else if(!strcmp(buff,"Send"))
			   {
			   buff[0] = '\0';
			   count=0;
			   read_flag=0;
			   while(!read_flag)
			   {
			   ret = read(clnt_sock,fbuff+count,fix.smem_len);
			   if(ret<=0)				
			   {
			   perror("read");
			   exit(1);
			   }
			   count+=ret;
			   printf(" read : %d\n",count);
			   if(count>=fix.smem_len)
			   {
			   read_flag = 1;
			   }
			   }
			   for(i=0;i<fix.smem_len;i++)
			   {
			   fbuffer[i]|=fbuff[i];
			   }

			   }
			   */
			   else if(!strcmp(buff,"Split"))
			   {
				   //split mode
				   buff[0] = '\0';
				   sleep(1);
#ifdef DEBUG
				   printf("Split mode on\n");
				   printf("is buff cleared ? : %s\n",buff);
#endif
			   }
			   else if(!strcmp(buff,"Exit"))
			   {
				   buff[0] = '\0';
				   sleep(1);
#ifdef DEBUG
				   printf("Exit\n");
				   printf("is buff cleared ? : %s\n",buff);
#endif
				   break;
			   }
			   else
			   {
				   buff[0] = '\0';
				   sleep(1);
				   //	continue;
				   break;
			   }

		}
		close(clnt_sock);
		pthread_cancel(ts_thread);
	}
	pthread_join(ts_thread, NULL);
	close(serv_sock);
}
Пример #3
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";
	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();
}
Пример #4
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();
}
Пример #5
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();
}