Showing the changes to interface/src/SerialInterface.cpp (1 of 2 files). Show all
Unified · Split
| @@ -34,6 +34,11 @@ const int GRAVITY_SAMPLES = 200; // Use the first samples to · 33 unmodified lines | |||
| 34 | 34 | ||
| 35 | const bool USING_INVENSENSE_MPU9150 = 1; | 35 | const bool USING_INVENSENSE_MPU9150 = 1; |
| 36 | 36 | ||
| 37 | SerialInterface::SerialInterface() : | ||
| 38 | active(false), | ||
| 39 | _failedOpenAttempts(0) { | ||
| 40 | } | ||
| 41 | |||
| 37 | void SerialInterface::pair() { | 42 | void SerialInterface::pair() { |
| 38 | 43 | ||
| 39 | #ifdef __APPLE__ | 44 | #ifdef __APPLE__ |
| @@ -43,25 +48,29 @@ void SerialInterface::pair() { · 3 unmodified lines | |||
| 43 | int matchStatus; | 48 | int matchStatus; |
| 44 | regex_t regex; | 49 | regex_t regex; |
| 45 | 50 | ||
| 46 | // for now this only works on OS X, where the usb serial shows up as /dev/tty.usb* | 51 | if (_failedOpenAttempts < 2) { |
| 47 | if((devDir = opendir("/dev"))) { | 52 | // if we've already failed to open the detected interface twice then don't try again |
| 48 | while((entry = readdir(devDir))) { | 53 | |
| 49 | regcomp(®ex, "tty\\.usb", REG_EXTENDED|REG_NOSUB); | 54 | // for now this only works on OS X, where the usb serial shows up as /dev/tty.usb* |
| 50 | matchStatus = regexec(®ex, entry->d_name, (size_t) 0, NULL, 0); | 55 | if((devDir = opendir("/dev"))) { |
| 51 | if (matchStatus == 0) { | 56 | while((entry = readdir(devDir))) { |
| 52 | char *serialPortname = new char[100]; | 57 | regcomp(®ex, "tty\\.usb", REG_EXTENDED|REG_NOSUB); |
| 53 | sprintf(serialPortname, "/dev/%s", entry->d_name); | 58 | matchStatus = regexec(®ex, entry->d_name, (size_t) 0, NULL, 0); |
| 54 | 59 | if (matchStatus == 0) { | |
| 55 | initializePort(serialPortname, 115200); | 60 | char *serialPortname = new char[100]; |
| 56 | 61 | sprintf(serialPortname, "/dev/%s", entry->d_name); | |
| 57 | delete [] serialPortname; | 62 | |
| 63 | initializePort(serialPortname, 115200); | ||
| 64 | |||
| 65 | delete [] serialPortname; | ||
| 66 | } | ||
| 67 | regfree(®ex); | ||
| 58 | } | 68 | } |
| 59 | regfree(®ex); | 69 | closedir(devDir); |
| 60 | } | 70 | } |
| 61 | closedir(devDir); | ||
| 62 | } | 71 | } |
| 63 | #endif | ||
| 64 | 72 | ||
| 73 | #endif | ||
| 65 | } | 74 | } |
| 66 | 75 | ||
| 67 | // connect to the serial port | 76 | // connect to the serial port |
| @@ -73,6 +82,7 @@ int SerialInterface::initializePort(char* portname, int baud) { · 5 unmodified lines | |||
| 73 | 82 | ||
| 74 | if (serialFd == -1) { | 83 | if (serialFd == -1) { |
| 75 | printLog("Failed.\n"); | 84 | printLog("Failed.\n"); |
| 85 | _failedOpenAttempts++; | ||
| 76 | return -1; // Failed to open port | 86 | return -1; // Failed to open port |
| 77 | } | 87 | } |
| 78 | struct termios options; | 88 | struct termios options; |