📄 tpcfg.c
字号:
#include <stdio.h>#include <errno.h>#include <unistd.h>#include <fcntl.h>#include "device.h"//#ifdef S3C44B0_ADS7843_MOUSE#include "touchscreen_s3c44b0_ads7843.h"//#endifstatic int pd_fd = -1;extern SCREENDEVICE scrdev;/*modify by kh 2003_12_21*/struct tpmark { int ltx; int lty; int rbx; int rby; }tpMark;MOUSEDEVICE mymousedev;static int rx,ry;//任意点坐标static int lt_x,lt_y;//左上角static int rb_x,rb_y;//右下角static char sure1,sure2,sure;FILE *tpmap;//存放校验坐标static int x,y,z,t;static int Open(MOUSEDEVICE *pmd);static void Close(void);static int Read(MWCOORD *px, MWCOORD *py, MWCOORD *pz, int *pb, int mode);static int GetButtonInfo(void);static void GetDefaultAccel(int *pscale,int *pthresh);static void checkpoint();static void savedata();int main(){ printf("\n This program will guid to initial your touchpad.\n"); checkpoint(); printf("Are you sure?(input y/n)\n"); //savedata(); while(1) { scanf("%c",&sure); if((sure=='y')||(sure=='Y')) { savedata(); break; } if((sure=='n')||(sure=='N')) { printf("your touchscreen had't been initial,Please initial again!\n"); exit(0); } printf("Please input y/n!\n"); } return 0; /*if(!((sure=='y')||(sure=='Y')||(sure=='n')||(sure=='N')))*/}static int Open(MOUSEDEVICE *pmd){ if((pd_fd = open(TS_DEVICE_FILE, O_NONBLOCK)) < 0) { EPRINTF("Error %d opening %s touchscreen device [%s]\n", errno, TS_DEVICE, TS_DEVICE_FILE); return -1; } //GdHideCursor(&scrdev); return pd_fd;}static void Close(void){ // Close the touch panel device. if(pd_fd < 0) return; close(pd_fd); pd_fd = -1;}static int GetButtonInfo(void){ // get "mouse" buttons supported return MWBUTTON_L;}static void GetDefaultAccel(int *pscale,int *pthresh){ *pscale = 3; *pthresh = 5;}static int Read(MWCOORD *px, MWCOORD *py, MWCOORD *pz, int *pb, int mode){ struct ts_event event; int bytes_read; // read a data point bytes_read = read(pd_fd, &event, sizeof(event)); if(bytes_read != sizeof(event)) { if(bytes_read == -1) { if(errno == EINTR || errno == EAGAIN) return 0; EPRINTF("[%s] Error %d reading from touch panel\n", TS_DEVICE, errno); return -1; } EPRINTF("[%s] Wrong number of bytes %d read from touch panel " "(expected %ld)\n", TS_DEVICE, bytes_read, sizeof(event)); return 0; }#ifdef S3C44B0_ADS7843_MOUSE //*px = (event.x-1719)*320/(314-1719); //*py = (event.y-408)*240/(3666-480); *px = event.x; *py = event.y; #else *px = event.x; *py = event.y; #endif#if defined(TOUCHSCREEN_IPAQ) || defined(TOUCHSCREEN_ADS7846)\ ||defined(S3C44B0_ADS7843_MOUSE) *pb = (event.pressure) ? MWBUTTON_L : 0;#else *pb = (event.pressure > 50) ? MWBUTTON_L : 0;#endif *pz = event.pressure; //printf("zkh x=%d, y=%d, pressure=%d\n",*px,*py,*pz); if(!*pb) return 3; return 2;}static void checkpoint(){ rx=0; ry=0; lt_x=0; lt_y=0; rb_x=0; rb_y=0; //sure='n'; mymousedev.Open(&mymousedev); //mymousedev.Read(&x, &y, &z, &t); printf("\nNow, press any point on touchpad!\n"); while(z==0){mymousedev.Read(&x, &y, &z, &t);} rx=x; ry=y; printf("Any_point: rx=%d,ry=%d\n",rx,ry); while(z>0){mymousedev.Read(&x, &y, &z, &t);} //point_1 printf("Next to press the LeftTop point of your touchsrceen!\n"); printf("If you srue next coorinate is you want, please input y then press the point.\n"); for(;;){ while(z==0){mymousedev.Read(&x, &y, &z, &t);} if(lt_x+lt_y==0) { lt_x=x; lt_y=y; } printf("Left_Top: lt_x=%d,lt_y=%d\n",lt_x,lt_y); while(z>0){mymousedev.Read(&x, &y, &z, &t);} scanf("%c",&sure1); if((sure1=='y')||(sure1=='Y')) { tpMark.ltx=lt_x; tpMark.lty=lt_y; break; } else{lt_x=0; lt_y=0;} } //point_2 printf("Next to press the RightBottom point on your touchsrceen!\n"); for(;;){ while(z==0){mymousedev.Read(&x, &y, &z, &t);} if(rb_x+rb_y==0) { rb_x=x; rb_y=y; } printf("Right_Bottom: rb_x=%d,rb_y=%d\n",rb_x,rb_y); while(z>0){mymousedev.Read(&x, &y, &z, &t);} scanf("%c",&sure2); if((sure2=='y')||(sure2=='Y')) { tpMark.rbx=rb_x; tpMark.rby=rb_y; break; } else{rb_x=0; rb_y=0;} } //point_3 mymousedev.Close();}static void savedata(){ if((tpmap=fopen("tpconfigure","wb+"))==NULL) { printf("can't open the config file!\n"); tpMark.ltx=1719; tpMark.lty=480; tpMark.rbx=314; tpMark.rby=3666; if(fwrite(&tpMark,sizeof(int),4,tpmap)!=4) { printf("file write error,can't initial touchpad!\n"); } } else { if(fwrite(&tpMark,sizeof(int),4,tpmap)!=4) { printf("file write error,can't initial touchpad!\n"); } } fclose(tpmap); }MOUSEDEVICE mymousedev = { Open, Close, GetButtonInfo, GetDefaultAccel, Read, NULL,#ifdef S3C44B0_ADS7843_MOUSE MOUSE_NORMAL#else MOUSE_TRANSFORM /* Input filter flags */#endif};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -