Skip to content

Commit

Permalink
NAU7802: refactor data flushing
Browse files Browse the repository at this point in the history
  • Loading branch information
tyeth committed May 21, 2024
1 parent 27ddddf commit b23fdea
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/components/i2c/drivers/WipperSnapper_I2C_Driver_NAU7802.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,7 @@ class WipperSnapper_I2C_Driver_NAU7802 : public WipperSnapper_I2C_Driver {
}

// Take 10 readings to flush out old readings (10 samples per second)
for (uint8_t skipCounter = 0; skipCounter < 10; skipCounter++) {
while (!_nau7802->available())
delay(1);
_nau7802->read();
}
flushNAU7802(10);

for (int retries = 0; retries < 3; retries++) {
if (_nau7802->calibrate(NAU7802_CALMOD_INTERNAL)) {
Expand All @@ -101,6 +97,19 @@ class WipperSnapper_I2C_Driver_NAU7802 : public WipperSnapper_I2C_Driver {
return false;
}

/*******************************************************************************/
/*!
@brief Gets datapoints from sensor and discards (flushes old data).
*/
/*******************************************************************************/
void flushNAU7802(uint8_t count) {
for (uint8_t skipCounter = 0; skipCounter < count; skipCounter++) {
while (!_nau7802->available())
delay(1);
_nau7802->read();
}
}

/*******************************************************************************/
/*!
@brief Gets the sensor's raw "force" value.
Expand Down

0 comments on commit b23fdea

Please sign in to comment.