Go to the source code of this file.
Data Structures | |
struct | point |
Defines | |
#define | TS_CALIBRATION_IN_PROGRESS 0 |
#define | TS_CALIBRATION_DONE 1 |
Functions | |
void | ts_init (int width, int height, int rotation) |
void | ts_get_target (int nth, int *x, int *y) |
void | ts_get_current_target (int *x, int *y) |
int | ts_handle_event (int x, int y, int pressure) |
void | ts_set_calibration (char **args) |
void | ts_show_calibration (void) |
void | ts_read_current_settings (char *filename) |
void | ts_write_calibration (char *filename) |
#define TS_CALIBRATION_DONE 1 |
Definition at line 42 of file ts.h.
Referenced by evt_filter(), and ts_handle_event().
#define TS_CALIBRATION_IN_PROGRESS 0 |
Definition at line 41 of file ts.h.
Referenced by ts_handle_event().
void ts_get_current_target | ( | int * | x, | |
int * | y | |||
) |
Definition at line 114 of file ts.c.
References event, calibration::xscr, and calibration::yscr.
Referenced by da_expose().
void ts_get_target | ( | int | nth, | |
int * | x, | |||
int * | y | |||
) |
Definition at line 108 of file ts.c.
References calibration::xscr, and calibration::yscr.
Referenced by da_expose().
int ts_handle_event | ( | int | x, | |
int | y, | |||
int | pressure | |||
) |
Definition at line 211 of file ts.c.
References ENOUGH, event, flag_debug, flag_sanityCheck, MAX_SAMPLES, next_target(), NR_POINTS, perform_calibration(), sample, samples, sort_by_x(), sort_by_y(), TS_CALIBRATION_DONE, TS_CALIBRATION_IN_PROGRESS, validate_input(), calibration::x, point::x, calibration::y, and point::y.
Referenced by evt_filter().
00212 { 00213 if (pressure) 00214 { 00215 if (samples < MAX_SAMPLES) 00216 { 00217 sample[samples].x = x; 00218 sample[samples].y = y; 00219 samples++; 00220 } 00221 } 00222 else 00223 { 00224 if (samples > ENOUGH) 00225 { 00226 int middle, sx, sy; 00227 00228 middle = samples / 2; 00229 qsort (sample, samples, sizeof(struct point), sort_by_x); 00230 if (samples & 1) 00231 sx = sample[middle].x; 00232 else 00233 sx = (sample[middle-1].x + sample[middle].x) / 2; 00234 qsort (sample, samples, sizeof(struct point), sort_by_y); 00235 if (samples & 1) 00236 sy = sample[middle].y; 00237 else 00238 sy = (sample[middle-1].y + sample[middle].y) / 2; 00239 00240 cal.x[event] = sx; 00241 cal.y[event] = sy; 00242 00243 if (flag_sanityCheck && !validate_input(cal.x[event], cal.y[event], event)) 00244 { 00245 fprintf(stderr, "Invalid input!\n"); 00246 samples = 0; 00247 return TS_CALIBRATION_IN_PROGRESS; 00248 } 00249 00250 if (flag_debug) 00251 fprintf (stderr, "point %d: [%d %d]\n", 00252 event, cal.x[event], cal.y[event]); 00253 00254 event++; 00255 00256 if (event < NR_POINTS) 00257 { 00258 samples = 0; 00259 next_target(); 00260 } 00261 else 00262 { 00263 if (perform_calibration (&cal)) 00264 { 00265 return TS_CALIBRATION_DONE; 00266 } 00267 else 00268 { 00269 samples = 0; 00270 event = 0; 00271 next_target(); 00272 } 00273 } 00274 } 00275 } 00276 return TS_CALIBRATION_IN_PROGRESS; 00277 }
void ts_init | ( | int | width, | |
int | height, | |||
int | rotation | |||
) |
Definition at line 69 of file ts.c.
References NR_POINTS, OFFSET, calibration::xfb, calibration::xscr, calibration::yfb, and calibration::yscr.
Referenced by main().
00070 { 00071 int i; 00072 00073 cal.xscr[0] = OFFSET; 00074 cal.yscr[0] = OFFSET; 00075 cal.xscr[1] = width - OFFSET; 00076 cal.yscr[1] = OFFSET; 00077 cal.xscr[2] = width - OFFSET; 00078 cal.yscr[2] = height - OFFSET; 00079 cal.xscr[3] = OFFSET; 00080 cal.yscr[3] = height - OFFSET; 00081 cal.xscr[4] = (width / 2); 00082 cal.yscr[4] = (height / 2); 00083 00084 for (i=0;i<NR_POINTS;i++) 00085 { 00086 switch (rotation) 00087 { 00088 case 0: 00089 cal.xfb[i] = cal.xscr[i]; 00090 cal.yfb[i] = cal.yscr[i]; 00091 break; 00092 case 90: 00093 cal.xfb[i] = cal.yscr[i]; 00094 cal.yfb[i] = width - cal.xscr[i]; 00095 break; 00096 case 180: 00097 cal.xfb[i] = width - cal.xscr[i]; 00098 cal.yfb[i] = height - cal.yscr[i]; 00099 break; 00100 case 270: 00101 cal.xfb[i] = height - cal.yscr[i]; 00102 cal.yfb[i] = cal.xscr[i]; 00103 break; 00104 } 00105 } 00106 }
void ts_read_current_settings | ( | char * | filename | ) |
Definition at line 314 of file ts.c.
References a_cur.
Referenced by main().
00315 { 00316 FILE* fp = NULL; 00317 00318 // give default value in case the pointercal does not exist 00319 // 4317 -4 -2205916 8 -4189 84612704 65536 00320 a_cur[0] = 4317; 00321 a_cur[1] = -4; 00322 a_cur[2] = -2205916; 00323 a_cur[3] = 8; 00324 a_cur[4] = -4189; 00325 a_cur[5] = 84612704; 00326 a_cur[6] = 65536; 00327 00328 if ((fp = fopen(filename, "r")) != NULL) 00329 { 00330 fscanf(fp, "%d %d %d %d %d %d %d", 00331 a_cur + 0, 00332 a_cur + 1, 00333 a_cur + 2, 00334 a_cur + 3, 00335 a_cur + 4, 00336 a_cur + 5, 00337 a_cur + 6); 00338 00339 fclose(fp); 00340 } 00341 }
void ts_set_calibration | ( | char ** | args | ) |
Definition at line 279 of file ts.c.
References flag_debug, ts_fd, TS_SET_CAL, h3600_ts_calibration::xscale, h3600_ts_calibration::xtrans, h3600_ts_calibration::xyswap, h3600_ts_calibration::yscale, and h3600_ts_calibration::ytrans.
Referenced by parse_args().
00280 { 00281 TS_CAL tc; 00282 00283 tc.xscale = atoi (args[0]); 00284 tc.xtrans = atoi (args[1]); 00285 tc.yscale = atoi (args[2]); 00286 tc.ytrans = atoi (args[3]); 00287 tc.xyswap = atoi (args[4]); 00288 00289 if (flag_debug) 00290 fprintf (stderr, "setting: %d %d %d %d %d\n", 00291 tc.xtrans, tc.ytrans, tc.xscale, tc.yscale, tc.xyswap); 00292 00293 if (ioctl (ts_fd, TS_SET_CAL, (void *)&tc) != 0) 00294 { 00295 perror ("TS_SET_CAL"); 00296 exit (1); 00297 } 00298 }
void ts_show_calibration | ( | void | ) |
Definition at line 300 of file ts.c.
References ts_fd, and TS_GET_CAL.
Referenced by parse_args().
00301 { 00302 TS_CAL tc; 00303 00304 if (ioctl (ts_fd, TS_GET_CAL, (void *)&tc) != 0) 00305 { 00306 perror ("TS_GET_CAL"); 00307 exit (1); 00308 } 00309 00310 printf ("%d %d %d %d %d\n", 00311 tc.xscale, tc.xtrans, tc.yscale, tc.ytrans, tc.xyswap); 00312 }
void ts_write_calibration | ( | char * | filename | ) |
Definition at line 130 of file ts.c.
References calibration::a, flag_debug, ts_fd, TS_SET_CAL, h3600_ts_calibration::xscale, h3600_ts_calibration::xtrans, h3600_ts_calibration::xyswap, h3600_ts_calibration::yscale, and h3600_ts_calibration::ytrans.
Referenced by evt_filter().
00131 { 00132 TS_CAL tc; 00133 int xtrans, ytrans, xscale, yscale, xyscale, yxscale; 00134 00135 FILE *fp; 00136 if (flag_debug) 00137 printf ("constants are: %d %d %d %d %d %d %d\n", 00138 cal.a[1], 00139 cal.a[2], 00140 cal.a[0], 00141 cal.a[4], 00142 cal.a[5], 00143 cal.a[3], 00144 cal.a[6]); 00145 00146 fp = fopen (filename, "w"); 00147 if (!fp) 00148 { 00149 perror (filename); 00150 exit (1); 00151 } 00152 fprintf (fp, "%d %d %d %d %d %d %d\n", 00153 cal.a[1], 00154 cal.a[2], 00155 cal.a[0], 00156 cal.a[4], 00157 cal.a[5], 00158 cal.a[3], 00159 cal.a[6]); 00160 fclose (fp); 00161 return; 00162 00163 xtrans = cal.a[0] / cal.a[6]; 00164 ytrans = cal.a[3] / cal.a[6]; 00165 xscale = cal.a[1] * 256 / cal.a[6]; 00166 yscale = cal.a[5] * 256 / cal.a[6]; 00167 xyscale = cal.a[2] * 256 / cal.a[6]; 00168 yxscale = cal.a[4] * 256 / cal.a[6]; 00169 00170 tc.xtrans = xtrans; 00171 tc.ytrans = ytrans; 00172 tc.xscale = xscale; 00173 tc.yscale = yscale; 00174 tc.xyswap = 0; 00175 00176 printf ("%d %d %d %d %d\n", 00177 tc.xscale, tc.xtrans, tc.yscale, tc.ytrans, tc.xyswap); 00178 00179 if (ioctl (ts_fd, TS_SET_CAL, (void *)&tc) != 0) 00180 { 00181 perror ("TS_SET_CAL"); 00182 exit (1); 00183 } 00184 }