Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
BMP180Wrapper.cpp@2:e28e685938f1, 2020-05-30 (annotated)
- Committer:
- marcel1691
- Date:
- Sat May 30 12:05:18 2020 +0000
- Revision:
- 2:e28e685938f1
- Parent:
- 1:02f543f15108
DevI2C obsolet durch I2C ersetzt
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| marcel1691 | 1:02f543f15108 | 1 | /** |
| marcel1691 | 1:02f543f15108 | 2 | * Bosch BMP180 Digital Pressure Sensor |
| marcel1691 | 1:02f543f15108 | 3 | */ |
| marcel1691 | 1:02f543f15108 | 4 | |
| marcel1691 | 1:02f543f15108 | 5 | #include <BMP180Wrapper.h> |
| marcel1691 | 1:02f543f15108 | 6 | |
| marcel1691 | 2:e28e685938f1 | 7 | BMP180Wrapper::BMP180Wrapper( I2C* i2c ) : bmp180(i2c) |
| marcel1691 | 1:02f543f15108 | 8 | { |
| marcel1691 | 1:02f543f15108 | 9 | } |
| marcel1691 | 1:02f543f15108 | 10 | |
| marcel1691 | 1:02f543f15108 | 11 | int BMP180Wrapper::init( void* init ) |
| marcel1691 | 1:02f543f15108 | 12 | { |
| marcel1691 | 1:02f543f15108 | 13 | while ( 1 ) |
| marcel1691 | 1:02f543f15108 | 14 | { |
| marcel1691 | 1:02f543f15108 | 15 | if ( bmp180.init() != 0 ) |
| marcel1691 | 1:02f543f15108 | 16 | { |
| marcel1691 | 1:02f543f15108 | 17 | printf( "Error communicating with BMP180\n" ); |
| marcel1691 | 1:02f543f15108 | 18 | } |
| marcel1691 | 1:02f543f15108 | 19 | else |
| marcel1691 | 1:02f543f15108 | 20 | { |
| marcel1691 | 1:02f543f15108 | 21 | printf( "Initialized BMP180\n" ); |
| marcel1691 | 1:02f543f15108 | 22 | break; |
| marcel1691 | 1:02f543f15108 | 23 | } |
| marcel1691 | 1:02f543f15108 | 24 | wait( 1 ); |
| marcel1691 | 1:02f543f15108 | 25 | } |
| marcel1691 | 1:02f543f15108 | 26 | return ( 0 ); |
| marcel1691 | 1:02f543f15108 | 27 | } |
| marcel1691 | 1:02f543f15108 | 28 | |
| marcel1691 | 1:02f543f15108 | 29 | int BMP180Wrapper::read_id( uint8_t* id ) |
| marcel1691 | 1:02f543f15108 | 30 | { |
| marcel1691 | 1:02f543f15108 | 31 | *id = 0x55; |
| marcel1691 | 1:02f543f15108 | 32 | return ( 0 ); |
| marcel1691 | 1:02f543f15108 | 33 | } |
| marcel1691 | 1:02f543f15108 | 34 | |
| marcel1691 | 1:02f543f15108 | 35 | int BMP180Wrapper::get_humidity( float* pfData ) |
| marcel1691 | 1:02f543f15108 | 36 | { |
| marcel1691 | 1:02f543f15108 | 37 | *pfData = 0.0f; |
| marcel1691 | 1:02f543f15108 | 38 | bmp180.startPressure(BMP180::ULTRA_LOW_POWER); |
| marcel1691 | 1:02f543f15108 | 39 | wait_ms(10); // Wait for conversion to complete |
| marcel1691 | 1:02f543f15108 | 40 | int pressure; |
| marcel1691 | 1:02f543f15108 | 41 | if(bmp180.getPressure(&pressure) == 0) |
| marcel1691 | 1:02f543f15108 | 42 | { |
| marcel1691 | 1:02f543f15108 | 43 | *pfData = pressure / 1000.0f; |
| marcel1691 | 1:02f543f15108 | 44 | } |
| marcel1691 | 1:02f543f15108 | 45 | return ( 0 ); |
| marcel1691 | 1:02f543f15108 | 46 | } |
| marcel1691 | 1:02f543f15108 | 47 | |
| marcel1691 | 1:02f543f15108 | 48 | int BMP180Wrapper::get_temperature( float* pfData ) |
| marcel1691 | 1:02f543f15108 | 49 | { |
| marcel1691 | 1:02f543f15108 | 50 | bmp180.startTemperature(); |
| marcel1691 | 1:02f543f15108 | 51 | wait_ms( 5 ); // Wait for conversion to complete |
| marcel1691 | 1:02f543f15108 | 52 | return ( bmp180.getTemperature( pfData ) ); |
| marcel1691 | 1:02f543f15108 | 53 | } |
| marcel1691 | 1:02f543f15108 | 54 | |
| marcel1691 | 1:02f543f15108 | 55 | int BMP180Wrapper::enable( void ) |
| marcel1691 | 1:02f543f15108 | 56 | { |
| marcel1691 | 1:02f543f15108 | 57 | return ( 0 ); |
| marcel1691 | 1:02f543f15108 | 58 | } |