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 X_NUCLEO_53L1A1_mbed
Diff: main.cpp
- Revision:
- 19:27f341756cb6
- Parent:
- 17:e7a6fd6d3c97
- Child:
- 20:639c4cbcfad9
--- a/main.cpp Fri May 17 09:49:47 2019 +0000 +++ b/main.cpp Thu May 23 12:01:43 2019 +0000 @@ -2,7 +2,7 @@ * This VL53L1X Expansion board test application performs range measurements * using the onboard embedded centre sensor. * - * Measured ranges are ouput on the Serial Port, running at 115200 baud. + * Measured ranges are ouput on the Serial Port, running at 96000 baud. * * The User Blue button stops the current measurement and entire program, * releasing all resources. @@ -36,14 +36,23 @@ #define VL53L1_I2C_SCL D15 static XNucleo53L1A1 *board=NULL; +Serial pc(SERIAL_TX, SERIAL_RX); -Serial pc(SERIAL_TX, SERIAL_RX); +volatile bool polling_stop = false; + +void stop_polling(void) +{ + polling_stop = true; +} /*=================================== Main ================================== =============================================================================*/ int main() { - +#if USER_BUTTON==PC_13 // we are cross compiling for Nucleo-f401 + InterruptIn stop_button(USER_BUTTON); + stop_button.rise(&stop_polling); +#endif int status = 0; uint8_t ready_centre = 0; uint8_t ready_left = 0; @@ -64,7 +73,7 @@ /* init the 53L1A1 expansion board with default values */ status = board->init_board(); - if (status != 0) { + if (status) { printf("Failed to init board!\r\n"); return status; } @@ -72,24 +81,30 @@ printf("board initiated! - %d\r\n", status); /* Start ranging on the centre sensor */ - status = board->sensor_centre->VL53L1X_StartRanging(); - if (status != 0) { - printf("Centre sensor failed to start ranging!\r\n"); - return status; + if (board->sensor_centre != NULL) { + status = board->sensor_centre->VL53L1X_StartRanging(); + if (status != 0) { + printf("Centre sensor failed to start ranging!\r\n"); + return status; + } } /* Start ranging on the left sensor */ - status = board->sensor_left->VL53L1X_StartRanging(); - if (status != 0) { - printf("Left sensor failed to start ranging!\r\n"); - return status; + if (board->sensor_left != NULL) { + status = board->sensor_left->VL53L1X_StartRanging(); + if (status != 0) { + printf("Left sensor failed to start ranging!\r\n"); + return status; + } } /* Start ranging on the right sensor */ - status = board->sensor_right->VL53L1X_StartRanging(); - if (status != 0) { - printf("Right sensor failed to start ranging!\r\n"); - return status; + if (board->sensor_right != NULL) { + status = board->sensor_right->VL53L1X_StartRanging(); + if (status != 0) { + printf("Right sensor failed to start ranging!\r\n"); + return status; + } } /* Ranging loop @@ -97,10 +112,20 @@ */ while (1) { - board->sensor_centre->VL53L1X_CheckForDataReady(&ready_centre); - board->sensor_left->VL53L1X_CheckForDataReady(&ready_left); - board->sensor_right->VL53L1X_CheckForDataReady(&ready_right); - + if (polling_stop) + { + printf("\r\nEnding loop mode \r\n"); + break; + } + if (board->sensor_centre != NULL) { + board->sensor_centre->VL53L1X_CheckForDataReady(&ready_centre); + } + if (board->sensor_left != NULL) { + board->sensor_left->VL53L1X_CheckForDataReady(&ready_left); + } + if (board->sensor_right != NULL) { + board->sensor_right->VL53L1X_CheckForDataReady(&ready_right); + } if (ready_centre) { board->sensor_centre->VL53L1X_GetRangeStatus(&ready_centre); board->sensor_centre->VL53L1X_GetDistance(&distance_centre); @@ -114,9 +139,15 @@ board->sensor_centre->VL53L1X_GetDistance(&distance_right); } - printf("%d\t", distance_centre); - printf("%d\t", distance_left); - printf("%d\t", distance_right); + if (board->sensor_centre != NULL) { + printf("%d\t", distance_centre); + } + if (board->sensor_left != NULL) { + printf("%d\t", distance_left); + } + if (board->sensor_right != NULL) { + printf("%d\t", distance_right); + } } return status;