//打印错误
void print_pal_error(VL53L0X_Error Status)
{
char buf[VL53L0X_MAX_STRING_LENGTH];
VL53L0X_GetPalErrorString(Status, buf);
OLED_printf(0,0,font_6x8,"API Status: %i : %s\n", Status, buf);
}
VL53L0X_Error vl53l0x_init(void)
{
VL53L0X_Error Status = VL53L0X_ERROR_NONE;
VL53L0X_Dev_t *pMyDevice = &vl53l0x_dev;
pMyDevice->I2cDevAddr = 0x52;
pMyDevice->comms_type = 1;
pMyDevice->comms_speed_khz = 400;
VL53L0X_i2c_init();
Status = VL53L0X_DataInit(pMyDevice); // Data initialization
if(Status != VL53L0X_ERROR_NONE){
print_pal_error(Status);
return Status;
}
Status = VL53L0X_GetDeviceInfo(pMyDevice, &vl53l0x_dev_info);
if(Status != VL53L0X_ERROR_NONE){
print_pal_error(Status);
return Status;
}
//OLED_printf(0,0,font_6x8,"VL53L0X_GetDeviceInfo:\n");
//OLED_printf(0,1,font_6x8,"Device Name : %s\n", vl53l0x_dev_info.Name);
//OLED_printf(0,2,font_6x8,"Device Type : %s\n", vl53l0x_dev_info.Type);
//OLED_printf(0,3,font_6x8,"Device ID : %s\n", vl53l0x_dev_info.ProductId);
//OLED_printf(0,4,font_6x8,"ProductRevisionMajor : %d\n", vl53l0x_dev_info.ProductRevisionMajor);
//OLED_printf(0,5,font_6x8,"ProductRevisionMinor : %d\n", vl53l0x_dev_info.ProductRevisionMinor);
if ((vl53l0x_dev_info.ProductRevisionMajor != 1) && (vl53l0x_dev_info.ProductRevisionMinor != 1)){
OLED_printf(0,0,font_6x8,"Error expected cut 1.1 but found cut %d.%d\n",vl53l0x_dev_info.ProductRevisionMajor, vl53l0x_dev_info.ProductRevisionMinor);
Status = VL53L0X_ERROR_NOT_SUPPORTED;
print_pal_error(Status);
return Status;
}
Status = vl53l0x_measure_init(pMyDevice);
vl53l0x_status = Status;
if(Status != VL53L0X_ERROR_NONE){
print_pal_error(Status);
return Status;
}
|