@@ -56,7 +56,7 @@ class WipperSnapper_I2C_Driver_MCP3421 : public WipperSnapper_I2C_Driver {
56
56
/* ******************************************************************************/
57
57
bool begin () {
58
58
_mcp3421 = new Adafruit_MCP3421 ();
59
- if (_mcp3421->begin ((uint8_t )_sensorAddress, _i2c)) {
59
+ if (! _mcp3421->begin ((uint8_t )_sensorAddress, _i2c)) {
60
60
WS_DEBUG_PRINTLN (" Failed to find MCP3421 chip" );
61
61
return false ;
62
62
}
@@ -79,32 +79,35 @@ class WipperSnapper_I2C_Driver_MCP3421 : public WipperSnapper_I2C_Driver {
79
79
80
80
/* ******************************************************************************/
81
81
/* !
82
- @brief Reads a voltage sensor and converts the
83
- reading into the expected SI unit.
84
- @param voltageEvent
85
- voltage sensor reading, in volts.
82
+ @brief Reads the ADC sensor with short wait for data.
83
+ @param rawEvent
84
+ ADC sensor reading
86
85
@returns True if the sensor event was obtained successfully, False
87
86
otherwise.
88
87
*/
89
88
/* ******************************************************************************/
90
- bool getEventVoltage (sensors_event_t *voltageEvent ) {
89
+ bool getEventRaw (sensors_event_t *rawEvent ) {
91
90
ulong start = millis ();
92
91
if (!_mcp3421->startOneShotConversion ()) {
93
92
WS_DEBUG_PRINTLN (" Failed to start one-shot conversion" );
94
93
return false ;
95
94
}
96
95
while (!_mcp3421->isReady ()) {
97
- if (millis () - start > 1000 ) {
96
+ ulong newMillis = millis ();
97
+ if (newMillis - start > 500 ) {
98
98
WS_DEBUG_PRINTLN (" Timeout waiting for conversion to complete" );
99
99
return false ;
100
+ } else if (start > newMillis) {
101
+ start = millis (); // rollover
100
102
}
103
+ delay (50 );
101
104
}
102
- voltageEvent-> voltage = (float )_mcp3421->readADC ();
105
+ rawEvent-> data [ 0 ] = (float )_mcp3421->readADC ();
103
106
return true ;
104
107
}
105
108
106
109
protected:
107
- Adafruit_MCP3421 *_mcp3421; // /< Pointer to MCP3421 temperature sensor object
110
+ Adafruit_MCP3421 *_mcp3421; // /< Pointer to MCP3421 sensor object
108
111
};
109
112
110
113
#endif // WipperSnapper_I2C_Driver_MCP3421
0 commit comments