refine sensor detection logic

This commit is contained in:
Yunhorn 2024-05-29 12:45:30 +08:00
parent f056688dae
commit de8886488c
4 changed files with 273 additions and 275 deletions

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -20,7 +20,7 @@
/** @ingroup VL53L0X_config
* @{*/
#define MAX_TOF_COUNT 2
#define MAX_TOF_COUNT 3
#ifndef VL53L0X_HAVE_UART
/**
@ -119,7 +119,7 @@ extern void XNUCLEO53L1A1_USART2_UART_Init(void);
* Must be set to non 0 for shared interrupt line
* see @sa VL53L0X_GPIO1_C_OPTION
*/
#define VL53L0X_GPIO1_SHARED 0
#define VL53L0X_GPIO1_SHARED 1
#endif

View File

@ -161,7 +161,7 @@ int sts_tof_vl53l0x_DetectSensors(void)
do {
/* Set I2C standard mode (400 KHz) before doing the first register access */
//if (status == VL53L0X_ERROR_NONE)
status = VL53L0X_WrByte(pDev, 0x88, 0x00);
//status = VL53L0X_WrByte(pDev, 0x88, 0x00);
/* Try to read one register using default 0x52 address */
status = VL53L0X_RdWord(pDev, VL53L0X_REG_IDENTIFICATION_MODEL_ID, &Id);
@ -180,26 +180,24 @@ int sts_tof_vl53l0x_DetectSensors(void)
pDev->I2cDevAddr = FinalAddress;
/* Check all is OK with the new I2C address and initialize the sensor */
status = VL53L0X_RdWord(pDev, VL53L0X_REG_IDENTIFICATION_MODEL_ID, &Id);
if (status !=0)
{
APP_LOG(TS_OFF, VLEVEL_H, "#i VL53L0X_RdWord fail\r\n");
break;
}
// if (status !=0)
//{
// APP_LOG(TS_OFF, VLEVEL_H, "#i VL53L0X_RdWord fail\r\n");
//break;
//}
status = VL53L0X_DataInit(pDev);
if( status == 0 ){
pDev->Present = 1;
//APP_LOG(TS_OFF, VLEVEL_H, "#%u VL53L0X_SetDeviceAddress to 0x%02x\r\n",i, pDev->I2cDevAddr);
nDevPresent++;
nDevMask |= 1 << i;
pDev->Present = 1;
APP_LOG(TS_OFF, VLEVEL_H, "VL53L0X %d Present and initiated to final 0x%2x, Position Mask=0x%02x\r\n", pDev->Id, pDev->I2cDevAddr, nDevMask);
}
else{
APP_LOG(TS_OFF, VLEVEL_H, "VL53L0X_DataInit %d fail\r\n", Id);
break;
}
nDevPresent++;
nDevMask |= 1 << i;
pDev->Present = 1;
APP_LOG(TS_OFF, VLEVEL_H, "VL53L0X %d Present and initiated to final 0x%2x, Position Mask=0x%02x\r\n", pDev->Id, pDev->I2cDevAddr, nDevMask);
} else {
APP_LOG(TS_OFF, VLEVEL_H, "# unknown ID %x\r\n", Id);