refactor stdin prep

This commit is contained in:
Yeo Kheng Meng
2016-10-29 18:49:24 +08:00
parent ade0cdc3cd
commit c60e0334bd

View File

@@ -15,6 +15,20 @@ let serialPort: SerialPort = SerialPort(path: portName)
var myturn = true
// Prepares the stdin so we can getchar() without echoing
func prepareStdin() {
// Set up the control structure
var settings = termios()
// Get options structure for stdin
tcgetattr(STDIN_FILENO, &settings)
//Turn off ICANON and ECHO
settings.c_lflag &= ~tcflag_t(ICANON | ECHO)
tcsetattr(STDIN_FILENO, TCSANOW, &settings)
}
func getKeyPress () -> UnicodeScalar {
let valueRead: Int = Int(getchar())
@@ -55,20 +69,7 @@ do {
transmitRate: .baud9600,
minimumBytesToRead: 1)
/* These prepares the stdin so we can getchar() without echoing */
// Set up the control structure
var settings = termios()
// Get options structure for stdin
tcgetattr(STDIN_FILENO, &settings)
//Turn off ICANON and ECHO
settings.c_lflag &= ~tcflag_t(ICANON | ECHO)
tcsetattr(STDIN_FILENO, TCSANOW, &settings)
prepareStdin()
//Turn off output buffering if not multiple threads will have problems printing