1 /* $NetBSD: keyboard.c,v 1.2 2000/07/06 16:30:47 hannken 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 struct wskbd_bell_data bell; 48 static struct wskbd_bell_data dfbell; 49 static struct wscons_keymap mapdata[KS_NUMKEYCODES]; 50 struct wskbd_map_data kbmap = { KS_NUMKEYCODES, mapdata }; /* used in map_parse.y 51 and in util.c */ 52 static struct wskbd_keyrepeat_data repeat; 53 static struct wskbd_keyrepeat_data dfrepeat; 54 static int ledstate; 55 static kbd_t kbdencoding; 56 57 struct field keyboard_field_tab[] = { 58 { "type", &kbtype, FMT_KBDTYPE, FLG_RDONLY }, 59 { "bell.pitch", &bell.pitch, FMT_UINT, FLG_MODIFY }, 60 { "bell.period", &bell.period, FMT_UINT, FLG_MODIFY }, 61 { "bell.volume", &bell.volume, FMT_UINT, FLG_MODIFY }, 62 { "bell.pitch.default", &dfbell.pitch, FMT_UINT, FLG_MODIFY }, 63 { "bell.period.default", &dfbell.period, FMT_UINT, FLG_MODIFY }, 64 { "bell.volume.default", &dfbell.volume, FMT_UINT, FLG_MODIFY }, 65 { "map", &kbmap, FMT_KBMAP, FLG_MODIFY|FLG_NOAUTO }, 66 { "repeat.del1", &repeat.del1, FMT_UINT, FLG_MODIFY }, 67 { "repeat.deln", &repeat.delN, FMT_UINT, FLG_MODIFY }, 68 { "repeat.del1.default", &dfrepeat.del1, FMT_UINT, FLG_MODIFY }, 69 { "repeat.deln.default", &dfrepeat.delN, FMT_UINT, FLG_MODIFY }, 70 { "ledstate", &ledstate, FMT_UINT, 0 }, 71 { "encoding", &kbdencoding, FMT_KBDENC, FLG_MODIFY }, 72 }; 73 74 int keyboard_field_tab_len = sizeof(keyboard_field_tab)/ 75 sizeof(keyboard_field_tab[0]); 76 77 void 78 keyboard_get_values(fd) 79 int fd; 80 { 81 if (field_by_value(&kbtype)->flags & FLG_GET) 82 if (ioctl(fd, WSKBDIO_GTYPE, &kbtype) < 0) 83 err(1, "WSKBDIO_GTYPE"); 84 85 bell.which = 0; 86 if (field_by_value(&bell.pitch)->flags & FLG_GET) 87 bell.which |= WSKBD_BELL_DOPITCH; 88 if (field_by_value(&bell.period)->flags & FLG_GET) 89 bell.which |= WSKBD_BELL_DOPERIOD; 90 if (field_by_value(&bell.volume)->flags & FLG_GET) 91 bell.which |= WSKBD_BELL_DOVOLUME; 92 if (bell.which != 0 && ioctl(fd, WSKBDIO_GETBELL, &bell) < 0) 93 err(1, "WSKBDIO_GETBELL"); 94 95 dfbell.which = 0; 96 if (field_by_value(&dfbell.pitch)->flags & FLG_GET) 97 dfbell.which |= WSKBD_BELL_DOPITCH; 98 if (field_by_value(&dfbell.period)->flags & FLG_GET) 99 dfbell.which |= WSKBD_BELL_DOPERIOD; 100 if (field_by_value(&dfbell.volume)->flags & FLG_GET) 101 dfbell.which |= WSKBD_BELL_DOVOLUME; 102 if (dfbell.which != 0 && 103 ioctl(fd, WSKBDIO_GETDEFAULTBELL, &dfbell) < 0) 104 err(1, "WSKBDIO_GETDEFAULTBELL"); 105 106 if (field_by_value(&kbmap)->flags & FLG_GET) { 107 kbmap.maplen = KS_NUMKEYCODES; 108 if (ioctl(fd, WSKBDIO_GETMAP, &kbmap) < 0) 109 err(1, "WSKBDIO_GETMAP"); 110 } 111 112 repeat.which = 0; 113 if (field_by_value(&repeat.del1)->flags & FLG_GET) 114 repeat.which |= WSKBD_KEYREPEAT_DODEL1; 115 if (field_by_value(&repeat.delN)->flags & FLG_GET) 116 repeat.which |= WSKBD_KEYREPEAT_DODELN; 117 if (repeat.which != 0 && 118 ioctl(fd, WSKBDIO_GETKEYREPEAT, &repeat) < 0) 119 err(1, "WSKBDIO_GETKEYREPEAT"); 120 121 dfrepeat.which = 0; 122 if (field_by_value(&dfrepeat.del1)->flags & FLG_GET) 123 dfrepeat.which |= WSKBD_KEYREPEAT_DODEL1; 124 if (field_by_value(&dfrepeat.delN)->flags & FLG_GET) 125 dfrepeat.which |= WSKBD_KEYREPEAT_DODELN; 126 if (dfrepeat.which != 0 && 127 ioctl(fd, WSKBDIO_GETKEYREPEAT, &dfrepeat) < 0) 128 err(1, "WSKBDIO_GETKEYREPEAT"); 129 130 if (field_by_value(&ledstate)->flags & FLG_GET) 131 if (ioctl(fd, WSKBDIO_GETLEDS, &ledstate) < 0) 132 err(1, "WSKBDIO_GETLEDS"); 133 134 if (field_by_value(&kbdencoding)->flags & FLG_GET) 135 if (ioctl(fd, WSKBDIO_GETENCODING, &kbdencoding) < 0) 136 err(1, "WSKBDIO_GETENCODING"); 137 } 138 139 void 140 keyboard_put_values(fd) 141 int fd; 142 { 143 bell.which = 0; 144 if (field_by_value(&bell.pitch)->flags & FLG_SET) 145 bell.which |= WSKBD_BELL_DOPITCH; 146 if (field_by_value(&bell.period)->flags & FLG_SET) 147 bell.which |= WSKBD_BELL_DOPERIOD; 148 if (field_by_value(&bell.volume)->flags & FLG_SET) 149 bell.which |= WSKBD_BELL_DOVOLUME; 150 if (bell.which != 0 && ioctl(fd, WSKBDIO_SETBELL, &bell) < 0) 151 err(1, "WSKBDIO_SETBELL"); 152 if (bell.which & WSKBD_BELL_DOPITCH) 153 pr_field(field_by_value(&bell.pitch), " -> "); 154 if (bell.which & WSKBD_BELL_DOPERIOD) 155 pr_field(field_by_value(&bell.period), " -> "); 156 if (bell.which & WSKBD_BELL_DOVOLUME) 157 pr_field(field_by_value(&bell.volume), " -> "); 158 159 dfbell.which = 0; 160 if (field_by_value(&dfbell.pitch)->flags & FLG_SET) 161 dfbell.which |= WSKBD_BELL_DOPITCH; 162 if (field_by_value(&dfbell.period)->flags & FLG_SET) 163 dfbell.which |= WSKBD_BELL_DOPERIOD; 164 if (field_by_value(&dfbell.volume)->flags & FLG_SET) 165 dfbell.which |= WSKBD_BELL_DOVOLUME; 166 if (dfbell.which != 0 && 167 ioctl(fd, WSKBDIO_SETDEFAULTBELL, &dfbell) < 0) 168 err(1, "WSKBDIO_SETDEFAULTBELL"); 169 if (dfbell.which & WSKBD_BELL_DOPITCH) 170 pr_field(field_by_value(&dfbell.pitch), " -> "); 171 if (dfbell.which & WSKBD_BELL_DOPERIOD) 172 pr_field(field_by_value(&dfbell.period), " -> "); 173 if (dfbell.which & WSKBD_BELL_DOVOLUME) 174 pr_field(field_by_value(&dfbell.volume), " -> "); 175 176 if (field_by_value(&kbmap)->flags & FLG_SET) { 177 if (ioctl(fd, WSKBDIO_SETMAP, &kbmap) < 0) 178 err(1, "WSKBDIO_SETMAP"); 179 pr_field(field_by_value(&kbmap), " -> "); 180 } 181 182 repeat.which = 0; 183 if (field_by_value(&repeat.del1)->flags & FLG_SET) 184 repeat.which |= WSKBD_KEYREPEAT_DODEL1; 185 if (field_by_value(&repeat.delN)->flags & FLG_SET) 186 repeat.which |= WSKBD_KEYREPEAT_DODELN; 187 if (repeat.which != 0 && 188 ioctl(fd, WSKBDIO_SETKEYREPEAT, &repeat) < 0) 189 err(1, "WSKBDIO_SETKEYREPEAT"); 190 if (repeat.which & WSKBD_KEYREPEAT_DODEL1) 191 pr_field(field_by_value(&repeat.del1), " -> "); 192 if (repeat.which & WSKBD_KEYREPEAT_DODELN) 193 pr_field(field_by_value(&repeat.delN), " -> "); 194 195 dfrepeat.which = 0; 196 if (field_by_value(&dfrepeat.del1)->flags & FLG_SET) 197 dfrepeat.which |= WSKBD_KEYREPEAT_DODEL1; 198 if (field_by_value(&dfrepeat.delN)->flags & FLG_SET) 199 dfrepeat.which |= WSKBD_KEYREPEAT_DODELN; 200 if (dfrepeat.which != 0 && 201 ioctl(fd, WSKBDIO_SETDEFAULTKEYREPEAT, &dfrepeat) < 0) 202 err(1, "WSKBDIO_SETDEFAULTKEYREPEAT"); 203 if (dfrepeat.which &WSKBD_KEYREPEAT_DODEL1) 204 pr_field(field_by_value(&dfrepeat.del1), " -> "); 205 if (dfrepeat.which & WSKBD_KEYREPEAT_DODELN) 206 pr_field(field_by_value(&dfrepeat.delN), " -> "); 207 208 if (field_by_value(&ledstate)->flags & FLG_SET) { 209 if (ioctl(fd, WSKBDIO_SETLEDS, &ledstate) < 0) 210 err(1, "WSKBDIO_SETLEDS"); 211 pr_field(field_by_value(&ledstate), " -> "); 212 } 213 214 if (field_by_value(&kbdencoding)->flags & FLG_SET) { 215 if (ioctl(fd, WSKBDIO_SETENCODING, &kbdencoding) < 0) 216 err(1, "WSKBDIO_SETENCODING"); 217 pr_field(field_by_value(&kbdencoding), " -> "); 218 } 219 } 220