Skip to content

Commit

Permalink
Merge pull request #58 from caternuson/iss57
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 7dea792 + 56a5e5e commit afdc338
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions Adafruit_BMP280.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ Adafruit_BMP280::Adafruit_BMP280(TwoWire *theWire) {
}

Adafruit_BMP280::~Adafruit_BMP280(void) {
if (spi_dev)
delete spi_dev;
if (i2c_dev)
delete i2c_dev;
delete temp_sensor;
delete pressure_sensor;
}
Expand Down Expand Up @@ -80,10 +84,14 @@ Adafruit_BMP280::Adafruit_BMP280(int8_t cspin, int8_t mosipin, int8_t misopin,
*/
bool Adafruit_BMP280::begin(uint8_t addr, uint8_t chipid) {
if (spi_dev == NULL) {
// I2C mode
if (i2c_dev)
delete i2c_dev;
i2c_dev = new Adafruit_I2CDevice(addr, _wire);
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 BMP280 Library
version=2.4.0
version=2.4.1
author=Adafruit
maintainer=Adafruit <[email protected]>
sentence=Arduino library for BMP280 sensors.
Expand Down

0 comments on commit afdc338

Please sign in to comment.