Skip to content

Commit

Permalink
ping360: Avoid unnecessary baud rate changes
Browse files Browse the repository at this point in the history
Check variables before selecting the new baud rate

Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
  • Loading branch information
patrickelectric authored and jaxxzer committed Aug 8, 2019
1 parent 4d69cc5 commit 111a385
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/sensor/ping360.cpp
Expand Up @@ -341,16 +341,13 @@ void Ping360::detectBaudrates()
static int lastParserErrorCount = 0;
static int lastParserMsgsCount = 0;

// Check error margin
int lastCounter = -1;

if(!_configuring) {
return;
}

if(index < validBaudRates().size()) {
setBaudRate(validBaudRates()[index]);
}

int lastCounter = -1;

// We have already something to calculate
if(index != 0) {
// Get previous baud rate and error margin
Expand All @@ -364,10 +361,9 @@ void Ping360::detectBaudrates()
}
lastParserErrorCount = parserErrors();
lastParserMsgsCount = parsedMsgs();
index++;

// We are in the end of the list or someone is the winner!
if(index == validBaudRates().size() || lastCounter == 0) {
if(index == validBaudRates().size() - 1 || lastCounter == 0) {
_configuring = false;

// The actual baud rate is the winner, don't need to set a new one
Expand All @@ -389,7 +385,13 @@ void Ping360::detectBaudrates()
}

setBaudRate(validBaudRates()[index]);
qCDebug(PING_PROTOCOL_PING360) << "Baud rate procedure done.";
return;
}

// Check next baud rate
setBaudRate(validBaudRates()[index]);
index++;
}

Ping360::~Ping360()
Expand Down

0 comments on commit 111a385

Please sign in to comment.