From 6b85d93aeec22f47dc1c619e6643ee2f62b9933c Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Mon, 13 May 2013 18:52:43 -0700 Subject: [PATCH] Simplified serial port init to not use baud. --- interface/src/SerialInterface.cpp | 29 ++++++----------------------- interface/src/SerialInterface.h | 2 +- interface/src/main.cpp | 4 ++-- 3 files changed, 9 insertions(+), 26 deletions(-) diff --git a/interface/src/SerialInterface.cpp b/interface/src/SerialInterface.cpp index 961115df81..9fb022471f 100644 --- a/interface/src/SerialInterface.cpp +++ b/interface/src/SerialInterface.cpp @@ -36,7 +36,7 @@ void SerialInterface::pair() { char *serialPortname = new char[100]; sprintf(serialPortname, "/dev/%s", entry->d_name); - initializePort(serialPortname, 115200); + initializePort(serialPortname); delete [] serialPortname; } @@ -48,7 +48,7 @@ void SerialInterface::pair() { } // connect to the serial port -void SerialInterface::initializePort(char* portname, int baud) { +void SerialInterface::initializePort(char* portname) { #ifdef __APPLE__ _serialDescriptor = open(portname, O_RDWR | O_NOCTTY | O_NDELAY); @@ -61,32 +61,15 @@ void SerialInterface::initializePort(char* portname, int baud) { struct termios options; tcgetattr(_serialDescriptor, &options); - - switch(baud) { - case 9600: cfsetispeed(&options,B9600); - cfsetospeed(&options,B9600); - break; - case 19200: cfsetispeed(&options,B19200); - cfsetospeed(&options,B19200); - break; - case 38400: cfsetispeed(&options,B38400); - cfsetospeed(&options,B38400); - break; - case 115200: cfsetispeed(&options,B115200); - cfsetospeed(&options,B115200); - break; - default:cfsetispeed(&options,B9600); - cfsetospeed(&options,B9600); - break; - } - - options.c_cflag |= (CLOCAL | CREAD); + + options.c_cflag |= (CLOCAL | CREAD | CS8); options.c_cflag &= ~PARENB; options.c_cflag &= ~CSTOPB; options.c_cflag &= ~CSIZE; - options.c_cflag |= CS8; tcsetattr(_serialDescriptor, TCSANOW, &options); + cfsetispeed(&options,B115200); + cfsetospeed(&options,B115200); if (USING_INVENSENSE_MPU9150) { // block on invensense reads until there is data to read diff --git a/interface/src/SerialInterface.h b/interface/src/SerialInterface.h index f8e8798f0c..9aa7bccf04 100644 --- a/interface/src/SerialInterface.h +++ b/interface/src/SerialInterface.h @@ -60,7 +60,7 @@ public: bool active; private: - void initializePort(char* portname, int baud); + void initializePort(char* portname); void resetSerial(); int _serialDescriptor; diff --git a/interface/src/main.cpp b/interface/src/main.cpp index b78722fce0..824db7453f 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -1812,7 +1812,7 @@ void idle(void) { float deltaTime = 1.f/FPS; - // update behaviors for avatar hand movement: handControl takes mouse values as input, + // update behaviors for avatar hand movement: handControl takes mouse values as input, // and gives back 3D values modulated for smooth transitioning between interaction modes. handControl.update(mouseX, mouseY); myAvatar.setHandMovementValues(handControl.getValues()); @@ -1876,7 +1876,7 @@ void idle(void) { // Read serial port interface devices if (serialPort.active) { - serialPort.readData(); + serialPort.readData(); } // Sample hardware, update view frustum if needed, and send avatar data to mixer/agents