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.
Diff: main.cpp
- Revision:
- 4:360dc34c3769
- Parent:
- 3:42c96c9c627b
- Child:
- 5:92a861d48253
--- a/main.cpp Tue May 04 09:39:21 2021 +0000 +++ b/main.cpp Fri May 07 14:41:08 2021 +0000 @@ -1,19 +1,26 @@ /* - * This VL53L3 Expansion board test application performs range measurements - * using the onboard embedded centre sensor, in singleshot, polling mode. - * Measured ranges are ouput on the Serial Port, running at 115200 baud. + * This VL53L3 Expansion board test application performs range measurements + * using the onboard embedded centre sensor, in singleshot, polling mode. + * Measured ranges are ouput on the Serial Port, running at 115200 baud. + * + * The User Blue button stops the current measurement and entire program, + * releasing all resources. * - * The User Blue button stops the current measurement and entire program, - * releasing all resources. + * The Reset button can be used to restart the program. * - * The Reset button can be used to restart the program. + * *** Note : + * Default Mbed build system settings disable print floating-point support. + * Offline builds can enable this, again. + * https://github.com/ARMmbed/mbed-os/blob/master/platform/source/minimal-printf/README.md + * .\mbed-os\platform\mbed_lib.json + * */ - //Main_interrupt_ranging.h #include <stdio.h> #include <time.h> #include "mbed.h" + #include "XNucleo53L3A2.h" #include "vl53L3_I2c.h" @@ -37,6 +44,7 @@ class WaitForMeasurement { + public: @@ -65,7 +73,6 @@ // function is called every time an interupt is seen. A flag is raised which allows the main routine to service the interupt. void got_interrupt() { - _count++; if (Devlocal->I2cDevAddr == NEW_SENSOR_CENTRE_ADDRESS) @@ -73,9 +80,7 @@ if (Devlocal->I2cDevAddr == NEW_SENSOR_LEFT_ADDRESS) int_left_result = 1; //flag to main that interrupt happened if (Devlocal->I2cDevAddr == NEW_SENSOR_RIGHT_ADDRESS) - { int_right_result = 1; //flag to main that interrupt happened - } } @@ -86,11 +91,11 @@ } private: + InterruptIn _interrupt; volatile int _count; VL53LX_DEV Devlocal; - int status; - + int status; }; @@ -124,8 +129,6 @@ vl53L3_DevI2C *dev_I2C = new vl53L3_DevI2C(I2C_SDA, I2C_SCL); - // printf("I2C device created! %d %d\r\n",dev_I2C,*dev_I2C); - /* creates the 53L1A1 expansion board singleton obj */ board = XNucleo53L3A2::instance(dev_I2C, A2, D8, D2); printf("board created!\r\n"); @@ -227,32 +230,30 @@ { VL53LX_MultiRangingData_t MultiRangingData; - VL53LX_MultiRangingData_t *pMultiRangingData = &MultiRangingData; + VL53LX_MultiRangingData_t *pMultiRangingData = &MultiRangingData; - wait_ms( 1 * 10); - // printf("interruptcount %d \n",interruptcount); + wait_ms(10); + if (int_centre_result != 0) { int_centre_result = 0; - // printf("int_centre_result \n"); status = board->sensor_centre->VL53LX_GetMultiRangingData( pMultiRangingData); int no_of_object_found=pMultiRangingData->NumberOfObjectsFound; -// printf("int_centre_result %d %d \n",no_of_object_found,status); if (( no_of_object_found < 10 ) && ( no_of_object_found != 0 )) { for(int j=0;j<no_of_object_found;j++){ if (pMultiRangingData->RangeData[j].RangeStatus == 0) { printf("centre\t status=%d, \t D=%5dmm, \t Signal=%2.2f Mcps, \t Ambient=%2.2f Mcps \n", - pMultiRangingData->RangeData[j].RangeStatus, - pMultiRangingData->RangeData[j].RangeMilliMeter, - pMultiRangingData->RangeData[j].SignalRateRtnMegaCps/65536.0, - pMultiRangingData->RangeData[j].AmbientRateRtnMegaCps/65536.0); + pMultiRangingData->RangeData[j].RangeStatus, + pMultiRangingData->RangeData[j].RangeMilliMeter, + (pMultiRangingData->RangeData[j].SignalRateRtnMegaCps/65535.0), + (pMultiRangingData->RangeData[j].AmbientRateRtnMegaCps/65535.0)); } } } int_centre_result = 0; - wait_ms( MEASUREMENTTIMING ); + wait_ms( MEASUREMENTTIMING ); status = board->sensor_centre->VL53LX_ClearInterruptAndStartMeasurement(); } @@ -260,31 +261,26 @@ if (int_left_result != 0) { int_left_result = 0; -// printf("int_left_result \n"); status = board->sensor_left->VL53LX_GetMultiRangingData( pMultiRangingData); - // printf("int_left_result status %d \n",status); if ( status == 0) { int no_of_object_found=pMultiRangingData->NumberOfObjectsFound; - // printf("int_left_result %d %d \n",no_of_object_found,status); if (( no_of_object_found < 10 ) && ( no_of_object_found != 0 )) { for(int j=0;j<no_of_object_found;j++){ if (pMultiRangingData->RangeData[j].RangeStatus == 0) { - printf("left \t status=%d, \t D=%5dmm, \t Signal=%2.2f Mcps, \t Ambient=%2.2f Mcps \n", - pMultiRangingData->RangeData[j].RangeStatus, - pMultiRangingData->RangeData[j].RangeMilliMeter, - pMultiRangingData->RangeData[j].SignalRateRtnMegaCps/65536.0, - pMultiRangingData->RangeData[j].AmbientRateRtnMegaCps/65536.0); + pMultiRangingData->RangeData[j].RangeStatus, + pMultiRangingData->RangeData[j].RangeMilliMeter, + (pMultiRangingData->RangeData[j].SignalRateRtnMegaCps / 65535.0), + (pMultiRangingData->RangeData[j].AmbientRateRtnMegaCps / 65535.0) ); } } } } - wait_ms( MEASUREMENTTIMING ); + wait_ms( MEASUREMENTTIMING ); status = board->sensor_left->VL53LX_ClearInterruptAndStartMeasurement(); - } @@ -292,51 +288,30 @@ { // clear interrupt flag int_right_result = 0; - // printf("int_right_result \n"); status = board->sensor_right->VL53LX_GetMultiRangingData( pMultiRangingData); if ( status == 0) { - // printf("int_right_result status %d \n",status); // if valid result print it int no_of_object_found=pMultiRangingData->NumberOfObjectsFound; - // printf("int_right_result %d %d \n",no_of_object_found,status); if (( no_of_object_found < 10 ) && ( no_of_object_found != 0 )) { for(int j=0;j<no_of_object_found;j++){ if (pMultiRangingData->RangeData[j].RangeStatus == 0) { -// if(j!=0)printf("\n 0 "); printf("right \t status=%d, \t D=%5dmm, \t Signal=%2.2f Mcps, \t Ambient=%2.2f Mcps \n", - pMultiRangingData->RangeData[j].RangeStatus, - pMultiRangingData->RangeData[j].RangeMilliMeter, - pMultiRangingData->RangeData[j].SignalRateRtnMegaCps/65536.0, - pMultiRangingData->RangeData[j].AmbientRateRtnMegaCps/65536.0); + pMultiRangingData->RangeData[j].RangeStatus, + pMultiRangingData->RangeData[j].RangeMilliMeter, + (pMultiRangingData->RangeData[j].SignalRateRtnMegaCps/65535.0), + (pMultiRangingData->RangeData[j].AmbientRateRtnMegaCps/65535.0) ); } } } } - wait_ms( MEASUREMENTTIMING ); + wait_ms( MEASUREMENTTIMING ); // clear theinterrupt and wait for another result status = board->sensor_right->VL53LX_ClearInterruptAndStartMeasurement(); } - /* - if ( interruptcount > 10000) - { - printf("interruptcount exceeded \n"); - int_left_result = 0; - int_centre_result = 0; - int_right_result = 0; - if (board->sensor_centre!= NULL ) - status = board->sensor_centre->VL53LX_ClearInterruptAndStartMeasurement(); - if (board->sensor_left!= NULL ) - status = board->sensor_left->VL53LX_ClearInterruptAndStartMeasurement(); - if (board->sensor_right!= NULL ) - status = board->sensor_right->VL53LX_ClearInterruptAndStartMeasurement(); - interruptcount = 0; - } - */ - } printf("terminated"); }