Skip to content

Commit

Permalink
Merge pull request #72 from adafruit/actions
Browse files Browse the repository at this point in the history
Actions
  • Loading branch information
ladyada authored Dec 29, 2019
2 parents 7fa7054 + ed29ee6 commit 95f050b
Show file tree
Hide file tree
Showing 8 changed files with 323 additions and 52 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]

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 BME280 Library"
run: bash ci/doxy_gen_and_deploy.sh
26 changes: 0 additions & 26 deletions .travis.yml

This file was deleted.

169 changes: 168 additions & 1 deletion Adafruit_BME280.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ Adafruit_BME280::Adafruit_BME280(int8_t cspin, int8_t mosipin, int8_t misopin,
int8_t sckpin)
: _cs(cspin), _mosi(mosipin), _miso(misopin), _sck(sckpin) {}

Adafruit_BME280::~Adafruit_BME280(void) {
if (temp_sensor) {
delete temp_sensor;
}
if (pressure_sensor) {
delete pressure_sensor;
}
if (humidity_sensor) {
delete humidity_sensor;
}
}

/*!
* @brief Initialise sensor with given parameters / settings
* @param addr the I2C address the device can be found on
Expand Down Expand Up @@ -153,7 +165,6 @@ void Adafruit_BME280::setSampling(sensor_mode mode,
// making sure sensor is in sleep mode before setting configuration
// as it otherwise may be ignored
write8(BME280_REGISTER_CONTROL, MODE_SLEEP);


// you must make sure to also set REGISTER_CONTROL after setting the
// CONTROLHUMID register, otherwise the values won't be applied (see
Expand Down Expand Up @@ -528,3 +539,159 @@ float Adafruit_BME280::seaLevelForAltitude(float altitude, float atmospheric) {
* @returns Sensor ID 0x60 for BME280, 0x56, 0x57, 0x58 BMP280
*/
uint32_t Adafruit_BME280::sensorID(void) { return _sensorID; }

/*!
@brief Gets an Adafruit Unified Sensor object for the temp sensor component
@return Adafruit_Sensor pointer to temperature sensor
*/
Adafruit_Sensor *Adafruit_BME280::getTemperatureSensor(void) {
if (!temp_sensor) {
temp_sensor = new Adafruit_BME280_Temp(this);
}

return temp_sensor;
}

/*!
@brief Gets an Adafruit Unified Sensor object for the pressure sensor
component
@return Adafruit_Sensor pointer to pressure sensor
*/
Adafruit_Sensor *Adafruit_BME280::getPressureSensor(void) {
if (!pressure_sensor) {
pressure_sensor = new Adafruit_BME280_Pressure(this);
}
return pressure_sensor;
}

/*!
@brief Gets an Adafruit Unified Sensor object for the humidity sensor
component
@return Adafruit_Sensor pointer to humidity sensor
*/
Adafruit_Sensor *Adafruit_BME280::getHumiditySensor(void) {
if (!humidity_sensor) {
humidity_sensor = new Adafruit_BME280_Humidity(this);
}
return humidity_sensor;
}

/**************************************************************************/
/*!
@brief Gets the sensor_t data for the BME280's temperature sensor
*/
/**************************************************************************/
void Adafruit_BME280_Temp::getSensor(sensor_t *sensor) {
/* Clear the sensor_t object */
memset(sensor, 0, sizeof(sensor_t));

/* Insert the sensor name in the fixed length char array */
strncpy(sensor->name, "BME280", sizeof(sensor->name) - 1);
sensor->name[sizeof(sensor->name) - 1] = 0;
sensor->version = 1;
sensor->sensor_id = _sensorID;
sensor->type = SENSOR_TYPE_AMBIENT_TEMPERATURE;
sensor->min_delay = 0;
sensor->min_value = -40.0; /* Temperature range -40 ~ +85 C */
sensor->max_value = +85.0;
sensor->resolution = 0.01; /* 0.01 C */
}

/**************************************************************************/
/*!
@brief Gets the temperature as a standard sensor event
@param event Sensor event object that will be populated
@returns True
*/
/**************************************************************************/
bool Adafruit_BME280_Temp::getEvent(sensors_event_t *event) {
/* Clear the event */
memset(event, 0, sizeof(sensors_event_t));

event->version = sizeof(sensors_event_t);
event->sensor_id = _sensorID;
event->type = SENSOR_TYPE_AMBIENT_TEMPERATURE;
event->timestamp = millis();
event->temperature = _theBME280->readTemperature();
return true;
}

/**************************************************************************/
/*!
@brief Gets the sensor_t data for the BME280's pressure sensor
*/
/**************************************************************************/
void Adafruit_BME280_Pressure::getSensor(sensor_t *sensor) {
/* Clear the sensor_t object */
memset(sensor, 0, sizeof(sensor_t));

/* Insert the sensor name in the fixed length char array */
strncpy(sensor->name, "BME280", sizeof(sensor->name) - 1);
sensor->name[sizeof(sensor->name) - 1] = 0;
sensor->version = 1;
sensor->sensor_id = _sensorID;
sensor->type = SENSOR_TYPE_PRESSURE;
sensor->min_delay = 0;
sensor->min_value = 300.0; /* 300 ~ 1100 hPa */
sensor->max_value = 1100.0;
sensor->resolution = 0.012; /* 0.12 hPa relative */
}

/**************************************************************************/
/*!
@brief Gets the pressure as a standard sensor event
@param event Sensor event object that will be populated
@returns True
*/
/**************************************************************************/
bool Adafruit_BME280_Pressure::getEvent(sensors_event_t *event) {
/* Clear the event */
memset(event, 0, sizeof(sensors_event_t));

event->version = sizeof(sensors_event_t);
event->sensor_id = _sensorID;
event->type = SENSOR_TYPE_PRESSURE;
event->timestamp = millis();
event->pressure = _theBME280->readPressure() / 100; // convert Pa to hPa
return true;
}

/**************************************************************************/
/*!
@brief Gets the sensor_t data for the BME280's humidity sensor
*/
/**************************************************************************/
void Adafruit_BME280_Humidity::getSensor(sensor_t *sensor) {
/* Clear the sensor_t object */
memset(sensor, 0, sizeof(sensor_t));

/* Insert the sensor name in the fixed length char array */
strncpy(sensor->name, "BME280", sizeof(sensor->name) - 1);
sensor->name[sizeof(sensor->name) - 1] = 0;
sensor->version = 1;
sensor->sensor_id = _sensorID;
sensor->type = SENSOR_TYPE_RELATIVE_HUMIDITY;
sensor->min_delay = 0;
sensor->min_value = 0;
sensor->max_value = 100; /* 0 - 100 % */
sensor->resolution = 3; /* 3% accuracy */
}

/**************************************************************************/
/*!
@brief Gets the humidity as a standard sensor event
@param event Sensor event object that will be populated
@returns True
*/
/**************************************************************************/
bool Adafruit_BME280_Humidity::getEvent(sensors_event_t *event) {
/* Clear the event */
memset(event, 0, sizeof(sensors_event_t));

event->version = sizeof(sensors_event_t);
event->sensor_id = _sensorID;
event->type = SENSOR_TYPE_RELATIVE_HUMIDITY;
event->timestamp = millis();
event->relative_humidity = _theBME280->readHumidity();
return true;
}
80 changes: 58 additions & 22 deletions Adafruit_BME280.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,26 +105,49 @@ typedef struct {
} bme280_calib_data;
/*=========================================================================*/

/*
class Adafruit_BME280_Unified : public Adafruit_Sensor
{
public:
Adafruit_BME280_Unified(int32_t sensorID = -1);
bool begin(uint8_t addr = BME280_ADDRESS);
void getTemperature(float *temp);
void getPressure(float *pressure);
float pressureToAltitude(float seaLevel, float atmospheric, float temp);
float seaLevelForAltitude(float altitude, float atmospheric, float temp);
void getEvent(sensors_event_t*);
void getSensor(sensor_t*);
private:
uint8_t _i2c_addr;
int32_t _sensorID;
class Adafruit_BME280;

/** Adafruit Unified Sensor interface for temperature component of BME280 */
class Adafruit_BME280_Temp : public Adafruit_Sensor {
public:
/** @brief Create an Adafruit_Sensor compatible object for the temp sensor
@param parent A pointer to the BME280 class */
Adafruit_BME280_Temp(Adafruit_BME280 *parent) { _theBME280 = parent; }
bool getEvent(sensors_event_t *);
void getSensor(sensor_t *);

private:
int _sensorID = 280;
Adafruit_BME280 *_theBME280 = NULL;
};

*/
/** Adafruit Unified Sensor interface for pressure component of BME280 */
class Adafruit_BME280_Pressure : public Adafruit_Sensor {
public:
/** @brief Create an Adafruit_Sensor compatible object for the pressure sensor
@param parent A pointer to the BME280 class */
Adafruit_BME280_Pressure(Adafruit_BME280 *parent) { _theBME280 = parent; }
bool getEvent(sensors_event_t *);
void getSensor(sensor_t *);

private:
int _sensorID = 280;
Adafruit_BME280 *_theBME280 = NULL;
};

/** Adafruit Unified Sensor interface for humidity component of BME280 */
class Adafruit_BME280_Humidity : public Adafruit_Sensor {
public:
/** @brief Create an Adafruit_Sensor compatible object for the humidity sensor
@param parent A pointer to the BME280 class */
Adafruit_BME280_Humidity(Adafruit_BME280 *parent) { _theBME280 = parent; }
bool getEvent(sensors_event_t *);
void getSensor(sensor_t *);

private:
int _sensorID = 280;
Adafruit_BME280 *_theBME280 = NULL;
};

/**************************************************************************/
/*!
Expand Down Expand Up @@ -190,10 +213,9 @@ class Adafruit_BME280 {
// constructors
Adafruit_BME280();
Adafruit_BME280(int8_t cspin, SPIClass *theSPI = &SPI);
Adafruit_BME280(int8_t cspin, int8_t mosipin, int8_t misopin,
int8_t sckpin);

bool begin(uint8_t addr=BME280_ADDRESS, TwoWire *theWire=&Wire);
Adafruit_BME280(int8_t cspin, int8_t mosipin, int8_t misopin, int8_t sckpin);
~Adafruit_BME280(void);
bool begin(uint8_t addr = BME280_ADDRESS, TwoWire *theWire = &Wire);
bool init();

void setSampling(sensor_mode mode = MODE_NORMAL,
Expand All @@ -212,9 +234,23 @@ class Adafruit_BME280 {
float seaLevelForAltitude(float altitude, float pressure);
uint32_t sensorID(void);

Adafruit_Sensor *getTemperatureSensor(void);
Adafruit_Sensor *getPressureSensor(void);
Adafruit_Sensor *getHumiditySensor(void);

protected:
TwoWire *_wire; //!< pointer to a TwoWire object
SPIClass *_spi; //!< pointer to SPI object

Adafruit_BME280_Temp *temp_sensor = NULL;
//!< Adafruit_Sensor compat temperature sensor component

Adafruit_BME280_Pressure *pressure_sensor = NULL;
//!< Adafruit_Sensor compat pressure sensor component

Adafruit_BME280_Humidity *humidity_sensor = NULL;
//!< Adafruit_Sensor compat humidity sensor component

void readCoefficients(void);
bool isReadingCalibration(void);
uint8_t spixfer(uint8_t x);
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Adafruit BME280 Library [![Build Status](https://travis-ci.com/adafruit/Adafruit_BME280_Library.svg?branch=master)](https://travis-ci.com/adafruit/Adafruit_BME280_Library)
# Adafruit BME280 Library ![Build Status](https://github.com/adafruit/Adafruit_BME280_Library/workflows/Arduino%20Library%20CI/badge.svg)

<a href="http://www.adafruit.com/products/2652"><img src="./assets/board.jpg" width="500"/></a>

Expand Down
2 changes: 1 addition & 1 deletion examples/advancedsettings/advancedsettings.ino
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void setup() {
Serial.begin(9600);
Serial.println(F("BME280 test"));

if (! bme.begin(&Wire)) {
if (! bme.begin(0x77, &Wire)) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}
Expand Down
Loading

0 comments on commit 95f050b

Please sign in to comment.