keyboard.c revision 66834
130044Ssos/*-
230044Ssos * Copyright (c) 1997 S�ren Schmidt
330044Ssos * All rights reserved.
430044Ssos *
530044Ssos * Redistribution and use in source and binary forms, with or without
630044Ssos * modification, are permitted provided that the following conditions
730044Ssos * are met:
830044Ssos * 1. Redistributions of source code must retain the above copyright
930044Ssos *    notice, this list of conditions and the following disclaimer
1030044Ssos *    in this position and unchanged.
1130044Ssos * 2. Redistributions in binary form must reproduce the above copyright
1230044Ssos *    notice, this list of conditions and the following disclaimer in the
1330044Ssos *    documentation and/or other materials provided with the distribution.
1430044Ssos * 3. The name of the author may not be used to endorse or promote products
1530044Ssos *    derived from this software withough specific prior written permission
1630044Ssos *
1730044Ssos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1830044Ssos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1930044Ssos * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2030044Ssos * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2130044Ssos * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2230044Ssos * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2330044Ssos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2430044Ssos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2530044Ssos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2630044Ssos * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2730044Ssos *
2850476Speter * $FreeBSD: head/lib/libvgl/keyboard.c 66834 2000-10-08 21:34:00Z phk $
2930044Ssos */
3030044Ssos
3130044Ssos#include <stdio.h>
3230044Ssos#include <sys/types.h>
3330044Ssos#include <sys/ioctl.h>
3430044Ssos#include <termios.h>
3530044Ssos#include <sys/time.h>
3666834Sphk#include <sys/fbio.h>
3766834Sphk#include <sys/kbio.h>
3830044Ssos#include "vgl.h"
3930044Ssos
4030044Ssosstatic struct termios VGLKeyboardTty;
4130044Ssosstatic int VGLKeyboardMode = -1;
4230044Ssos
4330044Ssosint
4430044SsosVGLKeyboardInit(int mode)
4530044Ssos{
4630044Ssos  static struct termios term;
4730044Ssos
4830044Ssos  ioctl(0, KDGKBMODE, &VGLKeyboardMode);
4930044Ssos  tcgetattr(0, &VGLKeyboardTty);
5030044Ssos
5130044Ssos  term = VGLKeyboardTty;
5250141Syokota  cfmakeraw(&term);
5330044Ssos  term.c_iflag = IGNPAR | IGNBRK;
5430044Ssos  term.c_oflag = 0;
5530044Ssos  term.c_cflag = CREAD | CS8;
5630044Ssos  term.c_lflag &= ~(ICANON | ECHO | ISIG);
5730044Ssos  term.c_cc[VTIME] = 0;
5830044Ssos  term.c_cc[VMIN] = 0;
5930044Ssos  cfsetispeed(&term, 9600);
6030044Ssos  cfsetospeed(&term, 9600);
6130044Ssos  tcsetattr(0, TCSANOW, &term);
6230044Ssos
6330044Ssos  switch (mode) {
6430044Ssos  case VGL_RAWKEYS:
6530044Ssos    ioctl(0, KDSKBMODE, K_RAW);
6630044Ssos    break;
6730044Ssos  case VGL_CODEKEYS:
6830044Ssos    ioctl(0, KDSKBMODE, K_CODE);
6930044Ssos    break;
7030044Ssos  case VGL_XLATEKEYS:
7130044Ssos    ioctl(0, KDSKBMODE, K_XLATE);
7230044Ssos    break;
7330044Ssos  }
7430044Ssos  return 0;
7530044Ssos}
7630044Ssos
7730044Ssosvoid
7830044SsosVGLKeyboardEnd()
7930044Ssos{
8050141Syokota  if (VGLKeyboardMode != -1) {
8130044Ssos    ioctl(0, KDSKBMODE, VGLKeyboardMode);
8250141Syokota    tcsetattr(0, TCSANOW, &VGLKeyboardTty);
8350141Syokota  }
8430044Ssos}
8530044Ssos
8630044Ssosint
8730044SsosVGLKeyboardGetCh()
8830044Ssos{
8930044Ssos  unsigned char ch = 0;
9030044Ssos
9130044Ssos  read (0, &ch, 1);
9230044Ssos  return (int)ch;
9330044Ssos}
94