Add scancode reading capability to TTY

This commit is contained in:
Erik van der Kouwe 2010-04-15 06:55:42 +00:00
parent 32f43d7571
commit 7de730afe4
7 changed files with 64 additions and 16 deletions

View File

@ -591,14 +591,14 @@ int try;
if (ch <= 0xFF) {
/* A normal character. */
buf[0] = ch;
(void) in_process(tp, buf, 1);
(void) in_process(tp, buf, 1, scode);
} else
if (HOME <= ch && ch <= INSRT) {
/* An ASCII escape sequence generated by the numeric pad. */
buf[0] = ESC;
buf[1] = '[';
buf[2] = numpad_map[ch - HOME];
(void) in_process(tp, buf, 3);
(void) in_process(tp, buf, 3, scode);
} else
if ((F1 <= ch && ch <= F12) || (SF1 <= ch && ch <= SF12) ||
(CF1 <= ch && ch <= CF12 && !debug_fkeys)) {
@ -626,7 +626,7 @@ int try;
*p++ = suffix;
}
*p++ = '~';
(void) in_process(tp, buf, p - buf);
(void) in_process(tp, buf, p - buf, scode);
} else
if (ch == ALEFT) {
/* Choose lower numbered console as current console. */
@ -651,6 +651,9 @@ int try;
case CF8: sigchar(&tty_table[CONSOLE], SIGINT, 1); break;
case CF9: sigchar(&tty_table[CONSOLE], SIGKILL, 1); break;
}
} else {
/* pass on scancode even though there is no character code */
(void) in_process(tp, NULL, 0, scode);
}
}

View File

@ -417,7 +417,7 @@ PRIVATE int pty_read(tty_t *tp, int try)
}
/* Input processing. */
if (in_process(tp, &c, 1) == 0) break;
if (in_process(tp, &c, 1, -1) == 0) break;
/* PTY writer bookkeeping. */
pp->wrcum++;

View File

@ -619,7 +619,7 @@ PRIVATE int rs_read(tty_t *tp, int try)
if (count > icount) count = icount;
/* Perform input processing on (part of) the input buffer. */
if ((count = in_process(tp, rs->itail, count)) == 0) break;
if ((count = in_process(tp, rs->itail, count, -1)) == 0) break;
lock(); /* protect interrupt sensitive variables */
rs->icount -= count;

View File

@ -1036,10 +1036,26 @@ register tty_t *tp; /* pointer to terminal to read from */
/*===========================================================================*
* in_process *
*===========================================================================*/
PUBLIC int in_process(tp, buf, count)
PRIVATE void in_process_send_byte(tp, ch)
tty_t *tp; /* terminal on which character has arrived */
int ch; /* input character */
{
/* Save the character in the input queue. */
*tp->tty_inhead++ = ch;
if (tp->tty_inhead == bufend(tp->tty_inbuf))
tp->tty_inhead = tp->tty_inbuf;
tp->tty_incount++;
if (ch & IN_EOT) tp->tty_eotct++;
/* Try to finish input if the queue threatens to overflow. */
if (tp->tty_incount == buflen(tp->tty_inbuf)) in_transfer(tp);
}
PUBLIC int in_process(tp, buf, count, scode)
register tty_t *tp; /* terminal on which character has arrived */
char *buf; /* buffer with input characters */
int count; /* number of input characters */
int scode; /* scan code */
{
/* Characters have just been typed in. Process, save, and echo them. Return
* the number of characters processed.
@ -1048,6 +1064,11 @@ int count; /* number of input characters */
int ch, sig, ct;
int timeset = FALSE;
/* Send scancode if requested */
if (tp->tty_termios.c_iflag & SCANCODES) {
in_process_send_byte(tp, (scode & BYTE) | IN_EOT);
}
for (ct = 0; ct < count; ct++) {
/* Take one character. */
ch = *buf++ & BYTE;
@ -1180,15 +1201,10 @@ int count; /* number of input characters */
/* Perform the intricate function of echoing. */
if (tp->tty_termios.c_lflag & (ECHO|ECHONL)) ch = tty_echo(tp, ch);
/* Save the character in the input queue. */
*tp->tty_inhead++ = ch;
if (tp->tty_inhead == bufend(tp->tty_inbuf))
tp->tty_inhead = tp->tty_inbuf;
tp->tty_incount++;
if (ch & IN_EOT) tp->tty_eotct++;
/* Try to finish input if the queue threatens to overflow. */
if (tp->tty_incount == buflen(tp->tty_inbuf)) in_transfer(tp);
/* Send processed byte of input unless scancodes sent instead */
if (!(tp->tty_termios.c_iflag & SCANCODES)) {
in_process_send_byte(tp, ch);
}
}
return ct;
}
@ -1502,6 +1518,9 @@ tty_t *tp;
/* Setting the output speed to zero hangs up the phone. */
if (tp->tty_termios.c_ospeed == B0) sigchar(tp, SIGHUP, 1);
/* SCANCODES is supported only for the console */
if (!isconsole(tp)) tp->tty_termios.c_iflag &= ~SCANCODES;
/* Set new line speed, character size, etc at the device level. */
(*tp->tty_ioctl)(tp, 0);
}

View File

@ -147,7 +147,8 @@ extern struct kmessages kmess;
_PROTOTYPE( void handle_events, (struct tty *tp) );
_PROTOTYPE( void sigchar, (struct tty *tp, int sig, int mayflush) );
_PROTOTYPE( void tty_task, (void) );
_PROTOTYPE( int in_process, (struct tty *tp, char *buf, int count) );
_PROTOTYPE( int in_process, (struct tty *tp, char *buf, int count,
int scode) );
_PROTOTYPE( void out_process, (struct tty *tp, char *bstart, char *bpos,
char *bend, int *icount, int *ocount) );
_PROTOTYPE( void tty_wakeup, (clock_t now) );

View File

@ -146,6 +146,7 @@ _PROTOTYPE( int tcsetattr, \
/* Extensions to the termios c_iflag bit map. */
#define IXANY 0x0800 /* allow any key to continue ouptut */
#define SCANCODES 0x1000 /* send scancodes */
/* Extensions to the termios c_oflag bit map. They are only active iff
* OPOST is enabled. */

View File

@ -315,6 +315,30 @@ is set a break is input as a single '\e0', or if
.B PARMRK
is set as '\e377', '\e0', '\e0'.
(Breaks are always ignored.)
.TP
.B SCANCODES
Send input as keyboard scancodes rather than processed ASCII characters. This
flag only applies to consoles; to check whether the flag is supported use the
.B tcgetattr
function after setting it and test whether
.B c_iflag
still contains the
.B SCANCODES
flag. Scancodes are provided directly and without any processing. As a
consequence, the
.B ISTRIP
,
.B IGNCR
,
.B ICRNL
,
.B INLCR
,
.B ICANON
and
.B IEXTEN
flags no longer influence input if this flag is specified. However, they may
still influence echoing if enabled. (MINIX 3 specific.)
.SS "Output Modes"
The
.B c_oflag