Skip to content

Commit

Permalink
Merge pull request #24 from caternuson/iss23_remove_chunk
Browse files Browse the repository at this point in the history
Remove chunk and memory alloc tweaks
  • Loading branch information
caternuson authored Aug 24, 2021
2 parents 2665171 + 910c33e commit 70db666
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 24 deletions.
31 changes: 9 additions & 22 deletions Adafruit_AMG88xx.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#include "Adafruit_AMG88xx.h"

Adafruit_AMG88xx::~Adafruit_AMG88xx(void) {
if (i2c_dev)
delete i2c_dev;
}

/**************************************************************************/
/*!
@brief Setups the I2C interface and hardware
Expand All @@ -10,6 +15,8 @@
*/
/**************************************************************************/
bool Adafruit_AMG88xx::begin(uint8_t addr, TwoWire *theWire) {
if (i2c_dev)
delete i2c_dev;
i2c_dev = new Adafruit_I2CDevice(addr, theWire);
if (!i2c_dev->begin())
return false;
Expand Down Expand Up @@ -212,28 +219,8 @@ uint8_t Adafruit_AMG88xx::read8(byte reg) {
}

void Adafruit_AMG88xx::read(uint8_t reg, uint8_t *buf, uint8_t num) {
uint8_t buffer[1];
size_t chunkSize = i2c_dev->maxBufferSize();
if (chunkSize > num) {
// can just read
buffer[0] = reg;
i2c_dev->write(buffer, 1);
i2c_dev->read(buf, num);
} else {
// must read in chunks
uint8_t pos = 0;
uint8_t read_buffer[chunkSize];
while (pos < num) {
buffer[0] = reg + pos;
i2c_dev->write(buffer, 1);
uint8_t read_now = min(uint8_t(chunkSize), (uint8_t)(num - pos));
i2c_dev->read(read_buffer, read_now);
for (uint8_t i = 0; i < read_now; i++) {
buf[pos] = read_buffer[i];
pos++;
}
}
}
uint8_t buffer[1] = {reg};
i2c_dev->write_then_read(buffer, 1, buf, num);
}

void Adafruit_AMG88xx::write(uint8_t reg, uint8_t *buf, uint8_t num) {
Expand Down
2 changes: 1 addition & 1 deletion Adafruit_AMG88xx.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class Adafruit_AMG88xx {
public:
// constructors
Adafruit_AMG88xx(void){};
~Adafruit_AMG88xx(void){};
~Adafruit_AMG88xx(void);

bool begin(uint8_t addr = AMG88xx_ADDRESS, TwoWire *theWire = &Wire);

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 AMG88xx Library
version=1.2.0
version=1.2.1
author=Adafruit
maintainer=Adafruit <[email protected]>
sentence=Arduino library for AMG88xx 8x8 Thermocouple Sensors.
Expand Down

0 comments on commit 70db666

Please sign in to comment.