1919#include " WipperSnapper_I2C_Driver.h"
2020#include < Adafruit_NAU7802.h>
2121
22+ #define NAU7802_TIMEOUT_MS 250 // Timeout waiting for data from NAU7802
23+
2224/* *************************************************************************/
2325/* !
2426 @brief Class that provides a driver interface for the NAU7802.
@@ -55,20 +57,23 @@ class WipperSnapper_I2C_Driver_NAU7802 : public WipperSnapper_I2C_Driver {
5557 @returns True if initialized successfully, False otherwise.
5658 */
5759 /* ******************************************************************************/
58- bool begin () {
59- if (!_nau7802->begin (_i2c))
60- return false ;
60+ bool begin () { return _nau7802->begin (_i2c) && configure_nau7802 (); }
6161
62+ /* ******************************************************************************/
63+ /* !
64+ @brief Configures the NAU7802 sensor.
65+ @returns True if configured successfully, False otherwise.
66+ */
67+ /* ******************************************************************************/
68+ bool configure_nau7802 () {
6269 if (!_nau7802->setLDO (NAU7802_3V0)) {
6370 WS_DEBUG_PRINTLN (" Failed to set LDO to 3V0" );
71+ return false ;
6472 }
6573
6674 if (!_nau7802->setGain (NAU7802_GAIN_128)) {
6775 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 ;
7277 }
7378 return true ;
7479 }
@@ -86,8 +91,8 @@ class WipperSnapper_I2C_Driver_NAU7802 : public WipperSnapper_I2C_Driver {
8691
8792 // Wait for the sensor to be ready
8893 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" );
9196 return false ;
9297 }
9398 }
0 commit comments