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:
- 6:4bc839979c55
- Parent:
- 5:92a861d48253
- Child:
- 7:bd1ddfbee3ef
--- a/main.cpp Fri May 07 14:46:18 2021 +0000 +++ b/main.cpp Fri May 07 15:51:29 2021 +0000 @@ -1,6 +1,6 @@ /* * This VL53L3 Expansion board test application performs range measurements - * using the onboard embedded centre sensor, in singleshot, polling mode. + * using the onboard embedded centre sensor, in interrupt mode. * Measured ranges are ouput on the Serial Port, running at 115200 baud. * * The User Blue button stops the current measurement and entire program, @@ -101,10 +101,10 @@ -VL53LX_Dev_t devCentre; -VL53LX_Dev_t devLeft; -VL53LX_Dev_t devRight; -VL53LX_DEV Dev = &devCentre; +VL53LX_Dev_t devCentre; +VL53LX_Dev_t devLeft; +VL53LX_Dev_t devRight; +VL53LX_DEV Dev = &devCentre; @@ -120,9 +120,7 @@ uint8_t ToFSensor = 1; // 0=Left, 1=Center(default), 2=Right - WaitForMeasurement* int2; WaitForMeasurement* int1; - WaitForMeasurement* int3; pc.baud(115200); // baud rate is important as printf statements take a lot of time @@ -154,20 +152,6 @@ Dev->I2cDevAddr = NEW_SENSOR_CENTRE_ADDRESS; printf("configuring centre channel \n"); break; - case 1: - if (board->sensor_left== NULL ) continue; - Dev=&devLeft; - Sensor=board->sensor_left; - Dev->I2cDevAddr = NEW_SENSOR_LEFT_ADDRESS; - printf("configuring left channel \n"); - break; - case 2: - if (board->sensor_right== NULL ) continue; - Dev=&devRight; - Sensor=board->sensor_right; - Dev->I2cDevAddr = NEW_SENSOR_RIGHT_ADDRESS; - printf("configuring right channel \n"); - break; default: printf(" error in switch, invalid ToF sensor \n"); } @@ -187,7 +171,6 @@ status = Sensor->VL53LX_SmudgeCorrectionEnable(VL53LX_SMUDGE_CORRECTION_SINGLE); status = Sensor->VL53LX_SetXTalkCompensationEnable(1); - } if (board->sensor_centre!= NULL ) { @@ -200,28 +183,6 @@ status = board->sensor_centre->VL53LX_ClearInterruptAndStartMeasurement(); } - - if (board->sensor_left!= NULL ) { - printf("starting interrupt left\n"); - Sensor=board->sensor_left; - devLeft.I2cDevAddr = NEW_SENSOR_LEFT_ADDRESS; - int2 = new WaitForMeasurement(D8,&devLeft); - status = Sensor->VL53LX_StartMeasurement(); - printf("VL53L1_StartMeasurement %d \n",status); - status = board->sensor_left->VL53LX_ClearInterruptAndStartMeasurement(); - } - - if (board->sensor_right!= NULL ) { - printf("starting interrupt right\n"); - Sensor=board->sensor_right; - devRight.I2cDevAddr = NEW_SENSOR_RIGHT_ADDRESS; - int3 = new WaitForMeasurement(D2,&devRight); - status = Sensor->VL53LX_StartMeasurement(); - printf("VL53L1_StartMeasurement %d \n",status); - status = board->sensor_right->VL53LX_ClearInterruptAndStartMeasurement(); - } - - // loop waiting for interrupts to happen. This is signaled by int_centre_result,int_left_result or int_right_result // being non zero. The are set back to zero when processing is completed while (1) { @@ -251,61 +212,12 @@ status = board->sensor_centre->VL53LX_ClearInterruptAndStartMeasurement(); } - - if (int_left_result != 0) { - int_left_result = 0; - status = board->sensor_left->VL53LX_GetMultiRangingData( pMultiRangingData); - if ( status == 0) { - int no_of_object_found=pMultiRangingData->NumberOfObjectsFound; - 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 / 65535.0), - (pMultiRangingData->RangeData[j].AmbientRateRtnMegaCps / 65535.0) ); - } - } - } - } - wait_ms( MEASUREMENTTIMING ); - status = board->sensor_left->VL53LX_ClearInterruptAndStartMeasurement(); - } - - - if (int_right_result != 0) { - // clear interrupt flag - int_right_result = 0; - status = board->sensor_right->VL53LX_GetMultiRangingData( pMultiRangingData); - if ( status == 0) { - // if valid result print it - int no_of_object_found=pMultiRangingData->NumberOfObjectsFound; - 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("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/65535.0), - (pMultiRangingData->RangeData[j].AmbientRateRtnMegaCps/65535.0) ); - } - } - } - } - wait_ms( MEASUREMENTTIMING ); - // clear theinterrupt and wait for another result - status = board->sensor_right->VL53LX_ClearInterruptAndStartMeasurement(); - - } + printf("terminated"); } - printf("terminated"); } #if (MBED_VERSION > 60300) -extern "C" void wait_ms(int ms) -{ - thread_sleep_for(ms); -} + extern "C" void wait_ms(int ms) { + thread_sleep_for(ms); + } #endif - \ No newline at end of file