NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: kern/45872: Issues and fixes for tpcalib (touchscreen calibration)
The following reply was made to PR kern/45872; it has been noted by GNATS.
From: Pierre Pronchery <khorben%defora.org@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc:
Subject: Re: kern/45872: Issues and fixes for tpcalib (touchscreen calibration)
Date: Sat, 18 Feb 2012 13:38:48 -0500
This is a multi-part message in MIME format.
--------------070005020708030603080700
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Hi all,
I have made additional modifications to sbin/wsconstl to fully support
calibration; with them I can calibrate my touchscreen with wsconsctl
directly.
As an example, on that same Lenovo IdeaPad S10-3t at a screen resolution
of 1024x600:
=== BEGIN PASTE ===
#!/bin/sh
wsconsctl -mw calibration.maxx=4096
wsconsctl -mw calibration.maxy=4096
wsconsctl -mw
calibration.samples=4095,4095,1023,599:256,328,64,48:3840,328,960,48:3840,3768,960,552
=== END PASTE ===
This change also obsoletes the manual pages for at least uts(4) and
uep(4), which both mention that they do not support calibration. It may
also be true of ztp(4) (in the zaurus port).
HTH!
--
khorben
--------------070005020708030603080700
Content-Type: text/plain;
name="wsconsctl.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="wsconsctl.diff"
Index: mouse.c
===================================================================
RCS file: /cvsroot/src/sbin/wsconsctl/mouse.c,v
retrieving revision 1.8
diff -p -u -r1.8 mouse.c
--- mouse.c 28 Apr 2008 20:23:09 -0000 1.8
+++ mouse.c 18 Feb 2012 18:32:15 -0000
@@ -45,8 +45,13 @@
static int mstype;
static int resolution;
static int samplerate;
+static struct wsmouse_calibcoords calibration;
+static char * calibration_samples;
static struct wsmouse_repeat repeat;
+static void mouse_get_calibration(int);
+static void mouse_put_calibration(int);
+
static void mouse_get_repeat(int);
static void mouse_put_repeat(int);
@@ -54,6 +59,16 @@ struct field mouse_field_tab[] = {
{ "resolution", &resolution, FMT_UINT, FLG_WRONLY },
{ "samplerate", &samplerate, FMT_UINT, FLG_WRONLY },
{ "type", &mstype, FMT_MSTYPE, FLG_RDONLY },
+ { "calibration.minx", &calibration.minx,
+ FMT_INT, FLG_MODIFY },
+ { "calibration.miny", &calibration.miny,
+ FMT_INT, FLG_MODIFY },
+ { "calibration.maxx", &calibration.maxx,
+ FMT_INT, FLG_MODIFY },
+ { "calibration.maxy", &calibration.maxy,
+ FMT_INT, FLG_MODIFY },
+ { "calibration.samples", &calibration_samples,
+ FMT_STRING, FLG_MODIFY },
{ "repeat.buttons", &repeat.wr_buttons,
FMT_BITFIELD, FLG_MODIFY },
{ "repeat.delay.first", &repeat.wr_delay_first,
@@ -75,6 +90,13 @@ mouse_get_values(int fd)
if (ioctl(fd, WSMOUSEIO_GTYPE, &mstype) < 0)
err(EXIT_FAILURE, "WSMOUSEIO_GTYPE");
+ if (field_by_value(&calibration.minx)->flags & FLG_GET ||
+ field_by_value(&calibration.miny)->flags & FLG_GET ||
+ field_by_value(&calibration.maxx)->flags & FLG_GET ||
+ field_by_value(&calibration.maxy)->flags & FLG_GET ||
+ field_by_value(&calibration_samples)->flags & FLG_GET)
+ mouse_get_calibration(fd);
+
if (field_by_value(&repeat.wr_buttons)->flags & FLG_GET ||
field_by_value(&repeat.wr_delay_first)->flags & FLG_GET ||
field_by_value(&repeat.wr_delay_decrement)->flags & FLG_GET ||
@@ -83,6 +105,56 @@ mouse_get_values(int fd)
}
static void
+mouse_get_calibration(int fd)
+{
+ struct wsmouse_calibcoords tmp;
+ char * samples = NULL;
+ char buf[48];
+ int i;
+
+ if (ioctl(fd, WSMOUSEIO_GCALIBCOORDS, &tmp) == -1)
+ {
+ warn("WSMOUSEIO_GCALIBCOORDS");
+ field_disable_by_value(&calibration.minx);
+ field_disable_by_value(&calibration.miny);
+ field_disable_by_value(&calibration.maxx);
+ field_disable_by_value(&calibration.maxy);
+ field_disable_by_value(&calibration_samples);
+ return;
+ }
+
+ if (field_by_value(&calibration.minx)->flags & FLG_GET)
+ calibration.minx = tmp.minx;
+ if (field_by_value(&calibration.miny)->flags & FLG_GET)
+ calibration.miny = tmp.miny;
+ if (field_by_value(&calibration.maxx)->flags & FLG_GET)
+ calibration.maxx = tmp.maxx;
+ if (field_by_value(&calibration.maxy)->flags & FLG_GET)
+ calibration.maxy = tmp.maxy;
+ if (field_by_value(&calibration_samples)->flags & FLG_GET)
+ {
+ calibration_samples = strdup("");
+ if(tmp.samplelen >= 0 && (samples = malloc(tmp.samplelen
+ * sizeof(buf))) != NULL)
+ {
+ samples[0] = '\0';
+ for (i = 0; i < tmp.samplelen; i++)
+ {
+ snprintf(buf, sizeof(buf), "%s%d,%d,%d,%d",
+ (i == 0) ? "" : ":",
+ tmp.samples[i].rawx,
+ tmp.samples[i].rawy,
+ tmp.samples[i].x,
+ tmp.samples[i].y);
+ strcat(samples, buf);
+ }
+ free(calibration_samples);
+ calibration_samples = samples;
+ }
+ }
+}
+
+static void
mouse_get_repeat(int fd)
{
struct wsmouse_repeat tmp;
@@ -119,6 +191,13 @@ mouse_put_values(int fd)
pr_field(field_by_value(&samplerate), " -> ");
}
+ if (field_by_value(&calibration.minx)->flags & FLG_SET ||
+ field_by_value(&calibration.miny)->flags & FLG_SET ||
+ field_by_value(&calibration.maxx)->flags & FLG_SET ||
+ field_by_value(&calibration.maxy)->flags & FLG_SET ||
+ field_by_value(&calibration_samples)->flags & FLG_SET)
+ mouse_put_calibration(fd);
+
if (field_by_value(&repeat.wr_buttons)->flags & FLG_SET ||
field_by_value(&repeat.wr_delay_first)->flags & FLG_SET ||
field_by_value(&repeat.wr_delay_decrement)->flags & FLG_SET ||
@@ -127,6 +206,69 @@ mouse_put_values(int fd)
}
static void
+mouse_put_calibration(int fd)
+{
+ struct wsmouse_calibcoords tmp;
+ int i;
+ char const * p;
+ char * q;
+
+ /* Fetch current values into the temporary structure. */
+ if (ioctl(fd, WSMOUSEIO_GCALIBCOORDS, &tmp) == -1)
+ err(EXIT_FAILURE, "WSMOUSEIO_GCALIBCOORDS");
+
+ /* Overwrite the desired values in the temporary structure. */
+ if (field_by_value(&calibration.minx)->flags & FLG_SET)
+ tmp.minx = calibration.minx;
+ if (field_by_value(&calibration.miny)->flags & FLG_SET)
+ tmp.miny = calibration.miny;
+ if (field_by_value(&calibration.maxx)->flags & FLG_SET)
+ tmp.maxx = calibration.maxx;
+ if (field_by_value(&calibration.maxy)->flags & FLG_SET)
+ tmp.maxy = calibration.maxy;
+ if (field_by_value(&calibration_samples)->flags & FLG_SET)
+ {
+ p = calibration_samples;
+ for(i = 0; p[0] != '\0' && i < WSMOUSE_CALIBCOORDS_MAX; i++)
+ {
+ tmp.samples[i].rawx = strtol(p, &q, 0);
+ if(*q != ',')
+ break;
+ p = q + 1;
+ tmp.samples[i].rawy = strtol(p, &q, 0);
+ if(*q != ',')
+ break;
+ p = q + 1;
+ tmp.samples[i].x = strtol(p, &q, 0);
+ if(*q != ',')
+ break;
+ p = q + 1;
+ tmp.samples[i].y = strtol(p, &q, 0);
+ p = q + 1;
+ if(*q != '\0' && *q != ':')
+ break;
+ }
+ tmp.samplelen = i;
+ }
+
+ /* Set new values for calibrating events. */
+ if (ioctl(fd, WSMOUSEIO_SCALIBCOORDS, &tmp) == -1)
+ err(EXIT_FAILURE, "WSMOUSEIO_SCALIBCOORDS");
+
+ /* Now print what changed. */
+ if (field_by_value(&calibration.minx)->flags & FLG_SET)
+ pr_field(field_by_value(&calibration.minx), " -> ");
+ if (field_by_value(&calibration.miny)->flags & FLG_SET)
+ pr_field(field_by_value(&calibration.miny), " -> ");
+ if (field_by_value(&calibration.maxx)->flags & FLG_SET)
+ pr_field(field_by_value(&calibration.maxx), " -> ");
+ if (field_by_value(&calibration.maxy)->flags & FLG_SET)
+ pr_field(field_by_value(&calibration.maxy), " -> ");
+ if (field_by_value(&calibration_samples)->flags & FLG_SET)
+ pr_field(field_by_value(&calibration_samples), " -> ");
+}
+
+static void
mouse_put_repeat(int fd)
{
struct wsmouse_repeat tmp;
Index: util.c
===================================================================
RCS file: /cvsroot/src/sbin/wsconsctl/util.c,v
retrieving revision 1.30
diff -p -u -r1.30 util.c
--- util.c 15 Dec 2011 14:25:12 -0000 1.30
+++ util.c 18 Feb 2012 18:32:15 -0000
@@ -263,6 +263,9 @@ pr_field(struct field *f, const char *se
case FMT_BITFIELD:
pr_bitfield(*((unsigned int *) f->valp));
break;
+ case FMT_INT:
+ (void)printf("%d", *((int *) f->valp));
+ break;
case FMT_KBDTYPE:
p = int2name(*((unsigned int *) f->valp), 1,
kbtype_tab, TABLEN(kbtype_tab));
@@ -368,6 +371,14 @@ rd_field(struct field *f, char *val, int
case FMT_BITFIELD:
*((unsigned int *) f->valp) = rd_bitfield(val);
break;
+ case FMT_INT:
+ if (sscanf(val, "%d", &i) != 1)
+ errx(EXIT_FAILURE, "%s: not a number", val);
+ if (merge)
+ *((int *) f->valp) += i;
+ else
+ *((int *) f->valp) = i;
+ break;
case FMT_KBDENC:
p = strchr(val, '.');
if (p != NULL)
Index: wsconsctl.h
===================================================================
RCS file: /cvsroot/src/sbin/wsconsctl/wsconsctl.h,v
retrieving revision 1.11
diff -p -u -r1.11 wsconsctl.h
--- wsconsctl.h 27 Aug 2011 19:01:34 -0000 1.11
+++ wsconsctl.h 18 Feb 2012 18:32:15 -0000
@@ -55,6 +55,7 @@ struct field {
#define FMT_UINT 1 /* unsigned integer */
#define FMT_STRING 2 /* zero terminated string */
#define FMT_BITFIELD 3 /* bit field */
+#define FMT_INT 4 /* signed integer */
#define FMT_KBDTYPE 101 /* keyboard type */
#define FMT_MSTYPE 102 /* mouse type */
#define FMT_DPYTYPE 103 /* display type */
--------------070005020708030603080700--
Home |
Main Index |
Thread Index |
Old Index