Jenhao Ou
/
Nucleo_53l0x
Try to work but compile time error
main.cpp
- Committer:
- oldmon
- Date:
- 2018-06-24
- Revision:
- 0:4879420eb6e3
File content as of revision 0:4879420eb6e3:
#include "mbed.h" #include "VL53L0X.h" #define USE_I2C_2V8 Serial pc(USBTX, USBRX); DigitalOut shutdown_pin(D4); DevI2C i2c(I2C_SDA, I2C_SCL); VL53L0X sensor(&i2c,&shutdown_pin,NC); void print_pal_error(VL53L0X_Error Status){ char buf[VL53L0X_MAX_STRING_LENGTH]; sensor.VL53L0X_get_pal_error_string(Status, buf); pc.printf("API Status: %i : %s\n", Status, buf); } void print_range_status(VL53L0X_RangingMeasurementData_t* pRangingMeasurementData){ char buf[VL53L0X_MAX_STRING_LENGTH]; uint8_t RangeStatus; /* * New Range Status: data is valid when pRangingMeasurementData->RangeStatus = 0 */ RangeStatus = pRangingMeasurementData->RangeStatus; sensor.VL53L0X_get_range_status_string(RangeStatus, buf); pc.printf("Range Status: %i : %s\n", RangeStatus, buf); } VL53L0X_Error rangingTest(VL53L0X_Dev_t *pMyDevice){ VL53L0X_Error Status = VL53L0X_ERROR_NONE; VL53L0X_RangingMeasurementData_t RangingMeasurementData; int i; FixPoint1616_t LimitCheckCurrent; uint32_t refSpadCount; uint8_t isApertureSpads; uint8_t VhvSettings; uint8_t PhaseCal; if(Status == VL53L0X_ERROR_NONE){ pc.printf ("Call of VL53L0X_StaticInit\n"); Status = sensor.VL53L0X_static_init(pMyDevice); // Device Initialization print_pal_error(Status); } if(Status == VL53L0X_ERROR_NONE){ pc.printf ("Call of VL53L0X_PerformRefCalibration\n"); Status = sensor.VL53L0X_perform_ref_calibration(pMyDevice, &VhvSettings, &PhaseCal); // Device Initialization print_pal_error(Status); } if(Status == VL53L0X_ERROR_NONE){ pc.printf ("Call of VL53L0X_PerformRefSpadManagement\n"); Status = sensor.VL53L0X_perform_ref_spad_management(pMyDevice, &refSpadCount, &isApertureSpads); // Device Initialization pc.printf ("refSpadCount = %d, isApertureSpads = %d\n", refSpadCount, isApertureSpads); print_pal_error(Status); } if(Status == VL53L0X_ERROR_NONE){ // no need to do this when we use VL53L0X_PerformSingleRangingMeasurement pc.printf ("Call of VL53L0X_SetDeviceMode\n"); Status = sensor.VL53L0X_set_device_mode(pMyDevice, VL53L0X_DEVICEMODE_SINGLE_RANGING); // Setup in single ranging mode print_pal_error(Status); } // Enable/Disable Sigma and Signal check if (Status == VL53L0X_ERROR_NONE){ Status = sensor.VL53L0X_set_limit_check_enable(pMyDevice, VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE, 1); } if (Status == VL53L0X_ERROR_NONE){ Status = sensor.VL53L0X_set_limit_check_enable(pMyDevice, VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE, 1); } if (Status == VL53L0X_ERROR_NONE){ Status = sensor.VL53L0X_set_limit_check_enable(pMyDevice, VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD, 1); } if (Status == VL53L0X_ERROR_NONE){ Status = sensor.VL53L0X_set_limit_check_value(pMyDevice, VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD, (FixPoint1616_t)(1.5*0.023*65536)); } /* * Step 4 : Test ranging mode */ if(Status == VL53L0X_ERROR_NONE){ for(i=0;i<10;i++){ pc.printf ("Call of VL53L0X_PerformSingleRangingMeasurement\n"); Status = sensor.VL53L0X_perform_single_ranging_measurement(pMyDevice, &RangingMeasurementData); print_pal_error(Status); print_range_status(&RangingMeasurementData); sensor.VL53L0X_get_limit_check_current(pMyDevice, VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD, &LimitCheckCurrent); pc.printf("RANGE IGNORE THRESHOLD: %f\n\n", (double)LimitCheckCurrent/65536.0); if (Status != VL53L0X_ERROR_NONE) break; pc.printf("Measured distance: %i\n\n", RangingMeasurementData.RangeMilliMeter); } } return Status; } int main(){ VL53L0X_Error Status = VL53L0X_ERROR_NONE; VL53L0X_Dev_t MyDevice; VL53L0X_Dev_t *pMyDevice = &MyDevice; VL53L0X_Version_t Version; VL53L0X_Version_t *pVersion = &Version; VL53L0X_DeviceInfo_t DeviceInfo; int32_t status_int; //int32_t init_done = 0; pc.printf ("VL53L0X API Simple Ranging example\n\n"); /* * Disable VL53L0X API logging if you want to run at full speed */ #ifdef VL53L0X_LOG_ENABLE VL53L0X_trace_config("test.log", TRACE_MODULE_ALL, TRACE_LEVEL_ALL, TRACE_FUNCTION_ALL); #endif /* * Get the version of the VL53L0X API running in the firmware */ if(Status == VL53L0X_ERROR_NONE){ status_int = sensor.VL53L0X_get_version(pVersion); if (status_int != 0) Status = VL53L0X_ERROR_CONTROL_INTERFACE; } /* * Verify the version of the VL53L0X API running in the firmware */ if(Status == VL53L0X_ERROR_NONE) { pc.printf ("Call of VL53L0X_DataInit\n"); Status = sensor.VL53L0X_data_init(&MyDevice); // Data initialization print_pal_error(Status); } if(Status == VL53L0X_ERROR_NONE){ Status = sensor.VL53L0X_get_device_info(&MyDevice, &DeviceInfo); if(Status == VL53L0X_ERROR_NONE){ pc.printf("VL53L0X_GetDeviceInfo:\n"); pc.printf("Device Name : %s\n", DeviceInfo.Name); pc.printf("Device Type : %s\n", DeviceInfo.Type); pc.printf("Device ID : %s\n", DeviceInfo.ProductId); pc.printf("ProductRevisionMajor : %d\n", DeviceInfo.ProductRevisionMajor); pc.printf("ProductRevisionMinor : %d\n", DeviceInfo.ProductRevisionMinor); if ((DeviceInfo.ProductRevisionMinor != 1) && (DeviceInfo.ProductRevisionMinor != 1)) { pc.printf("Error expected cut 1.1 but found cut %d.%d\n", DeviceInfo.ProductRevisionMajor, DeviceInfo.ProductRevisionMinor); Status = VL53L0X_ERROR_NOT_SUPPORTED; } } print_pal_error(Status); } if(Status == VL53L0X_ERROR_NONE) Status = rangingTest(pMyDevice); print_pal_error(Status); // Implementation specific /* * Disconnect comms - part of VL53L0X_platform.c */ /*if(init_done == 0){ pc.printf ("Close Comms\n"); status_int = VL53L0X_comms_close(); if (status_int != 0) Status = VL53L0X_ERROR_CONTROL_INTERFACE; }*/ print_pal_error(Status); // printf ("\nPress a Key to continue!"); // getchar(); return (0); }