From ac5f294904232262325602fa355d3cc65bde1ed4 Mon Sep 17 00:00:00 2001 From: dherrada <=> Date: Mon, 1 Jun 2020 14:44:22 -0400 Subject: [PATCH] Moved library to actions, fully documented with doxygen --- .github/workflows/githubci.yml | 32 +++++ Adafruit_BMP085.cpp | 215 +++++++++++++++++++-------------- Adafruit_BMP085.h | 127 ++++++++++++------- README.txt => README.md | 4 +- library.properties | 2 +- 5 files changed, 243 insertions(+), 137 deletions(-) create mode 100644 .github/workflows/githubci.yml rename README.txt => README.md (77%) diff --git a/.github/workflows/githubci.yml b/.github/workflows/githubci.yml new file mode 100644 index 0000000..491510d --- /dev/null +++ b/.github/workflows/githubci.yml @@ -0,0 +1,32 @@ +name: Arduino Library CI + +on: [pull_request, push, repository_dispatch] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/setup-python@v1 + with: + python-version: '3.x' + - uses: actions/checkout@v2 + - uses: actions/checkout@v2 + with: + repository: adafruit/ci-arduino + path: ci + + - name: pre-install + run: bash ci/actions_install.sh + + - name: test platforms + run: python3 ci/build_platform.py main_platforms + + - name: clang + run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r . + + - name: doxygen + env: + GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }} + PRETTYNAME : "Adafruit BMP085 Library" + run: bash ci/doxy_gen_and_deploy.sh diff --git a/Adafruit_BMP085.cpp b/Adafruit_BMP085.cpp index 14e7e96..c78dd86 100644 --- a/Adafruit_BMP085.cpp +++ b/Adafruit_BMP085.cpp @@ -1,34 +1,45 @@ -/*************************************************** - This is a library for the Adafruit BMP085/BMP180 Barometric Pressure + Temp sensor - - Designed specifically to work with the Adafruit BMP085 or BMP180 Breakout - ----> http://www.adafruit.com/products/391 - ----> http://www.adafruit.com/products/1603 - - These displays use I2C to communicate, 2 pins are required to - interface - Adafruit invests time and resources providing this open source code, - please support Adafruit and open-source hardware by purchasing - products from Adafruit! - - Written by Limor Fried/Ladyada for Adafruit Industries. - BSD license, all text above must be included in any redistribution - ****************************************************/ +/*! + * @file Adafruit_BMP085.cpp + * + * @mainpage Adafruit BMP085 Library + * + * @section intro_sec Introduction + * + * This is a library for the Adafruit BMP085/BMP180 Barometric Pressure + Temp + * sensor + * + * Designed specifically to work with the Adafruit BMP085 or BMP180 Breakout + * ----> http://www.adafruit.com/products/391 + * ----> http://www.adafruit.com/products/1603 + * + * These displays use I2C to communicate, 2 pins are required to + * interface + * Adafruit invests time and resources providing this open source code, + * please support Adafruit and open-source hardware by purchasing + * products from Adafruit! + * + * @section author Author + * + * Written by Limor Fried/Ladyada for Adafruit Industries. + * + * @section license License + * + * BSD license, all text above must be included in any redistribution + */ #include "Adafruit_BMP085.h" -Adafruit_BMP085::Adafruit_BMP085() { -} - +Adafruit_BMP085::Adafruit_BMP085() {} boolean Adafruit_BMP085::begin(uint8_t mode) { - if (mode > BMP085_ULTRAHIGHRES) + if (mode > BMP085_ULTRAHIGHRES) mode = BMP085_ULTRAHIGHRES; oversampling = mode; Wire.begin(); - if (read8(0xD0) != 0x55) return false; + if (read8(0xD0) != 0x55) + return false; /* read calibration data */ ac1 = read16(BMP085_CAL_AC1); @@ -45,19 +56,30 @@ boolean Adafruit_BMP085::begin(uint8_t mode) { mc = read16(BMP085_CAL_MC); md = read16(BMP085_CAL_MD); #if (BMP085_DEBUG == 1) - Serial.print("ac1 = "); Serial.println(ac1, DEC); - Serial.print("ac2 = "); Serial.println(ac2, DEC); - Serial.print("ac3 = "); Serial.println(ac3, DEC); - Serial.print("ac4 = "); Serial.println(ac4, DEC); - Serial.print("ac5 = "); Serial.println(ac5, DEC); - Serial.print("ac6 = "); Serial.println(ac6, DEC); - - Serial.print("b1 = "); Serial.println(b1, DEC); - Serial.print("b2 = "); Serial.println(b2, DEC); - - Serial.print("mb = "); Serial.println(mb, DEC); - Serial.print("mc = "); Serial.println(mc, DEC); - Serial.print("md = "); Serial.println(md, DEC); + Serial.print("ac1 = "); + Serial.println(ac1, DEC); + Serial.print("ac2 = "); + Serial.println(ac2, DEC); + Serial.print("ac3 = "); + Serial.println(ac3, DEC); + Serial.print("ac4 = "); + Serial.println(ac4, DEC); + Serial.print("ac5 = "); + Serial.println(ac5, DEC); + Serial.print("ac6 = "); + Serial.println(ac6, DEC); + + Serial.print("b1 = "); + Serial.println(b1, DEC); + Serial.print("b2 = "); + Serial.println(b2, DEC); + + Serial.print("mb = "); + Serial.println(mb, DEC); + Serial.print("mc = "); + Serial.println(mc, DEC); + Serial.print("md = "); + Serial.println(md, DEC); #endif return true; @@ -65,7 +87,7 @@ boolean Adafruit_BMP085::begin(uint8_t mode) { int32_t Adafruit_BMP085::computeB5(int32_t UT) { int32_t X1 = (UT - (int32_t)ac6) * ((int32_t)ac5) >> 15; - int32_t X2 = ((int32_t)mc << 11) / (X1+(int32_t)md); + int32_t X2 = ((int32_t)mc << 11) / (X1 + (int32_t)md); return X1 + X2; } @@ -73,7 +95,8 @@ uint16_t Adafruit_BMP085::readRawTemperature(void) { write8(BMP085_CONTROL, BMP085_READTEMPCMD); delay(5); #if BMP085_DEBUG == 1 - Serial.print("Raw temp: "); Serial.println(read16(BMP085_TEMPDATA)); + Serial.print("Raw temp: "); + Serial.println(read16(BMP085_TEMPDATA)); #endif return read16(BMP085_TEMPDATA); } @@ -83,36 +106,36 @@ uint32_t Adafruit_BMP085::readRawPressure(void) { write8(BMP085_CONTROL, BMP085_READPRESSURECMD + (oversampling << 6)); - if (oversampling == BMP085_ULTRALOWPOWER) + if (oversampling == BMP085_ULTRALOWPOWER) delay(5); - else if (oversampling == BMP085_STANDARD) + else if (oversampling == BMP085_STANDARD) delay(8); - else if (oversampling == BMP085_HIGHRES) + else if (oversampling == BMP085_HIGHRES) delay(14); - else + else delay(26); raw = read16(BMP085_PRESSUREDATA); raw <<= 8; - raw |= read8(BMP085_PRESSUREDATA+2); + raw |= read8(BMP085_PRESSUREDATA + 2); raw >>= (8 - oversampling); - /* this pull broke stuff, look at it later? - if (oversampling==0) { - raw <<= 8; - raw |= read8(BMP085_PRESSUREDATA+2); - raw >>= (8 - oversampling); - } - */ + /* this pull broke stuff, look at it later? + if (oversampling==0) { + raw <<= 8; + raw |= read8(BMP085_PRESSUREDATA+2); + raw >>= (8 - oversampling); + } + */ #if BMP085_DEBUG == 1 - Serial.print("Raw pressure: "); Serial.println(raw); + Serial.print("Raw pressure: "); + Serial.println(raw); #endif return raw; } - int32_t Adafruit_BMP085::readPressure(void) { int32_t UT, UP, B3, B5, B6, X1, X2, X3, p; uint32_t B4, B7; @@ -140,36 +163,47 @@ int32_t Adafruit_BMP085::readPressure(void) { B5 = computeB5(UT); #if BMP085_DEBUG == 1 - Serial.print("X1 = "); Serial.println(X1); - Serial.print("X2 = "); Serial.println(X2); - Serial.print("B5 = "); Serial.println(B5); + Serial.print("X1 = "); + Serial.println(X1); + Serial.print("X2 = "); + Serial.println(X2); + Serial.print("B5 = "); + Serial.println(B5); #endif // do pressure calcs B6 = B5 - 4000; - X1 = ((int32_t)b2 * ( (B6 * B6)>>12 )) >> 11; + X1 = ((int32_t)b2 * ((B6 * B6) >> 12)) >> 11; X2 = ((int32_t)ac2 * B6) >> 11; X3 = X1 + X2; - B3 = ((((int32_t)ac1*4 + X3) << oversampling) + 2) / 4; + B3 = ((((int32_t)ac1 * 4 + X3) << oversampling) + 2) / 4; #if BMP085_DEBUG == 1 - Serial.print("B6 = "); Serial.println(B6); - Serial.print("X1 = "); Serial.println(X1); - Serial.print("X2 = "); Serial.println(X2); - Serial.print("B3 = "); Serial.println(B3); + Serial.print("B6 = "); + Serial.println(B6); + Serial.print("X1 = "); + Serial.println(X1); + Serial.print("X2 = "); + Serial.println(X2); + Serial.print("B3 = "); + Serial.println(B3); #endif X1 = ((int32_t)ac3 * B6) >> 13; X2 = ((int32_t)b1 * ((B6 * B6) >> 12)) >> 16; X3 = ((X1 + X2) + 2) >> 2; B4 = ((uint32_t)ac4 * (uint32_t)(X3 + 32768)) >> 15; - B7 = ((uint32_t)UP - B3) * (uint32_t)( 50000UL >> oversampling ); + B7 = ((uint32_t)UP - B3) * (uint32_t)(50000UL >> oversampling); #if BMP085_DEBUG == 1 - Serial.print("X1 = "); Serial.println(X1); - Serial.print("X2 = "); Serial.println(X2); - Serial.print("B4 = "); Serial.println(B4); - Serial.print("B7 = "); Serial.println(B7); + Serial.print("X1 = "); + Serial.println(X1); + Serial.print("X2 = "); + Serial.println(X2); + Serial.print("B4 = "); + Serial.println(B4); + Serial.print("B7 = "); + Serial.println(B7); #endif if (B7 < 0x80000000) { @@ -182,25 +216,29 @@ int32_t Adafruit_BMP085::readPressure(void) { X2 = (-7357 * p) >> 16; #if BMP085_DEBUG == 1 - Serial.print("p = "); Serial.println(p); - Serial.print("X1 = "); Serial.println(X1); - Serial.print("X2 = "); Serial.println(X2); + Serial.print("p = "); + Serial.println(p); + Serial.print("X1 = "); + Serial.println(X1); + Serial.print("X2 = "); + Serial.println(X2); #endif - p = p + ((X1 + X2 + (int32_t)3791)>>4); + p = p + ((X1 + X2 + (int32_t)3791) >> 4); #if BMP085_DEBUG == 1 - Serial.print("p = "); Serial.println(p); + Serial.print("p = "); + Serial.println(p); #endif return p; } int32_t Adafruit_BMP085::readSealevelPressure(float altitude_meters) { float pressure = readPressure(); - return (int32_t)(pressure / pow(1.0-altitude_meters/44330, 5.255)); + return (int32_t)(pressure / pow(1.0 - altitude_meters / 44330, 5.255)); } float Adafruit_BMP085::readTemperature(void) { - int32_t UT, B5; // following ds convention + int32_t UT, B5; // following ds convention float temp; UT = readRawTemperature(); @@ -215,9 +253,9 @@ float Adafruit_BMP085::readTemperature(void) { #endif B5 = computeB5(UT); - temp = (B5+8) >> 4; + temp = (B5 + 8) >> 4; temp /= 10; - + return temp; } @@ -226,27 +264,26 @@ float Adafruit_BMP085::readAltitude(float sealevelPressure) { float pressure = readPressure(); - altitude = 44330 * (1.0 - pow(pressure /sealevelPressure,0.1903)); + altitude = 44330 * (1.0 - pow(pressure / sealevelPressure, 0.1903)); return altitude; } - /*********************************************************************/ uint8_t Adafruit_BMP085::read8(uint8_t a) { uint8_t ret; - Wire.beginTransmission(BMP085_I2CADDR); // start transmission to device + Wire.beginTransmission(BMP085_I2CADDR); // start transmission to device #if (ARDUINO >= 100) Wire.write(a); // sends register address to read from #else - Wire.send(a); // sends register address to read from + Wire.send(a); // sends register address to read from #endif Wire.endTransmission(); // end transmission - - Wire.beginTransmission(BMP085_I2CADDR); // start transmission to device - Wire.requestFrom(BMP085_I2CADDR, 1);// send data n-bytes read + + Wire.beginTransmission(BMP085_I2CADDR); // start transmission to device + Wire.requestFrom(BMP085_I2CADDR, 1); // send data n-bytes read #if (ARDUINO >= 100) ret = Wire.read(); // receive DATA #else @@ -260,16 +297,16 @@ uint8_t Adafruit_BMP085::read8(uint8_t a) { uint16_t Adafruit_BMP085::read16(uint8_t a) { uint16_t ret; - Wire.beginTransmission(BMP085_I2CADDR); // start transmission to device + Wire.beginTransmission(BMP085_I2CADDR); // start transmission to device #if (ARDUINO >= 100) Wire.write(a); // sends register address to read from #else - Wire.send(a); // sends register address to read from + Wire.send(a); // sends register address to read from #endif Wire.endTransmission(); // end transmission - - Wire.beginTransmission(BMP085_I2CADDR); // start transmission to device - Wire.requestFrom(BMP085_I2CADDR, 2);// send data n-bytes read + + Wire.beginTransmission(BMP085_I2CADDR); // start transmission to device + Wire.requestFrom(BMP085_I2CADDR, 2); // send data n-bytes read #if (ARDUINO >= 100) ret = Wire.read(); // receive DATA ret <<= 8; @@ -285,13 +322,13 @@ uint16_t Adafruit_BMP085::read16(uint8_t a) { } void Adafruit_BMP085::write8(uint8_t a, uint8_t d) { - Wire.beginTransmission(BMP085_I2CADDR); // start transmission to device + Wire.beginTransmission(BMP085_I2CADDR); // start transmission to device #if (ARDUINO >= 100) Wire.write(a); // sends register address to read from - Wire.write(d); // write data + Wire.write(d); // write data #else - Wire.send(a); // sends register address to read from - Wire.send(d); // write data + Wire.send(a); // sends register address to read from + Wire.send(d); // write data #endif Wire.endTransmission(); // end transmission } diff --git a/Adafruit_BMP085.h b/Adafruit_BMP085.h index d91b7b1..56d7053 100644 --- a/Adafruit_BMP085.h +++ b/Adafruit_BMP085.h @@ -1,69 +1,105 @@ -/*************************************************** - This is a library for the Adafruit BMP085/BMP180 Barometric Pressure + Temp sensor - - Designed specifically to work with the Adafruit BMP085 or BMP180 Breakout - ----> http://www.adafruit.com/products/391 - ----> http://www.adafruit.com/products/1603 - - These displays use I2C to communicate, 2 pins are required to - interface - Adafruit invests time and resources providing this open source code, - please support Adafruit and open-source hardware by purchasing - products from Adafruit! - - Written by Limor Fried/Ladyada for Adafruit Industries. - BSD license, all text above must be included in any redistribution - ****************************************************/ +/*! + * @file Adafruit_BMP085.h + * + * This is a library for the Adafruit BMP085/BMP180 Barometric Pressure + Temp + * sensor + * + * Designed specifically to work with the Adafruit BMP085 or BMP180 Breakout + * ----> http://www.adafruit.com/products/391 + * ----> http://www.adafruit.com/products/1603 + * + * These displays use I2C to communicate, 2 pins are required to + * interface + * Adafruit invests time and resources providing this open source code, + * please support Adafruit and open-source hardware by purchasing + * products from Adafruit! + * + * Written by Limor Fried/Ladyada for Adafruit Industries. + * BSD license, all text above must be included in any redistribution + */ #ifndef ADAFRUIT_BMP085_H #define ADAFRUIT_BMP085_H #if (ARDUINO >= 100) - #include "Arduino.h" +#include "Arduino.h" #else - #include "WProgram.h" +#include "WProgram.h" #endif #include "Wire.h" -#define BMP085_DEBUG 0 +#define BMP085_DEBUG 0 //!< Debug mode -#define BMP085_I2CADDR 0x77 +#define BMP085_I2CADDR 0x77 //!< BMP085 I2C address -#define BMP085_ULTRALOWPOWER 0 -#define BMP085_STANDARD 1 -#define BMP085_HIGHRES 2 -#define BMP085_ULTRAHIGHRES 3 -#define BMP085_CAL_AC1 0xAA // R Calibration data (16 bits) -#define BMP085_CAL_AC2 0xAC // R Calibration data (16 bits) -#define BMP085_CAL_AC3 0xAE // R Calibration data (16 bits) -#define BMP085_CAL_AC4 0xB0 // R Calibration data (16 bits) -#define BMP085_CAL_AC5 0xB2 // R Calibration data (16 bits) -#define BMP085_CAL_AC6 0xB4 // R Calibration data (16 bits) -#define BMP085_CAL_B1 0xB6 // R Calibration data (16 bits) -#define BMP085_CAL_B2 0xB8 // R Calibration data (16 bits) -#define BMP085_CAL_MB 0xBA // R Calibration data (16 bits) -#define BMP085_CAL_MC 0xBC // R Calibration data (16 bits) -#define BMP085_CAL_MD 0xBE // R Calibration data (16 bits) - -#define BMP085_CONTROL 0xF4 -#define BMP085_TEMPDATA 0xF6 -#define BMP085_PRESSUREDATA 0xF6 -#define BMP085_READTEMPCMD 0x2E -#define BMP085_READPRESSURECMD 0x34 +#define BMP085_ULTRALOWPOWER 0 //!< Ultra low power mode +#define BMP085_STANDARD 1 //!< Standard mode +#define BMP085_HIGHRES 2 //!< High-res mode +#define BMP085_ULTRAHIGHRES 3 //!< Ultra high-res mode +#define BMP085_CAL_AC1 0xAA //!< R Calibration data (16 bits) +#define BMP085_CAL_AC2 0xAC //!< R Calibration data (16 bits) +#define BMP085_CAL_AC3 0xAE //!< R Calibration data (16 bits) +#define BMP085_CAL_AC4 0xB0 //!< R Calibration data (16 bits) +#define BMP085_CAL_AC5 0xB2 //!< R Calibration data (16 bits) +#define BMP085_CAL_AC6 0xB4 //!< R Calibration data (16 bits) +#define BMP085_CAL_B1 0xB6 //!< R Calibration data (16 bits) +#define BMP085_CAL_B2 0xB8 //!< R Calibration data (16 bits) +#define BMP085_CAL_MB 0xBA //!< R Calibration data (16 bits) +#define BMP085_CAL_MC 0xBC //!< R Calibration data (16 bits) +#define BMP085_CAL_MD 0xBE //!< R Calibration data (16 bits) +#define BMP085_CONTROL 0xF4 //!< Control register +#define BMP085_TEMPDATA 0xF6 //!< Temperature data register +#define BMP085_PRESSUREDATA 0xF6 //!< Pressure data register +#define BMP085_READTEMPCMD 0x2E //!< Read temperature control register value +#define BMP085_READPRESSURECMD 0x34 //!< Read pressure control register value +/*! + * @brief Main BMP085 class + */ class Adafruit_BMP085 { - public: +public: Adafruit_BMP085(); - boolean begin(uint8_t mode = BMP085_ULTRAHIGHRES); // by default go highres + /*! + * @brief Starts I2C connection + * @param mode Mode to set, ultra high-res by default + * @return Returns true if successful + */ + boolean begin(uint8_t mode = BMP085_ULTRAHIGHRES); + /*! + * @brief Gets the temperature over I2C from the BMP085 + * @return Returns the temperature + */ float readTemperature(void); + /*! + * @brief Gets the pressure over I2C from the BMP085 + * @return Returns the pressure + */ int32_t readPressure(void); + /*! + * @brief Calculates the pressure at sea level + * @param altitude_meters Current altitude (in meters) + * @return Returns the calculated pressure at sea level + */ int32_t readSealevelPressure(float altitude_meters = 0); + /*! + * @brief Reads the altitude + * @param sealevelPressure Pressure at sea level, measured in pascals + * @return Returns the altitude + */ float readAltitude(float sealevelPressure = 101325); // std atmosphere + /*! + * @brief Reads the raw temperature + * @return Returns signed 16-bit integer of the raw temperature + */ uint16_t readRawTemperature(void); + /*! + * @brief Reads the raw pressure + * @return Returns signed 32-bit integer of the raw temperature + */ uint32_t readRawPressure(void); - - private: + +private: int32_t computeB5(int32_t UT); uint8_t read8(uint8_t addr); uint16_t read16(uint8_t addr); @@ -75,5 +111,4 @@ class Adafruit_BMP085 { uint16_t ac4, ac5, ac6; }; - #endif // ADAFRUIT_BMP085_H diff --git a/README.txt b/README.md similarity index 77% rename from README.txt rename to README.md index 0a465b7..6912b2f 100644 --- a/README.txt +++ b/README.md @@ -1,3 +1,5 @@ +# Adafruit BMP085 Library [![Build Status](https://github.com/adafruit/Adafruit-BMP085-Library/workflows/Arduino%20Library%20CI/badge.svg)](https://github.com/adafruit/Adafruit-BMP085-Library/actions)[![Documentation](https://github.com/adafruit/ci-arduino/blob/master/assets/doxygen_badge.svg)](http://adafruit.github.io/Adafruit-BMP085-Library/html/index.html) + This is a library for the Adafruit BMP085/BMP180 Barometric Pressure + Temp sensor Designed specifically to work with the Adafruit BMP085 or BMP180 Breakout @@ -25,4 +27,4 @@ Place the Adafruit_BMP085 library folder your arduinosketchfolder/libraries/ fol You may need to create the libraries subfolder if its your first library. Restart the IDE. We also have a great tutorial on Arduino library installation at: -http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use \ No newline at end of file +http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use diff --git a/library.properties b/library.properties index 84e68fc..3b5285e 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Adafruit BMP085 Library -version=1.0.1 +version=1.1.0 author=Adafruit maintainer=Adafruit sentence=A powerful but easy to use BMP085/BMP180 Library