adafruit / Adafruit_BME680

117 stars 76 forks source link

Allow setting wire port after sensor has been created #49

Open uutzinger opened 2 years ago

uutzinger commented 2 years ago

in most Arduino libraries its possible to change the wire port after the sensor structure has been created. For example the main program initialized the sensor with: Adafruit_BME680 bme680;

Then the main program is searching for the sensor on the available wire interfaces. Then we provide that wire interface to the driver which keeps it in the _wire variable.

Either we provide opportunity to set wire interface in begin() function or with the proposed change in the file Adafruit_BME689.h by adding the following line:

void setWire(TwoWire *theWire = &Wire) {_wire = theWire;}

which exposed the private variable _wire.

caternuson commented 1 year ago

An alternate Wire instance can be provided as a parameter to the constructor.

Do you have an actual use case where the sensor changes what pins it is connected to after initial setup? Or some other specific use case requiring dynamically changing the Wire instance?