Skip to content

Commit

Permalink
Moved library to actions, fully documented with doxygen
Browse files Browse the repository at this point in the history
  • Loading branch information
dherrada committed Jun 1, 2020
1 parent 7b69aed commit ac5f294
Show file tree
Hide file tree
Showing 5 changed files with 243 additions and 137 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/githubci.yml
Original file line number Diff line number Diff line change
@@ -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
215 changes: 126 additions & 89 deletions Adafruit_BMP085.cpp
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -45,35 +56,47 @@ 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;
}

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;
}

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);
}
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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();
Expand All @@ -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;
}

Expand All @@ -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
Expand All @@ -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;
Expand All @@ -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
}
Loading

0 comments on commit ac5f294

Please sign in to comment.