Change to comply with mbed os 5.1, as the attach function as used has been deprecated

Dependents:   Barometer-Example LoRaWAN-demo-72-bootcamp

Fork of BMP085 by silabs-abakurs

BMP085 library supporting mbed os low power

Files at this revision

API Documentation at this revision

Comitter:
abouillot
Date:
Thu Mar 02 14:04:09 2017 +0000
Parent:
4:ed587a5331e4
Commit message:
Fixed some display error in traces and made traces switchable with #define TRACE

Changed in this revision

BMP085.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r ed587a5331e4 -r 64852447275f BMP085.cpp
--- a/BMP085.cpp	Mon Jan 30 21:42:49 2017 +0000
+++ b/BMP085.cpp	Thu Mar 02 14:04:09 2017 +0000
@@ -1,6 +1,8 @@
 #include "BMP085.h"
 
+#if defined (TRACE)
 extern Serial pc;
+#endif
 
 void BMP085::init(void)
 {
@@ -24,19 +26,27 @@
 {
     LowPowerTimeout delay;
 
+#if defined (TRACE)
     pc.printf("transfer ");
+#endif
     _state = BMP085_BUSY;
     _i2c.transfer(BMP085_ADDR, tx, tx_len, rx, rx_len, _callback);
+    // set the timeout timer to guard the transfer
     delay.attach(callback(this, &BMP085::_callback_handler_timeout), 2.0);
     while(_state == BMP085_BUSY) {
         sleep();
     }
+    delay.attach(NULL, 0);  // cancel timeout timer
     if (_state == BMP085_TIMEOUT) {
+#if defined (TRACE)
         pc.printf("\ntimeout\n");
+#endif
         _i2c.abort_transfer();
         return -33;
         }
-    pc.printf("completed ");
+#if defined (TRACE)
+    pc.printf(" completed ");
+#endif
     return 0;
 }
 
@@ -44,13 +54,17 @@
 {
     LowPowerTimeout delay;
 
-    pc.printf("bmpWait ");
+#if defined (TRACE)
+    pc.printf(" bmpWait ");
+#endif
     _state = BMP085_BUSY;
     delay.attach(callback(this, &BMP085::_callback_handler_timeout), wait);
     while(_state == BMP085_BUSY) {
         sleep();
     }
+#if defined (TRACE)
     pc.printf("over ");
+#endif
     return 0;
 }
 
@@ -58,7 +72,9 @@
 
 uint16_t BMP085::read_cal_register(BMP085_Register reg)
 {
+#if defined (TRACE)
     pc.printf("\nread_cal_register ");
+#endif
     _tx_buf[0] = reg;
     transfer((char*)_tx_buf, 1, (char*)_rx_buf, 2);
     return (_rx_buf[0] << 8) | _rx_buf[1];
@@ -66,7 +82,9 @@
 
 uint16_t BMP085::read_uc_temperature(void)
 {
-    pc.printf("\read_uc_temperature ");
+#if defined (TRACE)
+    pc.printf("\nread_uc_temperature ");
+#endif
     _tx_buf[0] = BMP085_CTRL;
     _tx_buf[1] = BMP085_CMD_READ_TEMP;
     transfer((char*)_tx_buf, 2, (char*)NULL, 0);
@@ -80,8 +98,10 @@
 
 uint32_t BMP085::read_uc_pressure(void)
 {
-    pc.printf("\read_uc_pressure ");
-        _tx_buf[0] = BMP085_CTRL;
+#if defined (TRACE)
+    pc.printf("\nread_uc_pressure ");
+#endif
+    _tx_buf[0] = BMP085_CTRL;
     _tx_buf[1] = BMP085_CMD_READ_PRESSURE + ((uint8_t)_mode << 6);
     transfer((char*)_tx_buf, 2, (char*)NULL, 0);
 
@@ -137,6 +157,8 @@
 
 void BMP085::_callback_handler_timeout()
 {
-    pc.printf("bmp timeout");
+#if defined (TRACE)
+    pc.printf(" bmp timeout callback ");
+#endif
     _state = BMP085_TIMEOUT;
 }