Skip to content

Commit a3b364d

Browse files
committed
MCP3421 Refactor to configureSensor and set Gain
1 parent 0416bc6 commit a3b364d

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/components/i2c/drivers/WipperSnapper_I2C_Driver_MCP3421.h

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,37 @@ class WipperSnapper_I2C_Driver_MCP3421 : public WipperSnapper_I2C_Driver {
6161
return false;
6262
}
6363

64+
if (!configureSensor()){
65+
WS_DEBUG_PRINTLN("Failed to configure MCP3421 sensor");
66+
return false;
67+
}
68+
return true;
69+
}
70+
71+
/*******************************************************************************/
72+
/*!
73+
@brief Configures the MCP3421 sensor.
74+
@returns True if the sensor was configured successfully, False otherwise.
75+
*/
76+
/*******************************************************************************/
77+
bool configureSensor() {
6478
// NOTE: We should allow the gain to be set in future, like resolution
6579
// 12_BIT (240 SPS), 14_BIT (60 SPS), 16_BIT (15 SPS), 18_BIT (3.75 SPS)
6680
_mcp3421->setResolution(RESOLUTION_18_BIT);
6781
if (_mcp3421->getResolution() != RESOLUTION_18_BIT) {
68-
WS_DEBUG_PRINTLN("Failed to set resolution");
82+
WS_DEBUG_PRINTLN("Failed to set resolution to 18-bit");
83+
return false;
84+
}
85+
86+
_mcp3421->setGain(GAIN_8X);
87+
if (_mcp3421->getGain() != GAIN_8X) {
88+
WS_DEBUG_PRINTLN("Failed to set gain to 8x");
6989
return false;
7090
}
7191

7292
_mcp3421->setMode(MODE_ONE_SHOT);
7393
if (_mcp3421->getMode() != MODE_ONE_SHOT) {
74-
WS_DEBUG_PRINTLN("Failed to set mode");
94+
WS_DEBUG_PRINTLN("Failed to set mode to One-Shot");
7595
return false;
7696
}
7797
return true;

0 commit comments

Comments
 (0)