Skip to content

Commit ddec5c1

Browse files
authored
Merge pull request #68 from hhk7734/master
Add alternate address to 'begfin(TwoWire)'
2 parents f3fc9f6 + 156a053 commit ddec5c1

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

Adafruit_BME280.cpp

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -63,52 +63,50 @@ Adafruit_BME280::Adafruit_BME280(int8_t cspin, int8_t mosipin, int8_t misopin,
6363

6464
/*!
6565
* @brief Initialise sensor with given parameters / settings
66+
* @param addr the I2C address the device can be found on
6667
* @param theWire the I2C object to use
6768
* @returns true on success, false otherwise
6869
*/
69-
bool Adafruit_BME280::begin(TwoWire *theWire) {
70+
bool Adafruit_BME280::begin(uint8_t addr, TwoWire *theWire) {
71+
bool status = false;
72+
_i2caddr = addr;
7073
_wire = theWire;
71-
_i2caddr = BME280_ADDRESS;
72-
return init();
74+
status = init();
75+
if ((!status) && (addr != BME280_ADDRESS)) {
76+
_i2caddr = BME280_ADDRESS;
77+
status = init();
78+
}
79+
if ((!status) && (addr != BME280_ADDRESS_ALTERNATE)) {
80+
_i2caddr = BME280_ADDRESS_ALTERNATE;
81+
status = init();
82+
}
83+
return status;
7384
}
7485

7586
/*!
7687
* @brief Initialise sensor with given parameters / settings
77-
* @param addr the I2C address the device can be found on
88+
* @param theWire the I2C object to use
7889
* @returns true on success, false otherwise
7990
*/
80-
bool Adafruit_BME280::begin(uint8_t addr) {
81-
_i2caddr = addr;
82-
_wire = &Wire;
83-
return init();
91+
bool Adafruit_BME280::begin(TwoWire *theWire) {
92+
return begin(BME280_ADDRESS, theWire);
8493
}
8594

8695
/*!
8796
* @brief Initialise sensor with given parameters / settings
8897
* @param addr the I2C address the device can be found on
89-
* @param theWire the I2C object to use
9098
* @returns true on success, false otherwise
9199
*/
92-
bool Adafruit_BME280::begin(uint8_t addr, TwoWire *theWire) {
93-
_i2caddr = addr;
94-
_wire = theWire;
95-
return init();
100+
bool Adafruit_BME280::begin(uint8_t addr) {
101+
return begin(addr, &Wire);
96102
}
97103

98104
/*!
99105
* @brief Initialise sensor with given parameters / settings
100106
* @returns true on success, false otherwise
101107
*/
102108
bool Adafruit_BME280::begin(void) {
103-
bool status = false;
104-
_i2caddr = BME280_ADDRESS;
105-
_wire = &Wire;
106-
status = init();
107-
if (!status) {
108-
_i2caddr = BME280_ADDRESS_ALTERNATE;
109-
status = init();
110-
}
111-
return status;
109+
return begin(BME280_ADDRESS, &Wire);
112110
}
113111

114112
/*!

0 commit comments

Comments
 (0)