From f665595f0f0f9bbe3d7b62c7b9e7f34125d87e11 Mon Sep 17 00:00:00 2001 From: Justin Hirsch Date: Mon, 25 Feb 2019 15:13:21 -0800 Subject: [PATCH] Fix custom baud rate for termios on apple --- c/common/i2cdriver.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/c/common/i2cdriver.c b/c/common/i2cdriver.c index 852e7c8..331fd18 100644 --- a/c/common/i2cdriver.c +++ b/c/common/i2cdriver.c @@ -126,14 +126,15 @@ int openSerialPort(const char *portname) perror(portname); return -1; } - tcgetattr(fd, &Settings); -#if defined(__APPLE__) && !defined(B1000000) -#define B1000000 1000000 -#endif +#if defined(__APPLE__) && !defined(B1000000) + #include +#else cfsetispeed(&Settings, B1000000); cfsetospeed(&Settings, B1000000); +#endif + cfmakeraw(&Settings); Settings.c_cc[VMIN] = 1; @@ -142,6 +143,11 @@ int openSerialPort(const char *portname) return -1; } +#if defined(__APPLE__) && !defined(B1000000) + speed_t speed = (speed_t)1000000; + ioctl(fd, IOSSIOSPEED, &speed); +#endif + return fd; }