mirror of
https://github.com/overte-org/overte.git
synced 2025-08-07 13:30:33 +02:00
if we fail to open SerialInterface twice then don't keep trying
This commit is contained in:
parent
69734f41fc
commit
0b810fa4c2
2 changed files with 28 additions and 17 deletions
|
@ -34,6 +34,11 @@ const int GRAVITY_SAMPLES = 200; // Use the first samples to
|
|||
|
||||
const bool USING_INVENSENSE_MPU9150 = 1;
|
||||
|
||||
SerialInterface::SerialInterface() :
|
||||
active(false),
|
||||
_failedOpenAttempts(0) {
|
||||
}
|
||||
|
||||
void SerialInterface::pair() {
|
||||
|
||||
#ifdef __APPLE__
|
||||
|
@ -43,6 +48,9 @@ void SerialInterface::pair() {
|
|||
int matchStatus;
|
||||
regex_t regex;
|
||||
|
||||
if (_failedOpenAttempts < 2) {
|
||||
// if we've already failed to open the detected interface twice then don't try again
|
||||
|
||||
// for now this only works on OS X, where the usb serial shows up as /dev/tty.usb*
|
||||
if((devDir = opendir("/dev"))) {
|
||||
while((entry = readdir(devDir))) {
|
||||
|
@ -60,8 +68,9 @@ void SerialInterface::pair() {
|
|||
}
|
||||
closedir(devDir);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
// connect to the serial port
|
||||
|
@ -73,6 +82,7 @@ int SerialInterface::initializePort(char* portname, int baud) {
|
|||
|
||||
if (serialFd == -1) {
|
||||
printLog("Failed.\n");
|
||||
_failedOpenAttempts++;
|
||||
return -1; // Failed to open port
|
||||
}
|
||||
struct termios options;
|
||||
|
|
|
@ -36,7 +36,7 @@ extern const bool USING_INVENSENSE_MPU9150;
|
|||
|
||||
class SerialInterface {
|
||||
public:
|
||||
SerialInterface() { active = false; };
|
||||
SerialInterface();
|
||||
void pair();
|
||||
void readData();
|
||||
|
||||
|
@ -68,6 +68,7 @@ private:
|
|||
int _lastYaw;
|
||||
int _lastPitch;
|
||||
int _lastRoll;
|
||||
int _failedOpenAttempts;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue