📄 ts_test.c
字号:
/*----------------------------------------------------------------------------*//* ts_test.c - little proggy to test the response of the touch screen drv * * Author: Philippe Ney <philippe.ney@smartdata.ch> * Copyright (C) 2001 SMARTDATA <www.smartdata.ch> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. *//*----------------------------------------------------------------------------*/#include <stdio.h>#include <string.h>#include <errno.h>#include <asm/MC68VZ328.h>#include <sys/types.h>#include <sys/stat.h>#include <asm/fcntl.h>#include <sys/ioctl.h>#include "/opt/uclinux-dist/uClinux-dist/linux-2.4.x/drivers/char/mc68328digi.h"#define DEVICE_FILE_NAME "/dev/ts"void init_pen_info(struct ts_pen_info *in) { in->x = 0; in->y = 0; in->dx = 0; in->dy = 0; in->event = EV_PEN_UP; in->ev_no = 0; in->state &= 0;}/* main */main() { char input[200]; int file_desc=0; int isTSopen=0; char c; struct ts_pen_info pen_info; struct ts_drv_params pen_set; unsigned long pps; int bytes_transfered=0,ret_val; char *pp; int i;do { printf("\n- (o)pen device\n"); printf("- (n)pen device with O_NONBLOCK flag\n"); printf("- (c)lose device\n"); printf("- (r)ead device\n"); printf("- (g)et driver params\n"); printf("- (s)et driver params\n"); printf("- (q)uit the program\n"); printf("Please input a char: "); fflush(stdout); gets(input); sscanf(input,"%c",&c); if((c=='o')&&(!isTSopen)) { file_desc = open(DEVICE_FILE_NAME,O_RDWR); if(file_desc < 0) { printf("Can't open device file: %s\n",DEVICE_FILE_NAME); printf("Error: %s\n",strerror(errno)); } else { printf("Device %s open -> It works!!!!\n"); isTSopen=1; } } if((c=='n')&&(!isTSopen)) { file_desc = open(DEVICE_FILE_NAME,O_RDWR | O_NONBLOCK); if(file_desc < 0) { printf("Can't open device file: %s in nonblocking mode\n", DEVICE_FILE_NAME); printf("Error: %s\n",strerror(errno)); } else { printf("Device %s open in nonblocking mode -> It works!!!!\n"); isTSopen=1; } } if(c=='c') { if(isTSopen) { close(file_desc); printf("Device %s closed.\n",DEVICE_FILE_NAME); isTSopen=0; } else printf ("Device %s not open!!\n",DEVICE_FILE_NAME); } if(c=='r') { if(isTSopen) { init_pen_info(&pen_info); while((pen_info.x < 4095) &&(pen_info.y < 4095)) { //for(i=0;i<10;i++) { bytes_transfered=read(file_desc,&pen_info,sizeof(pen_info)); if(pen_info.event == EV_PEN_UP) printf("U "); if(pen_info.event == EV_PEN_DOWN) printf("D "); if(pen_info.event == EV_PEN_MOVE) printf("M "); printf("(%i,%i) ",pen_info.x,pen_info.y); printf("ev_no:%d ",pen_info.ev_no); printf("ev_usec:%ld\n",pen_info.ev_time); //printf("nb bytes transfered: %d\n",bytes_transfered); } } else printf ("READ ERROR. Device %s not open!!\n",DEVICE_FILE_NAME); } if(c=='g') { if(isTSopen) { ret_val=ioctl(file_desc,TS_PARAMS_GET,&pen_set); if(ret_val < 0) printf("Error: %s\n",strerror(errno)); printf("x_ratio y_ratio x_offset y_offset Move_thrs"); printf(" Follow_thrs deglitch_ms evnt_q_on\n"); printf("%d/%d\t%d/%d\t%d\t%d\t%d\t%d\t%d\t%d\n", pen_set.x_ratio_num,pen_set.x_ratio_den, pen_set.y_ratio_num,pen_set.y_ratio_den, pen_set.x_offset,pen_set.y_offset, pen_set.mv_thrs,pen_set.follow_thrs, pen_set.deglitch_ms,pen_set.event_queue_on); } else printf ("READ ERROR. Device %s not open!!\n",DEVICE_FILE_NAME); } if(c=='s') { if(isTSopen) { printf("X ratio num ? ");fflush(stdout); gets(input); sscanf(input,"%d",&pen_set.x_ratio_num); printf("X ratio den ? ");fflush(stdout); gets(input); sscanf(input,"%d",&pen_set.x_ratio_den); printf("Y ratio num ? ");fflush(stdout); gets(input); sscanf(input,"%d",&pen_set.y_ratio_num); printf("Y ratio den ? ");fflush(stdout); gets(input); sscanf(input,"%d",&pen_set.y_ratio_den); printf("X offset ? ");fflush(stdout); gets(input); sscanf(input,"%d",&pen_set.x_offset); printf("Y offset ? ");fflush(stdout); gets(input); sscanf(input,"%d",&pen_set.y_offset); printf("Move threshold ? ");fflush(stdout); gets(input); sscanf(input,"%d",&pen_set.mv_thrs); printf("Follow threshold ? ");fflush(stdout); gets(input); sscanf(input,"%d",&pen_set.follow_thrs); printf("Deglitch time (ms) ? ");fflush(stdout); gets(input); sscanf(input,"%d",&pen_set.deglitch_ms); printf("Event queue (0-1) ? ");fflush(stdout); gets(input); sscanf(input,"%d",&pen_set.event_queue_on); ret_val=ioctl(file_desc,TS_PARAMS_SET,&pen_set); if(ret_val < 0) printf("Error: %s\n",strerror(errno)); else printf("File desc: %d\n",file_desc); printf("x_ratio y_ratio x_offset y_offset Move_thrs"); printf(" Follow_thrs deglitch_ms\n"); printf("%d/%d\t%d/%d\t%d\t%d\t%d\t%d\t%d\t%d\n", pen_set.x_ratio_num,pen_set.x_ratio_den, pen_set.y_ratio_num,pen_set.y_ratio_den, pen_set.x_offset,pen_set.y_offset, pen_set.mv_thrs,pen_set.follow_thrs, pen_set.deglitch_ms,pen_set.event_queue_on); } else printf ("WRITE ERROR. Device %s not open!!\n",DEVICE_FILE_NAME); }// printf("IMR bit 20: %d\n",(IMR & (1<<20)));// printf("ISR bit 20: %d\n",(ISR & (1<<20)));// printf("IPR bit 20: %d\n",(IPR & (1<<20)));// printf("PFDATA bit 1: %d\n",(PFDATA & (1<<1)));// printf("PFDIR bit 1: %d\n",(PFDIR & (1<<1)));// printf("PFSEL bit 1: %d\n",(PFSEL & (1<<1)));}while(c!='q');}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -