Allow running without TTY (e.g. in Instruments)
Continue running if TTY cannot be opened
This commit is contained in:
parent
9554f80a00
commit
d212e8f112
14
keyboard.cpp
14
keyboard.cpp
|
@ -111,21 +111,26 @@ unsigned char get_any_key_down_and_clear_strobe()
|
||||||
return 0x00;
|
return 0x00;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool started = false;
|
||||||
|
|
||||||
void start_keyboard()
|
void start_keyboard()
|
||||||
{
|
{
|
||||||
// Set raw mode on stdin.
|
// Set raw mode on stdin.
|
||||||
if (ttyraw(0) < 0) {
|
if (ttyraw(0) < 0) {
|
||||||
fprintf(stderr,"Can't go to raw mode.\n");
|
fprintf(stderr,"Can't go to raw mode. Oh, well!\n");
|
||||||
exit(1);
|
// exit(1);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
started = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void stop_keyboard()
|
void stop_keyboard()
|
||||||
{
|
{
|
||||||
if (ttyreset(0) < 0) {
|
if (started && (ttyreset(0) < 0)) {
|
||||||
fprintf(stderr, "Cannot reset terminal!\n");
|
fprintf(stderr, "Cannot reset terminal!\n");
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
started = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool peek_key(char *k)
|
bool peek_key(char *k)
|
||||||
|
@ -145,6 +150,9 @@ void poll_keyboard()
|
||||||
int i;
|
int i;
|
||||||
char c;
|
char c;
|
||||||
|
|
||||||
|
if(!started)
|
||||||
|
return;
|
||||||
|
|
||||||
i = read(0, &c, 1);
|
i = read(0, &c, 1);
|
||||||
if (i == -1) {
|
if (i == -1) {
|
||||||
if (errno == EAGAIN) {
|
if (errno == EAGAIN) {
|
||||||
|
|
Loading…
Reference in New Issue