Correct 'begin()' to check basic I2C address

suggestion: Carter Nelson <caternuson@gmail.com>
This commit is contained in:
Hyeonki Hong 2019-11-12 07:37:00 +09:00
parent f3fc9f61d9
commit 156a0537d6
1 changed files with 25 additions and 27 deletions

View File

@ -61,15 +61,35 @@ Adafruit_BME280::Adafruit_BME280(int8_t cspin, int8_t mosipin, int8_t misopin,
int8_t sckpin) int8_t sckpin)
: _cs(cspin), _mosi(mosipin), _miso(misopin), _sck(sckpin) {} : _cs(cspin), _mosi(mosipin), _miso(misopin), _sck(sckpin) {}
/*!
* @brief Initialise sensor with given parameters / settings
* @param addr the I2C address the device can be found on
* @param theWire the I2C object to use
* @returns true on success, false otherwise
*/
bool Adafruit_BME280::begin(uint8_t addr, TwoWire *theWire) {
bool status = false;
_i2caddr = addr;
_wire = theWire;
status = init();
if ((!status) && (addr != BME280_ADDRESS)) {
_i2caddr = BME280_ADDRESS;
status = init();
}
if ((!status) && (addr != BME280_ADDRESS_ALTERNATE)) {
_i2caddr = BME280_ADDRESS_ALTERNATE;
status = init();
}
return status;
}
/*! /*!
* @brief Initialise sensor with given parameters / settings * @brief Initialise sensor with given parameters / settings
* @param theWire the I2C object to use * @param theWire the I2C object to use
* @returns true on success, false otherwise * @returns true on success, false otherwise
*/ */
bool Adafruit_BME280::begin(TwoWire *theWire) { bool Adafruit_BME280::begin(TwoWire *theWire) {
_wire = theWire; return begin(BME280_ADDRESS, theWire);
_i2caddr = BME280_ADDRESS;
return init();
} }
/*! /*!
@ -78,21 +98,7 @@ bool Adafruit_BME280::begin(TwoWire *theWire) {
* @returns true on success, false otherwise * @returns true on success, false otherwise
*/ */
bool Adafruit_BME280::begin(uint8_t addr) { bool Adafruit_BME280::begin(uint8_t addr) {
_i2caddr = addr; return begin(addr, &Wire);
_wire = &Wire;
return init();
}
/*!
* @brief Initialise sensor with given parameters / settings
* @param addr the I2C address the device can be found on
* @param theWire the I2C object to use
* @returns true on success, false otherwise
*/
bool Adafruit_BME280::begin(uint8_t addr, TwoWire *theWire) {
_i2caddr = addr;
_wire = theWire;
return init();
} }
/*! /*!
@ -100,15 +106,7 @@ bool Adafruit_BME280::begin(uint8_t addr, TwoWire *theWire) {
* @returns true on success, false otherwise * @returns true on success, false otherwise
*/ */
bool Adafruit_BME280::begin(void) { bool Adafruit_BME280::begin(void) {
bool status = false; return begin(BME280_ADDRESS, &Wire);
_i2caddr = BME280_ADDRESS;
_wire = &Wire;
status = init();
if (!status) {
_i2caddr = BME280_ADDRESS_ALTERNATE;
status = init();
}
return status;
} }
/*! /*!