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.
Revision 4:396e4d72f19e, committed 2021-05-13
- Comitter:
- johnAlexander
- Date:
- Thu May 13 10:57:15 2021 +0000
- Parent:
- 3:09f23aad108a
- Commit message:
- debug trials.
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu May 13 08:31:52 2021 +0000
+++ b/main.cpp Thu May 13 10:57:15 2021 +0000
@@ -73,7 +73,7 @@
InterruptIn stop_button(SW2);
#endif
-void process_interrupt( VL53L1 * sensor,VL53L1_DEV dev );
+//void process_interrupt( VL53L1 * sensor,VL53L1_DEV dev );
void print_results( int devSpiNumber, VL53L1_MultiRangingData_t *pMultiRangingData );
@@ -146,46 +146,54 @@
if (centerSensor) {
centerSensor = false;
+ // get the result
+ status = board->sensor_centre->vl53L1_GetMultiRangingData(pMultiRangingData);
status = board->sensor_centre->VL53L1_GetDistance(&distance);
current = (currentSensor == 0);
if (current) {
+ print_results(devCentre.i2c_slave_address, pMultiRangingData );
printf("Centre: %d\r\n", distance);
- }
-
+ }
+// status = board->sensor_centre->vl53L1_ClearInterruptAndStartMeasurement();
status = board->sensor_centre->VL53L1_ClearInterrupt();
board->sensor_centre->enable_interrupt_measure_detection_irq();
-
}
/* Handle the interrupt and output the range from the left sensor */
if (leftSensor) {
leftSensor = false;
+ // get the result
+ status = board->sensor_left->vl53L1_GetMultiRangingData(pMultiRangingData);
status = board->sensor_left->VL53L1_GetDistance(&distance);
current = (installedSensors[currentSensor] == 'L');
if (current) {
+ print_results(devLeft.i2c_slave_address, pMultiRangingData );
printf("Left: %d\r\n", distance);
- }
+ }
+// status = board->sensor_left->vl53L1_ClearInterruptAndStartMeasurement();
status = board->sensor_left->VL53L1_ClearInterrupt();
board->sensor_left->enable_interrupt_measure_detection_irq();
-
}
/* Handle the interrupt and output the range from the right sensor */
if (rightSensor) {
rightSensor = false;
+ // get the result
+ status = board->sensor_right->vl53L1_GetMultiRangingData(pMultiRangingData);
status = board->sensor_right->VL53L1_GetDistance(&distance);
current = (installedSensors[currentSensor] == 'R');
if (current) {
+ print_results(devRight.i2c_slave_address, pMultiRangingData );
printf("Right: %d\r\n", distance);
}
+// status = board->sensor_right->vl53L1_ClearInterruptAndStartMeasurement();
status = board->sensor_right->VL53L1_ClearInterrupt();
board->sensor_right->enable_interrupt_measure_detection_irq();
-
}
}
@@ -193,11 +201,6 @@
{
int status = 0;
-// Device Initialization and setting
- status = Sensor->vl53L1_DataInit();
- status = Sensor->vl53L1_StaticInit();
- status = Sensor->vl53L1_SetPresetMode( VL53L1_PRESETMODE_MULTIZONES_SCANNING);
-
//configure the regions of interest for each sensor
VL53L1_RoiConfig_t roiConfig;
@@ -206,17 +209,25 @@
roiConfig.UserRois[0].TopLeftY = 9;
roiConfig.UserRois[0].BotRightX = 4;
roiConfig.UserRois[0].BotRightY = 5;
+
roiConfig.UserRois[1].TopLeftX = 5;
roiConfig.UserRois[1].TopLeftY = 9;
roiConfig.UserRois[1].BotRightX = 9;
roiConfig.UserRois[1].BotRightY = 4;
+
roiConfig.UserRois[2].TopLeftX = 11;
roiConfig.UserRois[2].TopLeftY = 9;
roiConfig.UserRois[2].BotRightX = 15;
roiConfig.UserRois[2].BotRightY = 5;
+
status = Sensor->vl53L1_SetROI( &roiConfig);
+// Device Initialization and setting
+ status = Sensor->vl53L1_DataInit();
+ status = Sensor->vl53L1_StaticInit();
+ status = Sensor->vl53L1_SetPresetMode( VL53L1_PRESETMODE_MULTIZONES_SCANNING);
+
status = Sensor->vl53L1_SetDistanceMode( VL53L1_DISTANCEMODE_LONG);
// status = Sensor->VL53L1_SetMeasurementTimingBudgetMicroSeconds( 100 * 500); // error -21 is because of this. Don't know why
@@ -237,6 +248,8 @@
if (board->sensor_centre != NULL) {
Dev = &devCentre;
Dev->i2c_slave_address = NEW_SENSOR_CENTRE_ADDRESS;
+ devCentre.i2c_slave_address = NEW_SENSOR_CENTRE_ADDRESS;
+
status = configure_sensor(board->sensor_centre);
printf("configuring centre channel \n");
}
@@ -244,6 +257,8 @@
if (board->sensor_left != NULL) {
Dev = &devLeft;
Dev->i2c_slave_address = NEW_SENSOR_LEFT_ADDRESS;
+ devLeft.i2c_slave_address = NEW_SENSOR_LEFT_ADDRESS;
+
status = configure_sensor(board->sensor_left);
printf("configuring left channel \n");
}
@@ -251,6 +266,8 @@
if (board->sensor_right != NULL) {
Dev = &devRight;
Dev->i2c_slave_address = NEW_SENSOR_RIGHT_ADDRESS;
+ devRight.i2c_slave_address = NEW_SENSOR_RIGHT_ADDRESS;
+
status = configure_sensor(board->sensor_right);
printf("configuring right channel \n");
}
@@ -357,16 +374,16 @@
// print out what data is required
-void print_results( int devNumber, VL53L1_MultiRangingData_t *pMultiRangingData )
+void print_results(int devNumber, VL53L1_MultiRangingData_t *pMultiRangingData )
{
- int no_of_object_found=pMultiRangingData->NumberOfObjectsFound;
+ int no_of_object_found = pMultiRangingData->NumberOfObjectsFound;
int signal_rate = 0;
int ambient_rate = 0;
- int RoiNumber=pMultiRangingData->RoiNumber;
+ int RoiNumber = pMultiRangingData->RoiNumber;
- if (( no_of_object_found < 10 ) && ( no_of_object_found != 0)) {
- for(int j=0; j<no_of_object_found; j++) {
+ 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 == VL53L1_RANGESTATUS_RANGE_VALID) ||
(pMultiRangingData->RangeData[j].RangeStatus == VL53L1_RANGESTATUS_RANGE_VALID_NO_WRAP_CHECK_FAIL)) {
signal_rate = pMultiRangingData->RangeData[j].SignalRateRtnMegaCps / 65535;