diff --git a/Adafruit_ADXL345_U.cpp b/Adafruit_ADXL345_U.cpp index e9716d0..49e90af 100644 --- a/Adafruit_ADXL345_U.cpp +++ b/Adafruit_ADXL345_U.cpp @@ -14,6 +14,13 @@ #include "Adafruit_ADXL345_U.h" +Adafruit_ADXL345_Unified::~Adafruit_ADXL345_Unified() { + if (i2c_dev) + delete i2c_dev; + if (spi_dev) + delete spi_dev; +} + /**************************************************************************/ /*! @brief Writes one byte to the specified destination register @@ -146,6 +153,8 @@ Adafruit_ADXL345_Unified::Adafruit_ADXL345_Unified(uint8_t clock, uint8_t miso, /**************************************************************************/ bool Adafruit_ADXL345_Unified::begin(uint8_t i2caddr) { if (spi_dev == NULL) { + if (i2c_dev) + delete i2c_dev; i2c_dev = new Adafruit_I2CDevice(i2caddr, &Wire); if (!i2c_dev->begin()) return false; diff --git a/Adafruit_ADXL345_U.h b/Adafruit_ADXL345_U.h index c7c900e..35490e0 100644 --- a/Adafruit_ADXL345_U.h +++ b/Adafruit_ADXL345_U.h @@ -129,6 +129,7 @@ class Adafruit_ADXL345_Unified : public Adafruit_Sensor { Adafruit_ADXL345_Unified(int32_t sensorID = -1); Adafruit_ADXL345_Unified(uint8_t clock, uint8_t miso, uint8_t mosi, uint8_t cs, int32_t sensorID = -1); + ~Adafruit_ADXL345_Unified(); bool begin(uint8_t addr = ADXL345_DEFAULT_ADDRESS); void setRange(range_t range); diff --git a/library.properties b/library.properties index ee81644..9f2f577 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Adafruit ADXL345 -version=1.3.0 +version=1.3.1 author=Adafruit maintainer=Adafruit sentence=Unified driver for the ADXL345 Accelerometer