Skip to content

Commit 7b2a437

Browse files
committed
NAU7802: refactor data flushing
1 parent 7be1e24 commit 7b2a437

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/components/i2c/drivers/WipperSnapper_I2C_Driver_NAU7802.h

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,7 @@ class WipperSnapper_I2C_Driver_NAU7802 : public WipperSnapper_I2C_Driver {
8383
}
8484

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

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

100+
/*******************************************************************************/
101+
/*!
102+
@brief Gets datapoints from sensor and discards (flushes old data).
103+
*/
104+
/*******************************************************************************/
105+
void flushNAU7802(uint8_t count) {
106+
for (uint8_t skipCounter = 0; skipCounter < count; skipCounter++) {
107+
while (!_nau7802->available())
108+
delay(1);
109+
_nau7802->read();
110+
}
111+
}
112+
104113
/*******************************************************************************/
105114
/*!
106115
@brief Gets the sensor's raw "force" value.

0 commit comments

Comments
 (0)