From b1e4352b7b89ca88f3d7821bfd116f20923727f8 Mon Sep 17 00:00:00 2001 From: caternuson Date: Tue, 24 Aug 2021 10:21:27 -0700 Subject: [PATCH] tweak memory alloc and cleanup --- Adafruit_BME280.cpp | 10 ++++++++++ library.properties | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Adafruit_BME280.cpp b/Adafruit_BME280.cpp index 9113f2b..838839e 100644 --- a/Adafruit_BME280.cpp +++ b/Adafruit_BME280.cpp @@ -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; } @@ -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; } diff --git a/library.properties b/library.properties index e9bf390..45c89e5 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Adafruit BME280 Library -version=2.2.0 +version=2.2.1 author=Adafruit maintainer=Adafruit sentence=Arduino library for BME280 sensors.