19
19
#include " WipperSnapper_I2C_Driver.h"
20
20
#include < Adafruit_NAU7802.h>
21
21
22
+ #define NAU7802_TIMEOUT_MS 250 // Timeout waiting for data from NAU7802
23
+
22
24
/* *************************************************************************/
23
25
/* !
24
26
@brief Class that provides a driver interface for the NAU7802.
@@ -55,20 +57,23 @@ class WipperSnapper_I2C_Driver_NAU7802 : public WipperSnapper_I2C_Driver {
55
57
@returns True if initialized successfully, False otherwise.
56
58
*/
57
59
/* ******************************************************************************/
58
- bool begin () {
59
- if (!_nau7802->begin (_i2c))
60
- return false ;
60
+ bool begin () { return _nau7802->begin (_i2c) && configure_nau7802 (); }
61
61
62
+ /* ******************************************************************************/
63
+ /* !
64
+ @brief Configures the NAU7802 sensor.
65
+ @returns True if configured successfully, False otherwise.
66
+ */
67
+ /* ******************************************************************************/
68
+ bool configure_nau7802 () {
62
69
if (!_nau7802->setLDO (NAU7802_3V0)) {
63
70
WS_DEBUG_PRINTLN (" Failed to set LDO to 3V0" );
71
+ return false ;
64
72
}
65
73
66
74
if (!_nau7802->setGain (NAU7802_GAIN_128)) {
67
75
WS_DEBUG_PRINTLN (" Failed to set gain to 128" );
68
- }
69
-
70
- if (!_nau7802->setRate (NAU7802_RATE_10SPS)) {
71
- WS_DEBUG_PRINTLN (" Failed to set sample rate to 10SPS" );
76
+ return false ;
72
77
}
73
78
return true ;
74
79
}
@@ -86,8 +91,8 @@ class WipperSnapper_I2C_Driver_NAU7802 : public WipperSnapper_I2C_Driver {
86
91
87
92
// Wait for the sensor to be ready
88
93
while (!_nau7802->available ()) {
89
- if (millis () - start > 1000 ) {
90
- WS_DEBUG_PRINTLN (" NAU7802 not available" );
94
+ if (millis () - start > NAU7802_TIMEOUT_MS ) {
95
+ WS_DEBUG_PRINTLN (" NAU7802 data not available" );
91
96
return false ;
92
97
}
93
98
}
0 commit comments