/* Allen Cheng. 2000/6/20 */ #include #include #include #include #include #define ERROR 9 #define ERROR_RATE 16 struct data{ short p; short x; short y; }p; /* PhantomCat, defined by allen */ struct cal{ int enable; int x_max; /* offset for x pos */ int y_max; int p_max; int x_min; /* offset for x pos */ int y_min; int p_min; int x_pd; /* offset for x pos */ int y_pd; int p_pd; int penup; int buf_clr; }cal_t; /* PhantomCat */ int dev_no; int no,i,j; int Xd,Yd,PP; int XXmax = 0, YYmax=0, XXmin = 0; YYmin=0; float Xpd=0,Ypd=0; int dev_open(void); int dev_close(void); int dev_dis(void); int dev_setall(void); int dev_getall(void); int dev_buf_clr(void); int dev_penup(void); int dev_read(void); void print_par(void); int ts_buf_clr(void); void penup_check(void); void delay_time(int x,int y); void main() { int cc = 0; printf("Welcome\n"); if (dev_open()==ERROR) return; if (dev_dis()==ERROR) return; while (cc != 21) { if (dev_read()==ERROR) return; else { Xd = p.x; Yd = p.y; PP = p.p; } if (ts_buf_clr()==ERROR) return; penup_check(); printf("\n Point - %2d : Xd = %d ; Yd = %d ; Pd = %d\n",cc,Xd,Yd,PP); cc++; } if (dev_close()==ERROR) return; } void delay_time(int x,int y) { int nop; for (i=0;i<=x;i++) for (j=0;j<=y;j++) nop=0; return; } void penup_check(void) { do { if (dev_penup()==ERROR) return; delay_time(255,255); }while(!cal_t.penup); if (ts_buf_clr()==ERROR) return; return; } int dev_open(void) { if ((dev_no=open("/dev/ts",O_SYNC)) < 0) { printf("can't open touchscreen device!\n"); return ERROR; } else { printf(" Open dev_no = %d\n",dev_no); return 1; } } int dev_close(void) { if (close(dev_no) < 0) { printf("can't close touchscreen device!\n\n"); return ERROR; } else return 1; } int dev_read(void) { int error_code; if ((error_code=read(dev_no,&p,6)) < 0) { printf("can't read touchscreen!\n"); return ERROR; } else { // printf("E = %d p = %d x = %d y = %d\n",error_code,p.p,p.x,p.y); return 1; } } int dev_dis(void) { int error_code; if ((error_code=ioctl(dev_no,TIODIS_CALI,0)) < 0) { printf("can't set the disable bit of the touchscreen device!\n"); printf(" ERROR_CODE = %d \n",error_code); return ERROR; } else return 1; } int dev_getall(void) { int error_code; if ((error_code=ioctl(dev_no,TIOGET_CALI,&cal_t)) < 0) { printf("can't get the parameters of the touchscreen device!\n"); printf(" ERROR_CODE = %d \n",error_code); return ERROR; } else { print_par(); return 1; } } int dev_setall(void) { cal_t.enable = 1; cal_t.x_max = XXmax; /* offset for x pos */ cal_t.y_max = YYmax; cal_t.p_max = 1; cal_t.x_min = XXmin; /* offset for x pos */ cal_t.y_min = YYmin; cal_t.p_min = 1; cal_t.x_pd = Xpd*SCALE; /* offset for x pos */ cal_t.y_pd = Ypd*SCALE; cal_t.p_pd = 1; print_par(); if (ioctl(dev_no,TIOSET_CALI,&cal_t) < 0) { printf("can't set the parameters of the touchscreen device!\n"); return ERROR; } else return 1; } void print_par(void) { printf(" enable = %d\n",cal_t.enable); printf(" x_min = %d\n",cal_t.x_min); printf(" y_min = %d\n",cal_t.y_min); printf(" x_pd = %d\n",cal_t.x_pd); printf(" y_pd = %d\n",cal_t.y_pd); printf(" penup = %d\n",cal_t.penup); printf(" buf_clr = %d\n",cal_t.buf_clr); } int ts_buf_clr(void) { int error_code; if ((error_code=ioctl(dev_no,TIO_BUF_CLR,0)) < 0) { printf("can't clear the parameters of the touchscreen device!\n"); printf(" ERROR_CODE = %d \n",error_code); return ERROR; } else return 1; } int dev_buf_clr(void) { if (ioctl(dev_no,TIOGET_BUFCLR,&cal_t) < 0) { printf("can't get the parameters of the touchscreen device!\n"); return ERROR; } else return 1; } int dev_penup(void) { if (ioctl(dev_no,TIOGET_PENUP,&cal_t) < 0) { printf("can't get the parameters of the touchscreen device!\n"); return ERROR; } else return 1; }