Skip to content

Commit

Permalink
Merge pull request #98 from caternuson/mem_tweak
Browse files Browse the repository at this point in the history
Tweak memory alloc and cleanup
  • Loading branch information
caternuson authored Aug 24, 2021
2 parents 587329a + b1e4352 commit a9c8219
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Adafruit_BME280.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ Adafruit_BME280::Adafruit_BME280(int8_t cspin, int8_t mosipin, int8_t misopin,
}

Adafruit_BME280::~Adafruit_BME280(void) {
if (spi_dev) {
delete spi_dev;
}
if (i2c_dev) {
delete i2c_dev;
}
if (temp_sensor) {
delete temp_sensor;
}
Expand All @@ -79,10 +85,14 @@ Adafruit_BME280::~Adafruit_BME280(void) {
*/
bool Adafruit_BME280::begin(uint8_t addr, TwoWire *theWire) {
if (spi_dev == NULL) {
// I2C mode
if (i2c_dev)
delete i2c_dev;
i2c_dev = new Adafruit_I2CDevice(addr, theWire);
if (!i2c_dev->begin())
return false;
} else {
// SPI mode
if (!spi_dev->begin())
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Adafruit BME280 Library
version=2.2.0
version=2.2.1
author=Adafruit
maintainer=Adafruit <[email protected]>
sentence=Arduino library for BME280 sensors.
Expand Down

0 comments on commit a9c8219

Please sign in to comment.