Skip to content

Commit 1d650a0

Browse files
committed
Updates from PR feedback + build settings
1 parent 3269247 commit 1d650a0

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

.vscode/settings.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"limits": "c",
44
"type_traits": "c"
55
},
6-
"C_Cpp.dimInactiveRegions": false,
7-
"dotnet.defaultSolution": "disable"
6+
"C_Cpp.dimInactiveRegions": true,
7+
"dotnet.defaultSolution": "disable",
8+
"cmake.configureOnOpen": false
89
}

src/components/i2c/WipperSnapper_I2C.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,14 +389,14 @@ bool WipperSnapper_Component_I2C::initI2CDevice(
389389
} else if (strcmp("nau7802", msgDeviceInitReq->i2c_device_name) == 0) {
390390
_nau7802 = new WipperSnapper_I2C_Driver_NAU7802(this->_i2c, i2cAddress);
391391
if (!_nau7802->begin()) {
392-
WS_DEBUG_PRINTLN("ERROR: Failed to initialize NAU7802/303");
392+
WS_DEBUG_PRINTLN("ERROR: Failed to initialize NAU7802");
393393
_busStatusResponse =
394394
wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_DEVICE_INIT_FAIL;
395395
return false;
396396
}
397397
_nau7802->configureDriver(msgDeviceInitReq);
398398
drivers.push_back(_nau7802);
399-
WS_DEBUG_PRINTLN("NAU7802/303 Initialized Successfully!");
399+
WS_DEBUG_PRINTLN("NAU7802 Initialized Successfully!");
400400
} else if (strcmp("sgp30", msgDeviceInitReq->i2c_device_name) == 0) {
401401
_sgp30 = new WipperSnapper_I2C_Driver_SGP30(this->_i2c, i2cAddress);
402402
if (!_sgp30->begin()) {

src/components/i2c/drivers/WipperSnapper_I2C_Driver_NAU7802.h

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
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

Comments
 (0)