From 9fb3b13af32e6ae0aae006d78e6797e526306176 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 4 Jan 2012 16:35:16 +1100 Subject: [PATCH] AP_Baro: when I2c fails, don't retry for 1s --- libraries/AP_Baro/AP_Baro_BMP085.cpp | 12 ++++++++++++ libraries/AP_Baro/AP_Baro_BMP085.h | 1 + 2 files changed, 13 insertions(+) diff --git a/libraries/AP_Baro/AP_Baro_BMP085.cpp b/libraries/AP_Baro/AP_Baro_BMP085.cpp index e88016f362..611fe58885 100644 --- a/libraries/AP_Baro/AP_Baro_BMP085.cpp +++ b/libraries/AP_Baro/AP_Baro_BMP085.cpp @@ -152,7 +152,13 @@ void AP_Baro_BMP085::ReadPress() { uint8_t buf[3]; + if (!healthy && millis() < _retry_time) { + return; + } + if (I2c.read(BMP085_ADDRESS, 0xF6, 3, buf) != 0) { + _retry_time = millis() + 1000; + I2c.setSpeed(false); healthy = false; return; } @@ -197,7 +203,13 @@ void AP_Baro_BMP085::ReadTemp() { uint8_t buf[2]; + if (!healthy && millis() < _retry_time) { + return; + } + if (I2c.read(BMP085_ADDRESS, 0xF6, 2, buf) != 0) { + _retry_time = millis() + 1000; + I2c.setSpeed(false); healthy = false; return; } diff --git a/libraries/AP_Baro/AP_Baro_BMP085.h b/libraries/AP_Baro/AP_Baro_BMP085.h index ea9e5742b0..8e08965996 100644 --- a/libraries/AP_Baro/AP_Baro_BMP085.h +++ b/libraries/AP_Baro/AP_Baro_BMP085.h @@ -50,6 +50,7 @@ class AP_Baro_BMP085 : public AP_Baro uint8_t _temp_index; uint8_t _press_index; + uint32_t _retry_time; void Command_ReadPress(); void Command_ReadTemp();