From a75bfc18b11ee714f7034355c632adb130926b31 Mon Sep 17 00:00:00 2001 From: tyeth Date: Tue, 16 Apr 2024 18:31:21 +0100 Subject: [PATCH] Update VL53L4CD after PR feedback --- .../WipperSnapper_I2C_Driver_VL53L4CD.h | 86 ++----------------- 1 file changed, 6 insertions(+), 80 deletions(-) diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_VL53L4CD.h b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_VL53L4CD.h index d9269b3d7..f62180e7e 100644 --- a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_VL53L4CD.h +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_VL53L4CD.h @@ -52,67 +52,7 @@ class WipperSnapper_I2C_Driver_VL53L4CD : public WipperSnapper_I2C_Driver { // Status codes for VL53L4CD sensor measurements #define VL53L4CD_STATUS_VALID 0 ///< Returned distance is valid -#define VL53L4CD_STATUS_WARNING_SIGMA_THRESHOLD \ - 1 ///< Sigma is above the defined threshold -#define VL53L4CD_STATUS_WARNING_SIGNAL_LOW \ - 2 ///< Signal is below the defined threshold -#define VL53L4CD_STATUS_ERROR_DISTANCE_LOW \ - 3 ///< Measured distance is below detection threshold -#define VL53L4CD_STATUS_ERROR_PHASE_OUT_OF_LIMIT 4 ///< Phase out of valid limit -#define VL53L4CD_STATUS_ERROR_HARDWARE_FAIL 5 ///< Hardware failure -#define VL53L4CD_STATUS_WARNING_NO_WRAP_CHECK \ - 6 ///< Phase valid but no wrap around check performed -#define VL53L4CD_STATUS_ERROR_WRAP_TARGET \ - 7 ///< Wrapped target, phase does not match -#define VL53L4CD_STATUS_ERROR_PROCESSING_FAIL 8 ///< Processing failure -#define VL53L4CD_STATUS_ERROR_CROSSTALK_FAIL 9 ///< Crosstalk signal failure -#define VL53L4CD_STATUS_ERROR_INTERRUPT 10 ///< Interrupt error -#define VL53L4CD_STATUS_ERROR_MERGED_TARGET 11 ///< Merged target detected -#define VL53L4CD_STATUS_ERROR_SIGNAL_TOO_LOW \ - 12 ///< Signal is too low for accurate measurement -#define VL53L4CD_STATUS_ERROR_OTHER 255 ///< Other error (e.g., boot error) - /**************************************************************************/ - /*! - @brief Gets a human-readable description of a VL53L4CD status code. - @param statusCode - The status code to describe. - @returns A human-readable description of the status code. - */ - const char *getVL53L4CDStatusDescription(int statusCode) { - switch (statusCode) { - case VL53L4CD_STATUS_VALID: - return "Returned distance is valid"; - case VL53L4CD_STATUS_WARNING_SIGMA_THRESHOLD: - return "Sigma is above the defined threshold"; - case VL53L4CD_STATUS_WARNING_SIGNAL_LOW: - return "Signal is below the defined threshold"; - case VL53L4CD_STATUS_ERROR_DISTANCE_LOW: - return "Measured distance is below detection threshold"; - case VL53L4CD_STATUS_ERROR_PHASE_OUT_OF_LIMIT: - return "Phase out of valid limit"; - case VL53L4CD_STATUS_ERROR_HARDWARE_FAIL: - return "Hardware failure"; - case VL53L4CD_STATUS_WARNING_NO_WRAP_CHECK: - return "Phase valid but no wrap around check performed"; - case VL53L4CD_STATUS_ERROR_WRAP_TARGET: - return "Wrapped target, phase does not match"; - case VL53L4CD_STATUS_ERROR_PROCESSING_FAIL: - return "Processing failure"; - case VL53L4CD_STATUS_ERROR_CROSSTALK_FAIL: - return "Crosstalk signal failure"; - case VL53L4CD_STATUS_ERROR_INTERRUPT: - return "Interrupt error"; - case VL53L4CD_STATUS_ERROR_MERGED_TARGET: - return "Merged target detected"; - case VL53L4CD_STATUS_ERROR_SIGNAL_TOO_LOW: - return "Signal is too low for accurate measurement"; - case VL53L4CD_STATUS_ERROR_OTHER: - return "Other error (e.g., boot error)"; - default: - return "Unknown status"; - } - } /*******************************************************************************/ /*! @@ -123,14 +63,6 @@ class WipperSnapper_I2C_Driver_VL53L4CD : public WipperSnapper_I2C_Driver { bool begin() { _VL53L4CD = new VL53L4CD(_i2c, -1); - /* Reinstate if shutdown pin utilised - * // Configure VL53L4CD satellite component. - * _VL53L4CD->begin(); - * - * // Switch off VL53L4CD satellite component. - * _VL53L4CD->VL53L4CD_Off(); - */ - if (_VL53L4CD->InitSensor((uint8_t)_sensorAddress) != VL53L4CD_ERROR_NONE) { WS_DEBUG_PRINTLN("Failed to initialize VL53L4CD sensor!"); return false; @@ -150,10 +82,7 @@ class WipperSnapper_I2C_Driver_VL53L4CD : public WipperSnapper_I2C_Driver { WS_DEBUG_PRINTLN(signalThreshold); } if (_VL53L4CD->VL53L4CD_SetSignalThreshold(50) != VL53L4CD_ERROR_NONE) { - WS_DEBUG_PRINTLN("Failed to set VL53L4CD signal threshold!"); - } else { - WS_DEBUG_PRINT("VL53L4CD new signal threshold: "); - WS_DEBUG_PRINTLN(8); + WS_DEBUG_PRINTLN("Failed to set new VL53L4CD signal threshold!"); } uint16_t sigmaThreshold = -1; @@ -166,9 +95,6 @@ class WipperSnapper_I2C_Driver_VL53L4CD : public WipperSnapper_I2C_Driver { } if (_VL53L4CD->VL53L4CD_SetSigmaThreshold(100) != VL53L4CD_ERROR_NONE) { WS_DEBUG_PRINTLN("Failed to set VL53L4CD sigma threshold!"); - } else { - WS_DEBUG_PRINT("VL53L4CD new sigma threshold: "); - WS_DEBUG_PRINTLN(100); } if (_VL53L4CD->VL53L4CD_StartRanging() != VL53L4CD_ERROR_NONE) { @@ -196,10 +122,10 @@ class WipperSnapper_I2C_Driver_VL53L4CD : public WipperSnapper_I2C_Driver { WS_DEBUG_PRINT("Waiting for VL53L4CD data ready..."); delay(250); - for (uint8_t i = 0; + for (uint8_t retries = 0; (status = _VL53L4CD->VL53L4CD_CheckForDataReady(&NewDataReady)) && - !NewDataReady && i < 3; - i++) { + !NewDataReady && retries < 3; + retries++) { delay(300); WS_DEBUG_PRINT(" ."); } @@ -212,13 +138,13 @@ class WipperSnapper_I2C_Driver_VL53L4CD : public WipperSnapper_I2C_Driver { if (_VL53L4CD->VL53L4CD_GetResult(&results) == VL53L4CD_ERROR_NONE) { if (results.range_status != VL53L4CD_STATUS_VALID) { WS_DEBUG_PRINT("VL53L4CD range status: "); - WS_DEBUG_PRINTLN(getVL53L4CDStatusDescription(results.range_status)); + WS_DEBUG_PRINTLN(results.range_status); return false; } proximityEvent->data[0] = (float)results.distance_mm; return true; } - // TODO: Once I2C sensors fire all data points during a single call, we + // NOTE: Once I2C sensors fire all data points during a single call, we // can return the std deviation in MM for the measurements. See // https://github.com/stm32duino/VL53L4CD/blob/066664f983bcf70819133c7fcf43101035b09bab/src/vl53l4cd_api.h#L130-L131 } else {