1 /* $OpenBSD: mouse.c,v 1.7 2008/06/26 05:42:06 ray Exp $ */ 2 /* $NetBSD: mouse.c,v 1.3 1999/11/15 13:47:30 ad Exp $ */ 3 4 /*- 5 * Copyright (c) 1998 The NetBSD Foundation, Inc. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to The NetBSD Foundation 9 * by Juergen Hannken-Illjes. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 #include <sys/ioctl.h> 34 #include <sys/time.h> 35 #include <dev/wscons/wsconsio.h> 36 #include <err.h> 37 #include <errno.h> 38 #include "wsconsctl.h" 39 40 static int mstype; 41 static int resolution; 42 static int samplerate; 43 static int rawmode; 44 45 struct wsmouse_calibcoords wmcoords; 46 47 struct field mouse_field_tab[] = { 48 { "resolution", &resolution, FMT_UINT, FLG_WRONLY }, 49 { "samplerate", &samplerate, FMT_UINT, FLG_WRONLY }, 50 { "type", &mstype, FMT_MSTYPE, FLG_RDONLY }, 51 { "rawmode", &rawmode, FMT_UINT, FLG_MODIFY|FLG_INIT}, 52 { "scale", &wmcoords, FMT_SCALE, FLG_MODIFY|FLG_INIT}, 53 { NULL } 54 }; 55 56 void 57 mouse_get_values(const char *pre, int fd) 58 { 59 if (field_by_value(mouse_field_tab, &mstype)->flags & FLG_GET) 60 if (ioctl(fd, WSMOUSEIO_GTYPE, &mstype) < 0) 61 warn("WSMOUSEIO_GTYPE"); 62 63 if (field_by_value(mouse_field_tab, &rawmode)->flags & FLG_GET) { 64 if (ioctl(fd, WSMOUSEIO_GCALIBCOORDS, &wmcoords) < 0) { 65 if (errno == ENOTTY) 66 field_by_value(mouse_field_tab, 67 &rawmode)->flags |= FLG_DEAD; 68 else 69 warn("WSMOUSEIO_GCALIBCOORDS"); 70 } 71 rawmode = wmcoords.samplelen; 72 } 73 74 if (field_by_value(mouse_field_tab, &wmcoords)->flags & FLG_GET) 75 if (ioctl(fd, WSMOUSEIO_GCALIBCOORDS, &wmcoords) < 0) { 76 if (errno == ENOTTY) 77 field_by_value(mouse_field_tab, 78 &wmcoords)->flags |= FLG_DEAD; 79 else 80 warn("WSMOUSEIO_GCALIBCOORDS"); 81 } 82 } 83 84 void 85 mouse_put_values(const char *pre, int fd) 86 { 87 if (field_by_value(mouse_field_tab, &resolution)->flags & FLG_SET) { 88 if (ioctl(fd, WSMOUSEIO_SRES, &resolution) < 0) 89 warn("WSMOUSEIO_SRES"); 90 else { 91 pr_field(pre, field_by_value(mouse_field_tab, 92 &resolution), " -> "); 93 } 94 } 95 if (field_by_value(mouse_field_tab, &samplerate)->flags & FLG_SET) { 96 if (ioctl(fd, WSMOUSEIO_SRATE, &samplerate) < 0) 97 warn("WSMOUSEIO_SRATE"); 98 else { 99 pr_field(pre, field_by_value(mouse_field_tab, 100 &samplerate), " -> "); 101 } 102 } 103 if (field_by_value(mouse_field_tab, &rawmode)->flags & FLG_SET) { 104 wmcoords.samplelen = rawmode; 105 if (ioctl(fd, WSMOUSEIO_SCALIBCOORDS, &wmcoords) < 0) { 106 if (errno == ENOTTY) { 107 field_by_value(mouse_field_tab, 108 &rawmode)->flags |= FLG_DEAD; 109 } else 110 warn("WSMOUSEIO_SCALIBCOORDS"); 111 } else { 112 pr_field(pre, field_by_value(mouse_field_tab, 113 &rawmode), " -> "); 114 } 115 } 116 if (field_by_value(mouse_field_tab, &wmcoords)->flags & FLG_SET) { 117 if (ioctl(fd, WSMOUSEIO_SCALIBCOORDS, &wmcoords) < 0) { 118 if (errno == ENOTTY) { 119 field_by_value(mouse_field_tab, 120 &wmcoords)->flags |= FLG_DEAD; 121 } else 122 warn("WSMOUSEIO_SCALIBCOORDS"); 123 } else { 124 pr_field(pre, field_by_value(mouse_field_tab, 125 &wmcoords), " -> "); 126 } 127 } 128 } 129