From 570f44304ed515bb82d545fcf03bac6bde6dbe0c Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Tue, 8 May 2007 20:51:59 +0000 Subject: Introduce the mouse.rawmode and mouse.scale fields for touchscreen calibration via ioctls. ok miod@ --- sbin/wsconsctl/mouse.c | 53 +++++++++++++++++++++++++++++++++++++++++- sbin/wsconsctl/util.c | 58 +++++++++++++++++++++++++++++++++++++++++++++- sbin/wsconsctl/wsconsctl.h | 3 ++- 3 files changed, 111 insertions(+), 3 deletions(-) diff --git a/sbin/wsconsctl/mouse.c b/sbin/wsconsctl/mouse.c index b559b5962b5..1ba3b94caad 100644 --- a/sbin/wsconsctl/mouse.c +++ b/sbin/wsconsctl/mouse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mouse.c,v 1.5 2002/12/11 18:27:19 deraadt Exp $ */ +/* $OpenBSD: mouse.c,v 1.6 2007/05/08 20:51:58 robert Exp $ */ /* $NetBSD: mouse.c,v 1.3 1999/11/15 13:47:30 ad Exp $ */ /*- @@ -41,16 +41,22 @@ #include #include #include +#include #include "wsconsctl.h" static int mstype; static int resolution; static int samplerate; +static int rawmode; + +struct wsmouse_calibcoords wmcoords; struct field mouse_field_tab[] = { { "resolution", &resolution, FMT_UINT, FLG_WRONLY }, { "samplerate", &samplerate, FMT_UINT, FLG_WRONLY }, { "type", &mstype, FMT_MSTYPE, FLG_RDONLY }, + { "rawmode", &rawmode, FMT_UINT, FLG_MODIFY|FLG_INIT}, + { "scale", &wmcoords, FMT_SCALE, FLG_MODIFY|FLG_INIT}, { NULL } }; @@ -60,6 +66,26 @@ mouse_get_values(const char *pre, int fd) if (field_by_value(mouse_field_tab, &mstype)->flags & FLG_GET) if (ioctl(fd, WSMOUSEIO_GTYPE, &mstype) < 0) warn("WSMOUSEIO_GTYPE"); + + if (field_by_value(mouse_field_tab, &rawmode)->flags & FLG_GET) { + if (ioctl(fd, WSMOUSEIO_GCALIBCOORDS, &wmcoords) < 0) { + if (errno == ENOTTY) + field_by_value(mouse_field_tab, + &rawmode)->flags |= FLG_DEAD; + else + warn("WSMOUSEIO_GCALIBCOORDS"); + } + rawmode = wmcoords.samplelen; + } + + if (field_by_value(mouse_field_tab, &wmcoords)->flags & FLG_GET) + if (ioctl(fd, WSMOUSEIO_GCALIBCOORDS, &wmcoords) < 0) { + if (errno == ENOTTY) + field_by_value(mouse_field_tab, + &wmcoords)->flags |= FLG_DEAD; + else + warn("WSMOUSEIO_GCALIBCOORDS"); + } } void @@ -81,4 +107,29 @@ mouse_put_values(const char *pre, int fd) &samplerate), " -> "); } } + if (field_by_value(mouse_field_tab, &rawmode)->flags & FLG_SET) { + wmcoords.samplelen = rawmode; + if (ioctl(fd, WSMOUSEIO_SCALIBCOORDS, &wmcoords) < 0) { + if (errno == ENOTTY) { + field_by_value(mouse_field_tab, + &rawmode)->flags |= FLG_DEAD; + } else + warn("WSMOUSEIO_SCALIBCOORDS"); + } else { + pr_field(pre, field_by_value(mouse_field_tab, + &rawmode), " -> "); + } + } + if (field_by_value(mouse_field_tab, &wmcoords)->flags & FLG_SET) { + if (ioctl(fd, WSMOUSEIO_SCALIBCOORDS, &wmcoords) < 0) { + if (errno == ENOTTY) { + field_by_value(mouse_field_tab, + &wmcoords)->flags |= FLG_DEAD; + } else + warn("WSMOUSEIO_SCALIBCOORDS"); + } else { + pr_field(pre, field_by_value(mouse_field_tab, + &wmcoords), " -> "); + } + } } diff --git a/sbin/wsconsctl/util.c b/sbin/wsconsctl/util.c index 5b34108a298..5258ca06d16 100644 --- a/sbin/wsconsctl/util.c +++ b/sbin/wsconsctl/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.34 2006/07/24 22:19:52 miod Exp $ */ +/* $OpenBSD: util.c,v 1.35 2007/05/08 20:51:58 robert Exp $ */ /* $NetBSD: util.c,v 1.8 2000/03/14 08:11:53 sato Exp $ */ /*- @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -50,6 +51,7 @@ extern struct wskbd_map_data kbmap; /* from keyboard.c */ extern struct wskbd_map_data newkbmap; /* from map_parse.y */ +extern struct wsmouse_calibcoords wmcoords; /* from mouse.c */ struct nameint { int value; @@ -270,6 +272,11 @@ pr_field(const char *pre, struct field *f, const char *sep) case FMT_KBMAP: print_kmap((struct wskbd_map_data *) f->valp); break; + case FMT_SCALE: + printf("%d,%d,%d,%d,%d,%d,%d", wmcoords.minx, wmcoords.maxx, + wmcoords.miny, wmcoords.maxy, wmcoords.swapxy, + wmcoords.resx, wmcoords.resy); + break; default: errx(1, "internal error: pr_field: no format %d", f->format); break; @@ -371,6 +378,55 @@ rd_field(struct field *f, char *val, int merge) bcopy(newkbmap.map, kbmap.map, kbmap.maplen*sizeof(struct wscons_keymap)); break; + case FMT_SCALE: + { + const char *errstr = 0; + + /* Unspecified values default to 0. */ + bzero(&wmcoords, sizeof(wmcoords)); + val = (void *)strtok(val, ","); + if (val != NULL) { + wmcoords.minx = (int)strtonum(val, + 0, 32768, &errstr); + val = (void *)strtok(NULL, ","); + } + if (!errstr && val != NULL) { + wmcoords.maxx = (int)strtonum(val, + 0, 32768, &errstr); + val = (void *)strtok(NULL, ","); + } + if (!errstr && val != NULL) { + wmcoords.miny = (int)strtonum(val, + 0, 32768, &errstr); + val = (void *)strtok(NULL, ","); + } + if (!errstr && val != NULL) { + wmcoords.maxy = (int)strtonum(val, + 0, 32768, &errstr); + val = (void *)strtok(NULL, ","); + } + if (!errstr && val != NULL) { + wmcoords.swapxy = (int)strtonum(val, + 0, 32768, &errstr); + val = (void *)strtok(NULL, ","); + } + if (!errstr && val != NULL) { + wmcoords.resx = (int)strtonum(val, + 0, 32768, &errstr); + val = (void *)strtok(NULL, ","); + } + if (!errstr && val != NULL) { + wmcoords.resy = (int)strtonum(val, + 0, 32768, &errstr); + val = (void *)strtok(NULL, ","); + } + if (errstr) + errx(1, "calibration value is %s", errstr); + if (val != NULL) + errx(1, "too many calibration values"); + + break; + } default: errx(1, "internal error: rd_field: no format %d", f->format); break; diff --git a/sbin/wsconsctl/wsconsctl.h b/sbin/wsconsctl/wsconsctl.h index eca518253a6..da11f00bf85 100644 --- a/sbin/wsconsctl/wsconsctl.h +++ b/sbin/wsconsctl/wsconsctl.h @@ -1,4 +1,4 @@ -/* $OpenBSD: wsconsctl.h,v 1.6 2002/12/17 07:10:25 mickey Exp $ */ +/* $OpenBSD: wsconsctl.h,v 1.7 2007/05/08 20:51:58 robert Exp $ */ /* $NetBSD: wsconsctl.h 1.1 1998/12/28 14:01:17 hannken Exp $ */ /*- @@ -51,6 +51,7 @@ struct field { #define FMT_DPYTYPE 103 /* display type */ #define FMT_KBDENC 104 /* keyboard encoding */ #define FMT_KBMAP 105 /* keyboard map */ +#define FMT_SCALE 106 /* wsmouse scale */ int format; #define FLG_RDONLY 0x0001 /* variable cannot be modified */ #define FLG_WRONLY 0x0002 /* variable cannot be displayed */ -- cgit v1.2.3