Skip to content

Commit 95f050b

Browse files
authored
Merge pull request #72 from adafruit/actions
Actions
2 parents 7fa7054 + ed29ee6 commit 95f050b

File tree

8 files changed

+323
-52
lines changed

8 files changed

+323
-52
lines changed

.github/workflows/githubci.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Arduino Library CI
2+
3+
on: [pull_request, push]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- uses: actions/setup-python@v1
11+
with:
12+
python-version: '3.x'
13+
- uses: actions/checkout@v2
14+
- uses: actions/checkout@v2
15+
with:
16+
repository: adafruit/ci-arduino
17+
path: ci
18+
19+
- name: pre-install
20+
run: bash ci/actions_install.sh
21+
22+
- name: test platforms
23+
run: python3 ci/build_platform.py main_platforms
24+
25+
- name: clang
26+
run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r .
27+
28+
- name: doxygen
29+
env:
30+
GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }}
31+
PRETTYNAME : "Adafruit BME280 Library"
32+
run: bash ci/doxy_gen_and_deploy.sh

.travis.yml

Lines changed: 0 additions & 26 deletions
This file was deleted.

Adafruit_BME280.cpp

Lines changed: 168 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@ Adafruit_BME280::Adafruit_BME280(int8_t cspin, int8_t mosipin, int8_t misopin,
6161
int8_t sckpin)
6262
: _cs(cspin), _mosi(mosipin), _miso(misopin), _sck(sckpin) {}
6363

64+
Adafruit_BME280::~Adafruit_BME280(void) {
65+
if (temp_sensor) {
66+
delete temp_sensor;
67+
}
68+
if (pressure_sensor) {
69+
delete pressure_sensor;
70+
}
71+
if (humidity_sensor) {
72+
delete humidity_sensor;
73+
}
74+
}
75+
6476
/*!
6577
* @brief Initialise sensor with given parameters / settings
6678
* @param addr the I2C address the device can be found on
@@ -153,7 +165,6 @@ void Adafruit_BME280::setSampling(sensor_mode mode,
153165
// making sure sensor is in sleep mode before setting configuration
154166
// as it otherwise may be ignored
155167
write8(BME280_REGISTER_CONTROL, MODE_SLEEP);
156-
157168

158169
// you must make sure to also set REGISTER_CONTROL after setting the
159170
// CONTROLHUMID register, otherwise the values won't be applied (see
@@ -528,3 +539,159 @@ float Adafruit_BME280::seaLevelForAltitude(float altitude, float atmospheric) {
528539
* @returns Sensor ID 0x60 for BME280, 0x56, 0x57, 0x58 BMP280
529540
*/
530541
uint32_t Adafruit_BME280::sensorID(void) { return _sensorID; }
542+
543+
/*!
544+
@brief Gets an Adafruit Unified Sensor object for the temp sensor component
545+
@return Adafruit_Sensor pointer to temperature sensor
546+
*/
547+
Adafruit_Sensor *Adafruit_BME280::getTemperatureSensor(void) {
548+
if (!temp_sensor) {
549+
temp_sensor = new Adafruit_BME280_Temp(this);
550+
}
551+
552+
return temp_sensor;
553+
}
554+
555+
/*!
556+
@brief Gets an Adafruit Unified Sensor object for the pressure sensor
557+
component
558+
@return Adafruit_Sensor pointer to pressure sensor
559+
*/
560+
Adafruit_Sensor *Adafruit_BME280::getPressureSensor(void) {
561+
if (!pressure_sensor) {
562+
pressure_sensor = new Adafruit_BME280_Pressure(this);
563+
}
564+
return pressure_sensor;
565+
}
566+
567+
/*!
568+
@brief Gets an Adafruit Unified Sensor object for the humidity sensor
569+
component
570+
@return Adafruit_Sensor pointer to humidity sensor
571+
*/
572+
Adafruit_Sensor *Adafruit_BME280::getHumiditySensor(void) {
573+
if (!humidity_sensor) {
574+
humidity_sensor = new Adafruit_BME280_Humidity(this);
575+
}
576+
return humidity_sensor;
577+
}
578+
579+
/**************************************************************************/
580+
/*!
581+
@brief Gets the sensor_t data for the BME280's temperature sensor
582+
*/
583+
/**************************************************************************/
584+
void Adafruit_BME280_Temp::getSensor(sensor_t *sensor) {
585+
/* Clear the sensor_t object */
586+
memset(sensor, 0, sizeof(sensor_t));
587+
588+
/* Insert the sensor name in the fixed length char array */
589+
strncpy(sensor->name, "BME280", sizeof(sensor->name) - 1);
590+
sensor->name[sizeof(sensor->name) - 1] = 0;
591+
sensor->version = 1;
592+
sensor->sensor_id = _sensorID;
593+
sensor->type = SENSOR_TYPE_AMBIENT_TEMPERATURE;
594+
sensor->min_delay = 0;
595+
sensor->min_value = -40.0; /* Temperature range -40 ~ +85 C */
596+
sensor->max_value = +85.0;
597+
sensor->resolution = 0.01; /* 0.01 C */
598+
}
599+
600+
/**************************************************************************/
601+
/*!
602+
@brief Gets the temperature as a standard sensor event
603+
@param event Sensor event object that will be populated
604+
@returns True
605+
*/
606+
/**************************************************************************/
607+
bool Adafruit_BME280_Temp::getEvent(sensors_event_t *event) {
608+
/* Clear the event */
609+
memset(event, 0, sizeof(sensors_event_t));
610+
611+
event->version = sizeof(sensors_event_t);
612+
event->sensor_id = _sensorID;
613+
event->type = SENSOR_TYPE_AMBIENT_TEMPERATURE;
614+
event->timestamp = millis();
615+
event->temperature = _theBME280->readTemperature();
616+
return true;
617+
}
618+
619+
/**************************************************************************/
620+
/*!
621+
@brief Gets the sensor_t data for the BME280's pressure sensor
622+
*/
623+
/**************************************************************************/
624+
void Adafruit_BME280_Pressure::getSensor(sensor_t *sensor) {
625+
/* Clear the sensor_t object */
626+
memset(sensor, 0, sizeof(sensor_t));
627+
628+
/* Insert the sensor name in the fixed length char array */
629+
strncpy(sensor->name, "BME280", sizeof(sensor->name) - 1);
630+
sensor->name[sizeof(sensor->name) - 1] = 0;
631+
sensor->version = 1;
632+
sensor->sensor_id = _sensorID;
633+
sensor->type = SENSOR_TYPE_PRESSURE;
634+
sensor->min_delay = 0;
635+
sensor->min_value = 300.0; /* 300 ~ 1100 hPa */
636+
sensor->max_value = 1100.0;
637+
sensor->resolution = 0.012; /* 0.12 hPa relative */
638+
}
639+
640+
/**************************************************************************/
641+
/*!
642+
@brief Gets the pressure as a standard sensor event
643+
@param event Sensor event object that will be populated
644+
@returns True
645+
*/
646+
/**************************************************************************/
647+
bool Adafruit_BME280_Pressure::getEvent(sensors_event_t *event) {
648+
/* Clear the event */
649+
memset(event, 0, sizeof(sensors_event_t));
650+
651+
event->version = sizeof(sensors_event_t);
652+
event->sensor_id = _sensorID;
653+
event->type = SENSOR_TYPE_PRESSURE;
654+
event->timestamp = millis();
655+
event->pressure = _theBME280->readPressure() / 100; // convert Pa to hPa
656+
return true;
657+
}
658+
659+
/**************************************************************************/
660+
/*!
661+
@brief Gets the sensor_t data for the BME280's humidity sensor
662+
*/
663+
/**************************************************************************/
664+
void Adafruit_BME280_Humidity::getSensor(sensor_t *sensor) {
665+
/* Clear the sensor_t object */
666+
memset(sensor, 0, sizeof(sensor_t));
667+
668+
/* Insert the sensor name in the fixed length char array */
669+
strncpy(sensor->name, "BME280", sizeof(sensor->name) - 1);
670+
sensor->name[sizeof(sensor->name) - 1] = 0;
671+
sensor->version = 1;
672+
sensor->sensor_id = _sensorID;
673+
sensor->type = SENSOR_TYPE_RELATIVE_HUMIDITY;
674+
sensor->min_delay = 0;
675+
sensor->min_value = 0;
676+
sensor->max_value = 100; /* 0 - 100 % */
677+
sensor->resolution = 3; /* 3% accuracy */
678+
}
679+
680+
/**************************************************************************/
681+
/*!
682+
@brief Gets the humidity as a standard sensor event
683+
@param event Sensor event object that will be populated
684+
@returns True
685+
*/
686+
/**************************************************************************/
687+
bool Adafruit_BME280_Humidity::getEvent(sensors_event_t *event) {
688+
/* Clear the event */
689+
memset(event, 0, sizeof(sensors_event_t));
690+
691+
event->version = sizeof(sensors_event_t);
692+
event->sensor_id = _sensorID;
693+
event->type = SENSOR_TYPE_RELATIVE_HUMIDITY;
694+
event->timestamp = millis();
695+
event->relative_humidity = _theBME280->readHumidity();
696+
return true;
697+
}

Adafruit_BME280.h

Lines changed: 58 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -105,26 +105,49 @@ typedef struct {
105105
} bme280_calib_data;
106106
/*=========================================================================*/
107107

108-
/*
109-
class Adafruit_BME280_Unified : public Adafruit_Sensor
110-
{
111-
public:
112-
Adafruit_BME280_Unified(int32_t sensorID = -1);
113-
114-
bool begin(uint8_t addr = BME280_ADDRESS);
115-
void getTemperature(float *temp);
116-
void getPressure(float *pressure);
117-
float pressureToAltitude(float seaLevel, float atmospheric, float temp);
118-
float seaLevelForAltitude(float altitude, float atmospheric, float temp);
119-
void getEvent(sensors_event_t*);
120-
void getSensor(sensor_t*);
121-
122-
private:
123-
uint8_t _i2c_addr;
124-
int32_t _sensorID;
108+
class Adafruit_BME280;
109+
110+
/** Adafruit Unified Sensor interface for temperature component of BME280 */
111+
class Adafruit_BME280_Temp : public Adafruit_Sensor {
112+
public:
113+
/** @brief Create an Adafruit_Sensor compatible object for the temp sensor
114+
@param parent A pointer to the BME280 class */
115+
Adafruit_BME280_Temp(Adafruit_BME280 *parent) { _theBME280 = parent; }
116+
bool getEvent(sensors_event_t *);
117+
void getSensor(sensor_t *);
118+
119+
private:
120+
int _sensorID = 280;
121+
Adafruit_BME280 *_theBME280 = NULL;
125122
};
126123

127-
*/
124+
/** Adafruit Unified Sensor interface for pressure component of BME280 */
125+
class Adafruit_BME280_Pressure : public Adafruit_Sensor {
126+
public:
127+
/** @brief Create an Adafruit_Sensor compatible object for the pressure sensor
128+
@param parent A pointer to the BME280 class */
129+
Adafruit_BME280_Pressure(Adafruit_BME280 *parent) { _theBME280 = parent; }
130+
bool getEvent(sensors_event_t *);
131+
void getSensor(sensor_t *);
132+
133+
private:
134+
int _sensorID = 280;
135+
Adafruit_BME280 *_theBME280 = NULL;
136+
};
137+
138+
/** Adafruit Unified Sensor interface for humidity component of BME280 */
139+
class Adafruit_BME280_Humidity : public Adafruit_Sensor {
140+
public:
141+
/** @brief Create an Adafruit_Sensor compatible object for the humidity sensor
142+
@param parent A pointer to the BME280 class */
143+
Adafruit_BME280_Humidity(Adafruit_BME280 *parent) { _theBME280 = parent; }
144+
bool getEvent(sensors_event_t *);
145+
void getSensor(sensor_t *);
146+
147+
private:
148+
int _sensorID = 280;
149+
Adafruit_BME280 *_theBME280 = NULL;
150+
};
128151

129152
/**************************************************************************/
130153
/*!
@@ -190,10 +213,9 @@ class Adafruit_BME280 {
190213
// constructors
191214
Adafruit_BME280();
192215
Adafruit_BME280(int8_t cspin, SPIClass *theSPI = &SPI);
193-
Adafruit_BME280(int8_t cspin, int8_t mosipin, int8_t misopin,
194-
int8_t sckpin);
195-
196-
bool begin(uint8_t addr=BME280_ADDRESS, TwoWire *theWire=&Wire);
216+
Adafruit_BME280(int8_t cspin, int8_t mosipin, int8_t misopin, int8_t sckpin);
217+
~Adafruit_BME280(void);
218+
bool begin(uint8_t addr = BME280_ADDRESS, TwoWire *theWire = &Wire);
197219
bool init();
198220

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

237+
Adafruit_Sensor *getTemperatureSensor(void);
238+
Adafruit_Sensor *getPressureSensor(void);
239+
Adafruit_Sensor *getHumiditySensor(void);
240+
215241
protected:
216242
TwoWire *_wire; //!< pointer to a TwoWire object
217243
SPIClass *_spi; //!< pointer to SPI object
244+
245+
Adafruit_BME280_Temp *temp_sensor = NULL;
246+
//!< Adafruit_Sensor compat temperature sensor component
247+
248+
Adafruit_BME280_Pressure *pressure_sensor = NULL;
249+
//!< Adafruit_Sensor compat pressure sensor component
250+
251+
Adafruit_BME280_Humidity *humidity_sensor = NULL;
252+
//!< Adafruit_Sensor compat humidity sensor component
253+
218254
void readCoefficients(void);
219255
bool isReadingCalibration(void);
220256
uint8_t spixfer(uint8_t x);

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Adafruit BME280 Library [![Build Status](https://travis-ci.com/adafruit/Adafruit_BME280_Library.svg?branch=master)](https://travis-ci.com/adafruit/Adafruit_BME280_Library)
1+
# Adafruit BME280 Library ![Build Status](https://github.com/adafruit/Adafruit_BME280_Library/workflows/Arduino%20Library%20CI/badge.svg)
22

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

examples/advancedsettings/advancedsettings.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void setup() {
3838
Serial.begin(9600);
3939
Serial.println(F("BME280 test"));
4040

41-
if (! bme.begin(&Wire)) {
41+
if (! bme.begin(0x77, &Wire)) {
4242
Serial.println("Could not find a valid BME280 sensor, check wiring!");
4343
while (1);
4444
}

0 commit comments

Comments
 (0)