Skip to content

Commit d391989

Browse files
committed
adjust read logic for MLX90632 if not continuous reads (offline/low-power mode?)
1 parent 79f372a commit d391989

File tree

1 file changed

+15
-32
lines changed

1 file changed

+15
-32
lines changed

src/components/i2c/drivers/WipperSnapper_I2C_Driver_MLX90632D.h

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@ class WipperSnapper_I2C_Driver_MLX90632D : public WipperSnapper_I2C_Driver {
8080
// Reset the device
8181
if (!_mlx90632->reset()) {
8282
WS_DEBUG_PRINTLN(F("Device reset failed"));
83-
while (1) {
84-
delay(10);
85-
}
83+
return false;
8684
}
8785
WS_DEBUG_PRINTLN(F("Device reset: SUCCESS"));
8886

@@ -261,25 +259,25 @@ class WipperSnapper_I2C_Driver_MLX90632D : public WipperSnapper_I2C_Driver {
261259
return true;
262260
}
263261

262+
// Check if we need to trigger a new measurement for step modes
263+
mlx90632_mode_t currentMode = _mlx90632->getMode();
264+
if (currentMode == MLX90632_MODE_STEP ||
265+
currentMode == MLX90632_MODE_SLEEPING_STEP) {
266+
// Trigger single measurement (SOC bit) for step modes
267+
if (!_mlx90632->startSingleMeasurement()) {
268+
WS_DEBUG_PRINTLN(F("Failed to start single measurement"));
269+
return false;
270+
}
271+
delay(510); // Wait for measurement to complete @ 2Hz
272+
}
273+
264274
// Only check new data flag - much more efficient for continuous mode
265275
if (_mlx90632->isNewData()) {
266-
WS_DEBUG_PRINT(F("New Data Available - Cycle Position: "));
267-
WS_DEBUG_PRINTLN(_mlx90632->readCyclePosition());
268-
269-
// Read ambient temperature
270276
_deviceTemp = _mlx90632->getAmbientTemperature();
271-
WS_DEBUG_PRINT(F("Ambient Temperature: "));
272-
WS_DEBUG_PRINT(_deviceTemp, 4);
273-
WS_DEBUG_PRINTLN(F(" °C"));
274-
275-
// Read object temperature
276277
_objectTemp = _mlx90632->getObjectTemperature();
277-
WS_DEBUG_PRINT(F("Object Temperature: "));
278278
if (isnan(_objectTemp)) {
279279
WS_DEBUG_PRINTLN(F("NaN (invalid cycle position)"));
280-
} else {
281-
WS_DEBUG_PRINT(_objectTemp, 4);
282-
WS_DEBUG_PRINTLN(F(" °C"));
280+
return false;
283281
}
284282
result = true;
285283
_lastRead = millis();
@@ -291,15 +289,7 @@ class WipperSnapper_I2C_Driver_MLX90632D : public WipperSnapper_I2C_Driver {
291289
WS_DEBUG_PRINTLN(F("No new data available, skipping read"));
292290
}
293291

294-
// Check if we need to trigger a new measurement for step modes
295-
mlx90632_mode_t currentMode = _mlx90632->getMode();
296-
if (currentMode == MLX90632_MODE_STEP ||
297-
currentMode == MLX90632_MODE_SLEEPING_STEP) {
298-
// Trigger single measurement (SOC bit) for step modes
299-
if (!_mlx90632->startSingleMeasurement()) {
300-
WS_DEBUG_PRINTLN(F("Failed to start single measurement"));
301-
}
302-
}
292+
303293
return result;
304294
}
305295

@@ -314,12 +304,6 @@ class WipperSnapper_I2C_Driver_MLX90632D : public WipperSnapper_I2C_Driver {
314304
/*******************************************************************************/
315305
bool getEventAmbientTemp(sensors_event_t *tempEvent) {
316306
if (ReadSensorData() && _deviceTemp != NAN) {
317-
// TODO: check max/min or error values in datasheet
318-
// if (_deviceTemp < -40 || _deviceTemp > 125) {
319-
// WS_DEBUG_PRINTLN(F("Invalid ambient temperature"));
320-
// return false;
321-
// }
322-
// if the sensor was read recently, return the cached temperature
323307
tempEvent->temperature = _deviceTemp;
324308
return true;
325309
}
@@ -337,7 +321,6 @@ class WipperSnapper_I2C_Driver_MLX90632D : public WipperSnapper_I2C_Driver {
337321
/*******************************************************************************/
338322
bool getEventObjectTemp(sensors_event_t *tempEvent) {
339323
if (ReadSensorData() && _objectTemp != NAN) {
340-
// if the sensor was read recently, return the cached temperature
341324
tempEvent->temperature = _objectTemp;
342325
return true;
343326
}

0 commit comments

Comments
 (0)