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 | 35 | const bool USING_INVENSENSE_MPU9150 = 1; |
| 36 | 36 | |
| 37 | +SerialInterface::SerialInterface() : | |
| 38 | + active(false), | |
| 39 | + _failedOpenAttempts(0) { | |
| 40 | +} | |
| 41 | + | |
| 37 | 42 | void SerialInterface::pair() { |
| 38 | 43 | |
| 39 | 44 | #ifdef __APPLE__ |
| @@ -43,25 +48,29 @@ void SerialInterface::pair() { · 3 unmodified lines | ||
| 43 | 48 | int matchStatus; |
| 44 | 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* | |
| 47 | − if((devDir = opendir("/dev"))) { | |
| 48 | − while((entry = readdir(devDir))) { | |
| 49 | − regcomp(®ex, "tty\\.usb", REG_EXTENDED|REG_NOSUB); | |
| 50 | − matchStatus = regexec(®ex, entry->d_name, (size_t) 0, NULL, 0); | |
| 51 | − if (matchStatus == 0) { | |
| 52 | − char *serialPortname = new char[100]; | |
| 53 | − sprintf(serialPortname, "/dev/%s", entry->d_name); | |
| 54 | − | |
| 55 | − initializePort(serialPortname, 115200); | |
| 56 | − | |
| 57 | − delete [] serialPortname; | |
| 51 | + if (_failedOpenAttempts < 2) { | |
| 52 | + // if we've already failed to open the detected interface twice then don't try again | |
| 53 | + | |
| 54 | + // for now this only works on OS X, where the usb serial shows up as /dev/tty.usb* | |
| 55 | + if((devDir = opendir("/dev"))) { | |
| 56 | + while((entry = readdir(devDir))) { | |
| 57 | + regcomp(®ex, "tty\\.usb", REG_EXTENDED|REG_NOSUB); | |
| 58 | + matchStatus = regexec(®ex, entry->d_name, (size_t) 0, NULL, 0); | |
| 59 | + if (matchStatus == 0) { | |
| 60 | + char *serialPortname = new char[100]; | |
| 61 | + sprintf(serialPortname, "/dev/%s", entry->d_name); | |
| 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 | 76 | // connect to the serial port |
| @@ -73,6 +82,7 @@ int SerialInterface::initializePort(char* portname, int baud) { · 5 unmodified lines | ||
| 73 | 82 | |
| 74 | 83 | if (serialFd == -1) { |
| 75 | 84 | printLog("Failed.\n"); |
| 85 | + _failedOpenAttempts++; | |
| 76 | 86 | return -1; // Failed to open port |
| 77 | 87 | } |
| 78 | 88 | struct termios options; |