Skip to content

Commit

Permalink
Merge pull request #25 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 25, 2021
2 parents 2e03583 + 30d6de7 commit 628b7d8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
9 changes: 9 additions & 0 deletions Adafruit_ADXL345_U.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions Adafruit_ADXL345_U.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
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 ADXL345
version=1.3.0
version=1.3.1
author=Adafruit
maintainer=Adafruit <[email protected]>
sentence=Unified driver for the ADXL345 Accelerometer
Expand Down

0 comments on commit 628b7d8

Please sign in to comment.