-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Trevor Flowers' mini VT100.
- Loading branch information
1 parent
0fe6abf
commit 208a638
Showing
5 changed files
with
83 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include <unistd.h> | ||
#include <sys/ioctl.h> | ||
#include "vt100.h" | ||
|
||
int flowers = 0; // Trevor Flowers' mini VT100. | ||
|
||
void flowers_leds(u8 data) | ||
{ | ||
char command[100]; | ||
int n; | ||
if (!flowers) | ||
return; | ||
n = snprintf(command, sizeof command, "\nSET_ALL_LEDS %c%c%c%c%c%c%c\n", | ||
(data & 0x20) ? '0' : '1', | ||
(data & 0x20) ? '1' : '0', | ||
(data & 0x10) ? '1' : '0', | ||
(data & 0x08) ? '1' : '0', | ||
(data & 0x04) ? '1' : '0', | ||
(data & 0x02) ? '1' : '0', | ||
(data & 0x01) ? '1' : '0'); | ||
write(flowers, command, n); | ||
} | ||
|
||
static const char *const prefix = "\nSPECIAL_KEY: "; | ||
static const char *pointer = prefix; | ||
|
||
int flowers_key(void) | ||
{ | ||
char data; | ||
int n; | ||
|
||
if (ioctl(flowers, FIONREAD, &n) != 0) | ||
return -1; | ||
if (n < 1) | ||
return -1; | ||
if (read(flowers, &data, 1) != 1) | ||
return -1; | ||
|
||
if (*pointer == 0) { | ||
pointer = prefix; | ||
return data; | ||
} | ||
|
||
if (data != *pointer) | ||
pointer = prefix; | ||
if (data == *pointer) | ||
pointer++; | ||
|
||
return -1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters