Skip to content

Commit

Permalink
remove chunk
Browse files Browse the repository at this point in the history
  • Loading branch information
caternuson committed Aug 11, 2021
1 parent ca4b3c9 commit 46afc07
Showing 1 changed file with 2 additions and 23 deletions.
25 changes: 2 additions & 23 deletions Adafruit_CCS811.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,29 +273,8 @@ uint8_t Adafruit_CCS811::read8(byte reg) {
}

void Adafruit_CCS811::read(uint8_t reg, uint8_t *buf, uint8_t num) {
uint8_t buffer[1];
size_t chunkSize = i2c_dev->maxBufferSize();
uint8_t pos = 0;

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 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_CCS811::write(uint8_t reg, uint8_t *buf, uint8_t num) {
Expand Down

0 comments on commit 46afc07

Please sign in to comment.