Class for using BMP180 Bosch Pressure sensor

Dependents:   ILI9341_Clock_Nucleo IoT-Polytech-Upmc

Revision:
2:4749ef781396
Parent:
1:4c6b41f1203d
Child:
3:f9ac42af2020
diff -r 4c6b41f1203d -r 4749ef781396 BMP180.h
--- a/BMP180.h	Tue Nov 26 08:29:44 2013 +0000
+++ b/BMP180.h	Tue Nov 26 19:56:05 2013 +0000
@@ -22,22 +22,13 @@
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
+*
+* Bosch data sheet at: http://ae-bst.resource.bosch.com/media/products/dokumente/bmp180/BST-BMP180-DS000-09.pdf
+* Some parts of the calculations used are infact from Rom Clement published Mbed code here: https://mbed.org/users/Rom/code/Barometer_bmp085/
+*   I only used snippets of the Rom's code because i was making this into a class and so this is structured totaly different then his code example is.
+* I also used the Bosch data sheet showing the calculations and adjusted everything accordingly!
 */
 
-/** BMP180 Digital Pressure Sensor class using mbed's i2c class
- *
- * Example:
- * @code
- * // show how the BMP180 class works
- * #include "BMP180.h"
- * #include "mbed.h"
- *
- * Serial pc(USBTX, USBRX); // tx, rx  for debug and usb pc comunications
- *
- *
- * @endcode
- */
-
 #include "mbed.h"
 
 #define EEprom 22            // The EEPROM has 176bits of calibration data (176/8 = 22 Bytes)
@@ -45,31 +36,106 @@
 #define BMP180FREQ 1000000   // Data sheet says 3.4 MHz is max but not sure what mbed can do here!
 #define CMD_READ_VALUE 0xF6
 #define CMD_READ_CALIBRATION 0xAA
-#define OVERSAMPLING_ULTRA_LOW_POWER 0
+#define OVERSAMPLING_ULTRA_LOW_POWER 0  // these are the constants used in the oversample variable in the below code!
 #define OVERSAMPLING_STANDARD 1
 #define OVERSAMPLING_HIGH_RESOLUTION 2
 #define OVERSAMPLING_ULTRA_HIGH_RESOLUTION 3
 
+
+/** BMP180 Digital Pressure Sensor class using mbed's i2c class
+ *
+ * Example:
+ * @code
+ * // show how the BMP180 class works
+ * #include "mbed.h"
+ * #include "BMP180.h"
+ *
+ * int main()
+ * {
+ *
+ *    long temp ;
+ *    long pressure;
+ *    int error ;
+ *    BMP180 mybmp180(p9,p10);
+ *    while(1) {
+ *        error = mybmp180.readTP(&temp,&pressure,OVERSAMPLING_ULTRA_HIGH_RESOLUTION);
+ *        printf("Temp is %ld\r\n",temp);
+ *        printf("Pressure is %ld\r\n",pressure);
+ *        printf("Error is %d\r\n\r\n",error);
+ *        wait(2);
+ *    }
+ * }
+ * @endcode
+ */
+
 class BMP180
 {
 public:
     /** Create object connected to BMP180 pins ( remember both pins need pull up resisters)
         *
         * Ensure the pull up resistors are used on these pins.  Also note there is no checking on
-        *  if you use thes pins p9, p10, p27, p28 so ensure you only use these ones on the LPC1768 device
+        *  if you use these pins p9, p10, p27, p28 so ensure you only use these ones on the LPC1768 device
         *
-        * @param sda pin that DS1307 connected to (p9 or p28 as defined on LPC1768)
-        * @param slc pin that DS1307 connected to (p10 or p27 ad defined on LPC1768)
+        * @param sda pin that BMP180 connected to (p9 or p28 as defined on LPC1768)
+        * @param slc pin that BMP180 connected to (p10 or p27 ad defined on LPC1768)
         */
-    BMP180(PinName sda, PinName slc);  // Constructor
+    BMP180(PinName sda, PinName slc);   // Constructor
+
+    ~BMP180();                          // Destructor
 
-    ~BMP180();          // Destructor
-
+    /** Read Temperature and Pressure at the same time
+    *
+    * This function will only return when it has readings.  This means that the time will vary depending on oversample setting!
+    *   Note if your code can not wait for these readings to be taken and calculated you should use the functions below.
+    *     These other functions are designed to allow your code to do other things then get the final readings.
+    *     This function is only designed as a one shot give me the answer function.
+    *
+    * @param t the temperature fully compensated value is returned in this variable. Degrees celsius with one decimal so 253 is 25.3 C.
+    * @param p the barometric pressure fully compensated value is returned in this variable. Pressure is in Pa so 88007 is 88.007 kPa.
+    * @param oversample is the method method for reading sensor.  OVERSAMPLING_ULTRA_HIGH_RESOLUTION is used if an incorrect value is passed to this function.
+    * @param returns 0 for no errors during i2c communication.  Any other number is just a i2c communication failure of some kind!
+    */
     int readTP(long *t, long *p, int oversample);    // get both temperature and pressure fully compensated values! Note this only returns when measurements are complete
 
+    /** Start the temperature reading process but return after the commands are issued to BMP180
+    *
+    * This function is ment to start the temperature reading process but will return to allow other code to run then a reading could be made at a later time.
+    *   Note the maximum time needed for this measurment is 4.5 ms.
+    *
+    * @param returns 0 for no errors during i2c communication.  Any other number is just a i2c communication failure of some kind!
+    */
     int startTemperature();             // Start temperature measurement
+
+    /** Reads the last temperature reading that was started with startTemperature() function
+    *
+    * This function will return the fully compensated value of the temperature in Degrees celsius with one decimal so 253 is 25.3 C.
+    *   Note this function should normaly follow the startTemperature() function and should also preceed the startPressure() and readPressure() commands!
+    *   Note this function should follow startTemperature() after 4.5 ms min has elapsed or reading will be incorrect.
+    *
+    * @param t the temperature fully compensated value is returned in this variable.
+    * @param returns 0 for no errors during i2c communication.  Any other number is just a i2c communication failure of some kind!
+    */
     int readTemperature(long *t);       // Get the temperature reading that was taken in startTemperature() but ensure 4.5 ms time has elapsed
+
+    /** Start the pressure reading process but return after the commands are issued to BMP180
+    *
+    * This function is ment to start the pressure reading process but will return to allow other code to run then a reading could be made at a later time.
+    *   Note the time needed for this reading pressure process will depend on oversample setting.  The maximum time is 25.5 ms and minimum time is 4.5 ms.
+    *
+    * @param oversample is the method for reading sensor.  OVERSAMPLING_ULTRA_HIGH_RESOLUTION is used if an incorrect value is passed to this function.
+    * @param returns 0 for no errors during i2c communication.  Any other number is just a i2c communication failure of some kind!
+    */
     int startPressure(int oversample);  // Start pressure measurement!  Note oversample will vary the time to complete this measurement. See defines above for oversampling constants to use!
+
+    /** Reads the last barometric pressure reading that was started with readTemperature() function
+    *
+    * This function will return the fully compensated value of the barometric pressure in Pa.
+    *   Note this function should follow startPressure() after the time needed to read the pressure.  This time will vary but maximum time is 25.5 ms and minimum time is 4.5 ms.
+    *   Note that this reading is dependent on temperature so the startTemperature() and readTemperature() functions should proceed this function or the pressure value will be incorrect!
+    *
+    * @param p the barometric pressure fully compensated value is returned in this variable. Pressure is in Pa so 88007 is 88.007 kPa.
+    * @param returns 0 for no errors during i2c communication.  Any other number is just a i2c communication failure of some kind!
+    */
     int readPressure(long *p);          // Get the pressure reading that was taken in startPressure() but ensure time for the measurement to complete
 
 protected: