Closed hhk7734 closed 4 years ago
Thanks for spotting that. My two cents on this - the overrides should be arranged differently to avoid the code duplication. Something like this:
bool Adafruit_BME280::begin(void) {
return begin(BME280_ADDRESS, &Wire);
}
bool Adafruit_BME280::begin(TwoWire *theWire) {
return begin(BME280_ADDRESS, theWire);
}
bool Adafruit_BME280::begin(uint8_t addr) {
return begin(addr, &Wire);
}
bool Adafruit_BME280::begin(uint8_t addr, TwoWire *theWire) {
bool status = false;
_i2caddr = addr;
_wire = theWire;
status = init();
if (!status) {
_i2caddr = BME280_ADDRESS_ALTERNATE;
status = init();
}
return status;
}
@caternuson Your suggestion is so good. I corrected it.
@hhk7734 Thanks. This looks good. Did you test this on hardware?
@caternuson Yes, I did.
examples/bme280test/bme280test.ino
line 46
- status = bme.begin();
+ status = bme.begin(0x01, &Wire);
line 46
- status = bme.begin();
+ status = bme.begin(&Wire3);
line 46
- status = bme.begin();
+ status = bme.begin(0x01);
Cool. Thanks.
It will be in the 1.1.0 release when it becomes available: https://github.com/adafruit/Adafruit_BME280_Library/releases/tag/1.1.0
When calling begin(void), if failed to init() with i2caddr=BME280_ADDRESS, it tries again with i2caddr=BME280_ADDRESS_ALTERNATE. But it does not try again when calling begin(TwoWire). So I added that.
examples/bme280test/bme280test.ino