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

📄 tbctl1.c

📁 一份介绍在S3C2410上液晶屏驱动程序的实现
💻 C
字号:
/* * * Copyright (c) 2004  DMC Co., Ltd. *  * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: *  * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. *  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL * THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. *  * Except as contained in this notice, the name of the DMC Co., Ltd shall not  * be used in advertising or otherwise to promote the sale, use or other dealings * in this Software without prior written authorization from DMC Co., Ltd. *//* * EUC * tab=4 */#include <X11/Xlib.h>#include <X11/Xutil.h>#include <X11/cursorfont.h>#include <stdio.h>#include <sys/wait.h>#include "tb.h"#include "../vers.h"#define	CALIB_SET_234569	0int main(int argc,char *argv[]);void prhelp();void domain();int run_exec(int cmd);#define	CMD_TBCALIB		0#define	CMD_TBTEST		1#define	CMD_SELECTOR	2int find_ps(char *str);int find_str(char *str,char *s);int do_find_exec(char *av[],int *pid);int pid;int fork_cur_dir = false;#define	S_RATE_GROUP		1int srate = 0;char *sratetb[] = { "30 p/s","50 p/s","80 p/s","100 p/s","130 p/s","150 p/s",NULL };#define	B_DOWN_BELL		1#define	B_UP_BELL		2int touchbell = B_DOWN_BELL|B_UP_BELL;char *belltb[] = { "Touch Down Beep on","Touch Up Beep on",NULL };#define	CALIB_POINT_GROUP	2int calib_point_num = 2;#if CALIB_SET_234569char *calibtb[] = { "2 points","3 points","4 points","5 points","6 points","9 points",NULL };#elsechar *calibtb[] = { "2 points",NULL };#endif#define	CALIB_TIMOUT_GROUP	3int calib_timeout = 10;char *totb[] = { "10 sec","20 sec","60 sec",NULL };int main(int argc,char *argv[]){	setbuf(stdin,0);	setbuf(stdout,0);	if( argc >= 2 && argv[1][0] == '-' )	{		switch( argv[1][1] )		{		case	'c':			fork_cur_dir = true;			break;		case	'?':		default:			prhelp();			exit(0);		}	}	domain();	return(0);}void prhelp(){	fprintf(stderr,"Syntax:tbctl {<Option>} \n");	fprintf(stderr,"Function: %s DMC touch-panel Control Main on X-Window\n",ProductName);	fprintf(stderr,"Option:\n");	fprintf(stderr,"    -?     help\n");	exit(0);}void domain(){uWindowPtr win;uColor fgcolor,bgcolor;int btnum[10];uControlPtr ctl[50];int ctlnum;int srate_base,bell_base;XEvent ev;Cursor cs;uRect r;int end,i,x,y,w,h,ww,x1,y1,y2,base;KeySym key;char s[100];	init_ulib();	get_display_rect(&r);	w = 330;#if	CALIB_SET_234569	h = 490;#else	h = 420;#endif	x = (r.width/2) - (w/2);	y = (r.height/4) - (h/2);	if( y <= 10 )		y = 50;	set_rect(&r,x,y,w,h);	fgcolor = BlackPixel(gDisp,0);	bgcolor = get_color(0xe000,0xe000,0xe000);	sprintf(s,"%s Control Main",ProductName);	win = new_window(&r,s,fgcolor,bgcolor,false);	// +----------------------------------------------------+	// |                                          Ver.1.0.1 |	// | < Sampling Rate >      < Sound >                   | <-- y1	// |      30 p/s         Touch Down Beep on             |	// |      50 p/s         Touch Up Beep on               |	// |      80 p/s                                        |	// |     100 p/s                                        |	// |     130 p/s                                        |	// |     150 p/s                                        |	// | +---------------------+ +------------------------+ |	// | |       Apply         | |       Test...          | |	// | +---------------------+ +------------------------+ |	// | +---------------------+                            |	// | |    Run Selector     |                            |	// | +---------------------+                            |	// | < Calibration Points > < Calibration Time Out >    | <-- y1	// |     2 points              10 sec                   |	// |                           20 sec                   |	// |                           60 sec                   |	// | +------------------------------------------------+ |	// | |               Calibration...                   | |	// | +------------------------------------------------+ |	// +----------------------------------------------------+	//   |	//   x1	XMoveWindow(gDisp,win->win,x,y);	x1 = x = (w/2) - ((w-10)/2);	y = 5;	w -= 10;	h = 25;	ctlnum = 0;	strcpy(s,TBCTL_VERSION);	w = get_text_width(win,s);	set_rect(&r,r.width-w-10,y,w,h);	ctl[ctlnum++] = new_control(win,PT_STEXT,s,&r,STATE_LEFT,0);	y += 20;	y1 = y;	strcpy(s,"< Sampling Rate >");	w = get_text_width(win,s);	set_rect(&r,x,y,w,h);	ctl[ctlnum++] = new_control(win,PT_STEXT,s,&r,STATE_LEFT,0);	ww = get_text_width(win,sratetb[0]) + 20;	x = x + (w/2) - (ww/2);	for( i=0,srate_base=base=ctlnum ; sratetb[i] ; i++ )	{		y += (20 + 5);		set_rect(&r,x,y,w,h);		ctl[ctlnum++] = new_control(win,PT_RADIO,sratetb[i],&r,STATE_OFF,S_RATE_GROUP);		if( srate == i )			ctl[base+i]->state = STATE_ON;	}	y += (20 + 5);	y2 = y;	x = x1 + w + 10;	y = y1;	strcpy(s,"      < Sound >      ");	w = get_text_width(win,s);	set_rect(&r,x,y,w,h);	ctl[ctlnum++] = new_control(win,PT_STEXT,s,&r,STATE_LEFT,0);	ww = get_text_width(win,belltb[0]) + 20;	x = x + (w/2) - (ww/2);	for( i=0,bell_base=base=ctlnum ; belltb[i] ; i++ )	{		y += (20 + 5);		set_rect(&r,x,y,w,h);		ctl[ctlnum++] = new_control(win,PT_CKBOX,belltb[i],&r,STATE_OFF,0);		if( touchbell & (1<<i) )			ctl[base+i]->state = STATE_ON;	}	y += (20 + 5);	if( y2 < y )		y2 = y;	get_win_rect(&r,win);	x = x1;	y = y2;	w = (r.width/2) - 10;	h = 25;	set_rect(&r,x,y,w,h);	btnum[0] = ctlnum;	ctl[ctlnum++] = new_control(win,PT_BUTTON,"Apply",&r,STATE_OFF,0);	x += w + 10;	set_rect(&r,x,y,w,h);	btnum[1] = ctlnum;	ctl[ctlnum++] = new_control(win,PT_BUTTON,"Test...",&r,STATE_OFF,0);	x = x1;	y += 25;	y += 5;	set_rect(&r,x,y,w,h);	btnum[2] = ctlnum;	ctl[ctlnum++] = new_control(win,PT_BUTTON,"Run Selector",&r,STATE_OFF,0);	x = x1;	y += (25+5);	y += 10;	get_win_rect(&r,win);	w = r.width - 10;	set_rect(&r,x,y,w,0);	ctl[ctlnum++] = new_control(win,PT_LINE,"line",&r,STATE_OFF,0);	y += 10;	y1 = y;	strcpy(s,"< Calibration Points >");	w = get_text_width(win,s);	set_rect(&r,x,y,w,h);	ctl[ctlnum++] = new_control(win,PT_STEXT,s,&r,STATE_LEFT,0);	ww = get_text_width(win,calibtb[0]) + 20;	x = x + (w/2) - (ww/2);	for( i=0,base=ctlnum ; calibtb[i] ; i++ )	{		y += (20 + 5);		set_rect(&r,x,y,w,h);		ctl[ctlnum++] = new_control(win,PT_RADIO,calibtb[i],&r,STATE_OFF,CALIB_POINT_GROUP);		if( calib_point_num == atoi(calibtb[i]) )			ctl[base+i]->state = STATE_ON;	}	y2 = y;	x = x1 + w + 10;	y = y1;	strcpy(s,"< Calibration Time Out >");	w = get_text_width(win,s);	set_rect(&r,x,y,w,h);	ctl[ctlnum++] = new_control(win,PT_STEXT,s,&r,STATE_LEFT,0);	ww = get_text_width(win,totb[0]) + 20;	x = x + (w/2) - (ww/2);	for( i=0,base=ctlnum ; totb[i] ; i++ )	{		y += (20 + 5);		set_rect(&r,x,y,w,h);		ctl[ctlnum++] = new_control(win,PT_RADIO,totb[i],&r,STATE_OFF,CALIB_TIMOUT_GROUP);		if( calib_timeout == atoi(totb[i]) )			ctl[base+i]->state = STATE_ON;	}	y = y2 >= y ? y2 : y;	x = x1;	y += (25 + 5);	get_win_rect(&r,win);	w = r.width - 10;	set_rect(&r,x,y,w,h);	btnum[3] = ctlnum;	ctl[ctlnum++] = new_control(win,PT_BUTTON,"Calibration...",&r,STATE_OFF,0);	ctl[ctlnum] = NULL;	if( ctlnum >= (sizeof(ctl)/sizeof(uControlPtr)) )	{		printf("BUFFER ERROR\n");		exit(0);	}	XSelectInput(gDisp,win->win,NormalMask);	draw_control(ctl,ctlnum);	open_xinput_driver("DMC");	pid = -1;	for( end=false ; !end ; )	{		if( pid != -1 )		{			if( waitpid(pid,NULL,WNOHANG) == pid )				pid = -1;;		}		XNextEvent(gDisp,&ev);		switch( ev.type )		{		case	KeyPress:			if( XLookupString(&ev.xkey,s,10,&key,NULL) >= 1 )			{				switch( s[0] )				{					case 'e': end = true;		break;				}			}			break;		case	ButtonPress:			ctl_mouse_on(ctl,ctlnum,&ev);			break;		case	ButtonRelease:			i = ctl_mouse_off(ctl,ctlnum,&ev);			if( i == btnum[0] )		// set button			{				cs = XCreateFontCursor(gDisp,XC_clock);				XDefineCursor(gDisp,win->win,cs);				XFlush(gDisp);				i = find_radio_group_on(ctl,ctlnum,S_RATE_GROUP);				// ++++++++++++ set sample rate ++++++++++++++++				y2 = i - srate_base;				if( set_samp_rate(y2) == -1 )				{					XUndefineCursor(gDisp,win->win);					msgbox("Error","set error",MB_OK);					break;				}				srate = y2;				// ++++++++++++ set beep ++++++++++++++++				if( ctl[bell_base+0]->state == STATE_ON )					y2 |= B_DOWN_BELL;				else					y2 &= (~B_DOWN_BELL);				if( ctl[bell_base+1]->state == STATE_ON )					y2 |= B_UP_BELL;				else					y2 &= (~B_UP_BELL);				set_beep(1,(y2&B_DOWN_BELL?1:0));				set_beep(0,(y2&B_UP_BELL?1:0));				touchbell = y2;				// ++++++++++++ do reset ++++++++++++++++				sleep(2);				reset_tb();				XUndefineCursor(gDisp,win->win);			}			else if( i == btnum[1] )	// test button			{				pid = run_exec(CMD_TBTEST);			}			else if( i == btnum[2] )	// selector button			{				pid = run_exec(CMD_SELECTOR);			}			else if( i == btnum[3] )	// calib button			{				i = find_radio_group_on(ctl,ctlnum,CALIB_POINT_GROUP);				calib_point_num = atoi(ctl[i]->s);				i = find_radio_group_on(ctl,ctlnum,CALIB_TIMOUT_GROUP);				calib_timeout = atoi(ctl[i]->s);				pid = run_exec(CMD_TBCALIB);			}			break;		case	MotionNotify:		case	LeaveNotify:			break;		case	Expose:	/* = window draw */			draw_control(ctl,ctlnum);			break;		case	ClientMessage:			if( ev.xclient.message_type == win->a1 && ev.xclient.data.l[0] == win->a2 )				end = true;			break;		case	DestroyNotify:			end = true;			break;		}	}	destroy_window(win);	term_ulib();}int run_exec(int cmd){char s[100],path[100];	path[0] = 0;	if( fork_cur_dir )		strcpy(path,"./");#if 1	switch( cmd )	{	case	CMD_TBCALIB:		sprintf(s,"%stbcalib %d %d &",path,calib_point_num,calib_timeout);		break;	case	CMD_TBTEST:		sprintf(s,"%stbtest &",path);		break;	case	CMD_SELECTOR:		if( find_ps("tbselector") )		{			msgbox("Warning!!","Don't run at same time",MB_OK);			return(-1);		}		sprintf(s,"%stbselector &",path);		break;	default:		return(-1);	}	system(s);	return(-1);#elsechar *av[10];	switch( cmd )	{	case	CMD_TBCALIB:		sprintf(&s[0],"%stbcalib",path);		av[0] = &s[0];		sprintf(&s[15],"%d",calib_point_num);		av[1] = &s[15];		sprintf(&s[30],"%d",calib_timeout);		av[2] = &s[30];		av[3] = NULL;		break;	case	CMD_TBTEST:		sprintf(s,"%stbtest",path);		av[0] = s;		av[1] = NULL;		break;	case	CMD_SELECTOR:		if( find_ps("tbselector") )		{			msgbox("Warning!!","Don't run at same time",MB_OK);			return(-1);		}		sprintf(s,"%stbselector",path);		av[0] = s;		av[1] = NULL;		break;	default:		return(-1);	}	if( (pid == fork()) == -1 )		return(-1);	if( pid == 0 )	{		execv(av[0],av);		exit(1);	}	printf("fork [%s]\n",av[0]);	return(pid);#endif}int find_ps(char *str){char *av[3];int i,len,pid;int pfd;char c,s[256];	av[0] = "ps";	av[1] = "-A";	av[2] = 0;	if( (pfd = do_find_exec(av,&pid)) < 0 )		return(false);	for( i=0,len=0 ; ; )	{		if( read(pfd,&c,1) <= 0 )		{			close(pfd);			return(false);		}		switch( c )		{			case	0x0a:				if( len > 0 )				{					i++;					if( find_str(str,s) )						return(true);				}				len = 0;				s[len] = 0;				break;			case	0x0d:				len = 0;				s[len] = 0;				break;			default:				if( len >= (256-10) )					break;				s[len++] = c;				s[len] = 0;				break;		}	}}int find_str(char *str,char *s){int i;	for( ; *s ; s++ )	{		for( i=0 ; str[i] ; i++ )		{			if( str[i] != s[i] )				break;		}		if( str[i] == 0 )			return(true);	}	return(false);}int do_find_exec(char *av[],int *pid){int pfd[2];	if( pipe(pfd) < 0 )		return(-1);	if( (*pid = fork()) < 0 )		return(-1);	if( *pid > 0 )	{		close(pfd[1]);		return(pfd[0]);	}	close(1);	dup(pfd[1]);	close(2);	dup(pfd[1]);	close(pfd[0]);	close(pfd[1]);	execvp(av[0],av);	perror(av[0]);	exit(1);}

⌨️ 快捷键说明

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