1 /* $NetBSD: keyboard.c,v 1.3 2001/09/19 12:45:24 ad Exp $ */ 2 3 /*- 4 * Copyright (c) 1998 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Juergen Hannken-Illjes. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39 #include <sys/ioctl.h> 40 #include <sys/time.h> 41 #include <dev/wscons/wsksymdef.h> 42 #include <dev/wscons/wsconsio.h> 43 #include <err.h> 44 #include "wsconsctl.h" 45 46 static int kbtype; 47 static int keyclick; 48 static struct wskbd_bell_data bell; 49 static struct wskbd_bell_data dfbell; 50 static struct wscons_keymap mapdata[KS_NUMKEYCODES]; 51 struct wskbd_map_data kbmap = { KS_NUMKEYCODES, mapdata }; /* used in map_parse.y 52 and in util.c */ 53 static struct wskbd_keyrepeat_data repeat; 54 static struct wskbd_keyrepeat_data dfrepeat; 55 static int ledstate; 56 static kbd_t kbdencoding; 57 58 struct field keyboard_field_tab[] = { 59 { "type", &kbtype, FMT_KBDTYPE, FLG_RDONLY }, 60 { "bell.pitch", &bell.pitch, FMT_UINT, FLG_MODIFY }, 61 { "bell.period", &bell.period, FMT_UINT, FLG_MODIFY }, 62 { "bell.volume", &bell.volume, FMT_UINT, FLG_MODIFY }, 63 { "bell.pitch.default", &dfbell.pitch, FMT_UINT, FLG_MODIFY }, 64 { "bell.period.default", &dfbell.period, FMT_UINT, FLG_MODIFY }, 65 { "bell.volume.default", &dfbell.volume, FMT_UINT, FLG_MODIFY }, 66 { "map", &kbmap, FMT_KBMAP, FLG_MODIFY|FLG_NOAUTO }, 67 { "repeat.del1", &repeat.del1, FMT_UINT, FLG_MODIFY }, 68 { "repeat.deln", &repeat.delN, FMT_UINT, FLG_MODIFY }, 69 { "repeat.del1.default", &dfrepeat.del1, FMT_UINT, FLG_MODIFY }, 70 { "repeat.deln.default", &dfrepeat.delN, FMT_UINT, FLG_MODIFY }, 71 { "ledstate", &ledstate, FMT_UINT, 0 }, 72 { "encoding", &kbdencoding, FMT_KBDENC, FLG_MODIFY }, 73 { "keyclick", &keyclick, FMT_UINT, FLG_MODIFY }, 74 }; 75 76 int keyboard_field_tab_len = sizeof(keyboard_field_tab)/ 77 sizeof(keyboard_field_tab[0]); 78 79 void 80 keyboard_get_values(fd) 81 int fd; 82 { 83 if (field_by_value(&kbtype)->flags & FLG_GET) 84 if (ioctl(fd, WSKBDIO_GTYPE, &kbtype) < 0) 85 err(1, "WSKBDIO_GTYPE"); 86 87 bell.which = 0; 88 if (field_by_value(&bell.pitch)->flags & FLG_GET) 89 bell.which |= WSKBD_BELL_DOPITCH; 90 if (field_by_value(&bell.period)->flags & FLG_GET) 91 bell.which |= WSKBD_BELL_DOPERIOD; 92 if (field_by_value(&bell.volume)->flags & FLG_GET) 93 bell.which |= WSKBD_BELL_DOVOLUME; 94 if (bell.which != 0 && ioctl(fd, WSKBDIO_GETBELL, &bell) < 0) 95 err(1, "WSKBDIO_GETBELL"); 96 97 dfbell.which = 0; 98 if (field_by_value(&dfbell.pitch)->flags & FLG_GET) 99 dfbell.which |= WSKBD_BELL_DOPITCH; 100 if (field_by_value(&dfbell.period)->flags & FLG_GET) 101 dfbell.which |= WSKBD_BELL_DOPERIOD; 102 if (field_by_value(&dfbell.volume)->flags & FLG_GET) 103 dfbell.which |= WSKBD_BELL_DOVOLUME; 104 if (dfbell.which != 0 && 105 ioctl(fd, WSKBDIO_GETDEFAULTBELL, &dfbell) < 0) 106 err(1, "WSKBDIO_GETDEFAULTBELL"); 107 108 if (field_by_value(&kbmap)->flags & FLG_GET) { 109 kbmap.maplen = KS_NUMKEYCODES; 110 if (ioctl(fd, WSKBDIO_GETMAP, &kbmap) < 0) 111 err(1, "WSKBDIO_GETMAP"); 112 } 113 114 repeat.which = 0; 115 if (field_by_value(&repeat.del1)->flags & FLG_GET) 116 repeat.which |= WSKBD_KEYREPEAT_DODEL1; 117 if (field_by_value(&repeat.delN)->flags & FLG_GET) 118 repeat.which |= WSKBD_KEYREPEAT_DODELN; 119 if (repeat.which != 0 && 120 ioctl(fd, WSKBDIO_GETKEYREPEAT, &repeat) < 0) 121 err(1, "WSKBDIO_GETKEYREPEAT"); 122 123 dfrepeat.which = 0; 124 if (field_by_value(&dfrepeat.del1)->flags & FLG_GET) 125 dfrepeat.which |= WSKBD_KEYREPEAT_DODEL1; 126 if (field_by_value(&dfrepeat.delN)->flags & FLG_GET) 127 dfrepeat.which |= WSKBD_KEYREPEAT_DODELN; 128 if (dfrepeat.which != 0 && 129 ioctl(fd, WSKBDIO_GETKEYREPEAT, &dfrepeat) < 0) 130 err(1, "WSKBDIO_GETKEYREPEAT"); 131 132 if (field_by_value(&ledstate)->flags & FLG_GET) 133 if (ioctl(fd, WSKBDIO_GETLEDS, &ledstate) < 0) 134 err(1, "WSKBDIO_GETLEDS"); 135 136 if (field_by_value(&kbdencoding)->flags & FLG_GET) 137 if (ioctl(fd, WSKBDIO_GETENCODING, &kbdencoding) < 0) 138 err(1, "WSKBDIO_GETENCODING"); 139 140 if (field_by_value(&keyclick)->flags & FLG_GET) { 141 ioctl(fd, WSKBDIO_GETKEYCLICK, &keyclick); 142 /* Optional; don't complain. */ 143 } 144 } 145 146 void 147 keyboard_put_values(fd) 148 int fd; 149 { 150 bell.which = 0; 151 if (field_by_value(&bell.pitch)->flags & FLG_SET) 152 bell.which |= WSKBD_BELL_DOPITCH; 153 if (field_by_value(&bell.period)->flags & FLG_SET) 154 bell.which |= WSKBD_BELL_DOPERIOD; 155 if (field_by_value(&bell.volume)->flags & FLG_SET) 156 bell.which |= WSKBD_BELL_DOVOLUME; 157 if (bell.which != 0 && ioctl(fd, WSKBDIO_SETBELL, &bell) < 0) 158 err(1, "WSKBDIO_SETBELL"); 159 if (bell.which & WSKBD_BELL_DOPITCH) 160 pr_field(field_by_value(&bell.pitch), " -> "); 161 if (bell.which & WSKBD_BELL_DOPERIOD) 162 pr_field(field_by_value(&bell.period), " -> "); 163 if (bell.which & WSKBD_BELL_DOVOLUME) 164 pr_field(field_by_value(&bell.volume), " -> "); 165 166 dfbell.which = 0; 167 if (field_by_value(&dfbell.pitch)->flags & FLG_SET) 168 dfbell.which |= WSKBD_BELL_DOPITCH; 169 if (field_by_value(&dfbell.period)->flags & FLG_SET) 170 dfbell.which |= WSKBD_BELL_DOPERIOD; 171 if (field_by_value(&dfbell.volume)->flags & FLG_SET) 172 dfbell.which |= WSKBD_BELL_DOVOLUME; 173 if (dfbell.which != 0 && 174 ioctl(fd, WSKBDIO_SETDEFAULTBELL, &dfbell) < 0) 175 err(1, "WSKBDIO_SETDEFAULTBELL"); 176 if (dfbell.which & WSKBD_BELL_DOPITCH) 177 pr_field(field_by_value(&dfbell.pitch), " -> "); 178 if (dfbell.which & WSKBD_BELL_DOPERIOD) 179 pr_field(field_by_value(&dfbell.period), " -> "); 180 if (dfbell.which & WSKBD_BELL_DOVOLUME) 181 pr_field(field_by_value(&dfbell.volume), " -> "); 182 183 if (field_by_value(&kbmap)->flags & FLG_SET) { 184 if (ioctl(fd, WSKBDIO_SETMAP, &kbmap) < 0) 185 err(1, "WSKBDIO_SETMAP"); 186 pr_field(field_by_value(&kbmap), " -> "); 187 } 188 189 repeat.which = 0; 190 if (field_by_value(&repeat.del1)->flags & FLG_SET) 191 repeat.which |= WSKBD_KEYREPEAT_DODEL1; 192 if (field_by_value(&repeat.delN)->flags & FLG_SET) 193 repeat.which |= WSKBD_KEYREPEAT_DODELN; 194 if (repeat.which != 0 && 195 ioctl(fd, WSKBDIO_SETKEYREPEAT, &repeat) < 0) 196 err(1, "WSKBDIO_SETKEYREPEAT"); 197 if (repeat.which & WSKBD_KEYREPEAT_DODEL1) 198 pr_field(field_by_value(&repeat.del1), " -> "); 199 if (repeat.which & WSKBD_KEYREPEAT_DODELN) 200 pr_field(field_by_value(&repeat.delN), " -> "); 201 202 dfrepeat.which = 0; 203 if (field_by_value(&dfrepeat.del1)->flags & FLG_SET) 204 dfrepeat.which |= WSKBD_KEYREPEAT_DODEL1; 205 if (field_by_value(&dfrepeat.delN)->flags & FLG_SET) 206 dfrepeat.which |= WSKBD_KEYREPEAT_DODELN; 207 if (dfrepeat.which != 0 && 208 ioctl(fd, WSKBDIO_SETDEFAULTKEYREPEAT, &dfrepeat) < 0) 209 err(1, "WSKBDIO_SETDEFAULTKEYREPEAT"); 210 if (dfrepeat.which &WSKBD_KEYREPEAT_DODEL1) 211 pr_field(field_by_value(&dfrepeat.del1), " -> "); 212 if (dfrepeat.which & WSKBD_KEYREPEAT_DODELN) 213 pr_field(field_by_value(&dfrepeat.delN), " -> "); 214 215 if (field_by_value(&ledstate)->flags & FLG_SET) { 216 if (ioctl(fd, WSKBDIO_SETLEDS, &ledstate) < 0) 217 err(1, "WSKBDIO_SETLEDS"); 218 pr_field(field_by_value(&ledstate), " -> "); 219 } 220 221 if (field_by_value(&kbdencoding)->flags & FLG_SET) { 222 if (ioctl(fd, WSKBDIO_SETENCODING, &kbdencoding) < 0) 223 err(1, "WSKBDIO_SETENCODING"); 224 pr_field(field_by_value(&kbdencoding), " -> "); 225 } 226 227 if (field_by_value(&keyclick)->flags & FLG_SET) { 228 if (ioctl(fd, WSKBDIO_SETKEYCLICK, &keyclick) < 0) 229 err(1, "WSKBDIO_SETKEYCLICK"); 230 pr_field(field_by_value(&keyclick), " -> "); 231 } 232 } 233