Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed vl53l0x_api
Fork of VL53L0X_Continuous_Ranging_Example by
Diff: main.cpp
- Revision:
- 2:32f0f47a19f2
- Parent:
- 0:b6867e1a23fa
--- a/main.cpp Tue Aug 23 05:19:55 2016 +0000 +++ b/main.cpp Wed Feb 15 15:46:04 2017 +0000 @@ -3,12 +3,17 @@ #include "vl53l0x_platform.h" #include "vl53l0x_i2c_platform.h" -Serial pc(SERIAL_TX, SERIAL_RX); + +/////////////////////////////////////////////////////////////////////////////// + //Example program for continuous ranging// +/////////////////////////////////////////////////////////////////////////////// + +Serial pc(USBTX, USBRX); void print_pal_error(VL53L0X_Error Status){ char buf[VL53L0X_MAX_STRING_LENGTH]; VL53L0X_GetPalErrorString(Status, buf); - printf("API Status: %i : %s\n", Status, buf); + printf("API Status: %i : %s\r\n", Status, buf); } void print_range_status(VL53L0X_RangingMeasurementData_t* pRangingMeasurementData){ @@ -22,7 +27,7 @@ RangeStatus = pRangingMeasurementData->RangeStatus; VL53L0X_GetRangeStatusString(RangeStatus, buf); - printf("Range Status: %i : %s\n", RangeStatus, buf); + printf("Range Status: %i : %s\r\n", RangeStatus, buf); } @@ -93,7 +98,7 @@ int32_t status_int; - pc.printf("VL53L0X API Simple Ranging Example\r\n"); + pc.printf("VL53L0X API Continuous Ranging Example\r\n"); // Initialize Comms pMyDevice->I2cDevAddr = 0x52; @@ -113,15 +118,16 @@ int addr; addr = VL53L0X_scan(); + //addr = 0x52; printf("Device found at: %i\r\n", addr); //uint8_t data; //data=0; if(Status == VL53L0X_ERROR_NONE) { - printf ("Call of VL53L0X_DataInit\n"); + printf ("Call of VL53L0X_DataInit\r\n"); uint16_t osc_calibrate_val=0; Status = VL53L0X_RdWord(&MyDevice, VL53L0X_REG_OSC_CALIBRATE_VAL,&osc_calibrate_val); - printf("%i\n",osc_calibrate_val); + printf("%i\r\n",osc_calibrate_val); Status = VL53L0X_DataInit(&MyDevice); // Data initialization print_pal_error(Status); } @@ -131,15 +137,15 @@ Status = VL53L0X_GetDeviceInfo(&MyDevice, &DeviceInfo); if(Status == VL53L0X_ERROR_NONE) { - printf("VL53L0X_GetDeviceInfo:\n"); + printf("VL53L0X_GetDeviceInfo:\r\n"); printf("Device Name : %s\n", DeviceInfo.Name); printf("Device Type : %s\n", DeviceInfo.Type); printf("Device ID : %s\n", DeviceInfo.ProductId); printf("ProductRevisionMajor : %d\n", DeviceInfo.ProductRevisionMajor); - printf("ProductRevisionMinor : %d\n", DeviceInfo.ProductRevisionMinor); + printf("ProductRevisionMinor : %d\r\n", DeviceInfo.ProductRevisionMinor); if ((DeviceInfo.ProductRevisionMinor != 1) && (DeviceInfo.ProductRevisionMinor != 1)) { - printf("Error expected cut 1.1 but found cut %d.%d\n", + printf("Error expected cut 1.1 but found cut %d.%d\r\n", DeviceInfo.ProductRevisionMajor, DeviceInfo.ProductRevisionMinor); Status = VL53L0X_ERROR_NOT_SUPPORTED; } @@ -157,7 +163,7 @@ if(Status == VL53L0X_ERROR_NONE) { - printf ("Call of VL53L0X_StaticInit\n"); + printf ("Call of VL53L0X_StaticInit\r\n"); Status = VL53L0X_StaticInit(pMyDevice); // Device Initialization // StaticInit will set interrupt by default print_pal_error(Status); @@ -165,7 +171,7 @@ if(Status == VL53L0X_ERROR_NONE) { - printf ("Call of VL53L0X_PerformRefCalibration\n"); + printf ("Call of VL53L0X_PerformRefCalibration\r\n"); Status = VL53L0X_PerformRefCalibration(pMyDevice, &VhvSettings, &PhaseCal); // Device Initialization print_pal_error(Status); @@ -173,7 +179,7 @@ if(Status == VL53L0X_ERROR_NONE) { - printf ("Call of VL53L0X_PerformRefSpadManagement\n"); + printf ("Call of VL53L0X_PerformRefSpadManagement\r\n"); Status = VL53L0X_PerformRefSpadManagement(pMyDevice, &refSpadCount, &isApertureSpads); // Device Initialization print_pal_error(Status); @@ -182,18 +188,19 @@ if(Status == VL53L0X_ERROR_NONE) { - printf ("Call of VL53L0X_SetDeviceMode\n"); - Status = VL53L0X_SetDeviceMode(pMyDevice, VL53L0X_DEVICEMODE_CONTINUOUS_RANGING); // Setup in single ranging mode + printf ("Call of VL53L0X_SetDeviceMode\r\n"); + Status = VL53L0X_SetDeviceMode(pMyDevice, VL53L0X_DEVICEMODE_CONTINUOUS_RANGING); // Setup in continuous ranging print_pal_error(Status); } if(Status == VL53L0X_ERROR_NONE) { - printf ("Call of VL53L0X_StartMeasurement\n"); + printf ("Call of VL53L0X_StartMeasurement\r\n"); Status = VL53L0X_StartMeasurement(pMyDevice); print_pal_error(Status); } + while(1){ if(Status == VL53L0X_ERROR_NONE) { uint32_t measurement; @@ -211,7 +218,7 @@ Status = VL53L0X_GetRangingMeasurementData(pMyDevice, pRangingMeasurementData); *(pResults + measurement) = pRangingMeasurementData->RangeMilliMeter; - printf("In loop measurement %lu: %d\n", measurement, pRangingMeasurementData->RangeMilliMeter); + printf("In loop measurement %lu: %d\r\n", measurement, pRangingMeasurementData->RangeMilliMeter); // Clear the interrupt VL53L0X_ClearInterruptMask(pMyDevice, VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY); @@ -220,28 +227,30 @@ break; } } - + /* if(Status == VL53L0X_ERROR_NONE) { for(measurement=0; measurement<no_of_measurements; measurement++) { - printf("measurement %lu: %d\n", measurement, *(pResults + measurement)); + printf("measurement %lu: %d\r\n", measurement, *(pResults + measurement)); } } - + */ free(pResults); } + } +/* if(Status == VL53L0X_ERROR_NONE) { - printf ("Call of VL53L0X_StopMeasurement\n"); + printf ("Call of VL53L0X_StopMeasurement\r\n"); Status = VL53L0X_StopMeasurement(pMyDevice); } if(Status == VL53L0X_ERROR_NONE) { - printf ("Wait Stop to be competed\n"); + printf ("Wait for stop to be competed\r\n"); Status = WaitStopCompleted(pMyDevice); } @@ -251,5 +260,7 @@ while (true) if (pc.readable()) pc.putc(pc.getc()); + +*/ }