Uses Ayoub's Custom library.

Dependencies:   X_NUCLEO_53L3CX

Revision:
1:3151ff0b9da9
Parent:
0:137ce045e2a2
Child:
2:2489dfbd49d7
--- a/main.cpp	Wed Jul 14 14:40:24 2021 +0000
+++ b/main.cpp	Tue Jul 20 16:11:02 2021 +0000
@@ -43,6 +43,7 @@
 
 
 PinName InterruptPins[] ={D8,A2,D2}; // interrupt pins for the three sensors. 
+                                     // these will depend on how the sensor is wired
 
 static const char *TofDevStr[] =
 {
@@ -70,7 +71,8 @@
 
 
 /* ISR callback function of the active sensor */
-/* all it does set a flag which causes the main loop to get data */
+/* all it does set a flag which causes the main loop to get data. */
+/* Interrupts activated and defined in CUSTOM_RANGING_ConfigProfile() */
 void sensor_irq(void)
 {
     EventDetected = 1;
@@ -127,22 +129,22 @@
     }
  
     EventDetected = 1;  // clear any existing interrupts
-
+    // repeatedly read data and start next measurement
     while (1)
     {
         if ( EventDetected == 1 ) // irq detected
         {
             EventDetected = 0;
             status = sensor->CUSTOM_RANGING_GetDistance(ToF_sensor, &Result);
-            if ((status == BSP_ERROR_NONE) && (Result.ZoneResult[0].Status[0] == BSP_ERROR_NONE ))
+            if ((status == BSP_ERROR_NONE) && 
+                (Result.NumberOfZones != 0) && 
+                (Result.ZoneResult[0].Status[0] == BSP_ERROR_NONE ))
             {
                 printf("\n%s\t - ", TofDevStr[ToF_sensor]);
                 print_result(&Result);
             }
         }
       
-  
-  //  wait_ms(2);
     }
 }
 
@@ -151,12 +153,12 @@
 static void print_result(RANGING_SENSOR_Result_t *Result)
 {
     uint8_t j = 0;
-    uint8_t target = 0;
+    uint8_t zone = 0;
     
     printf(" |---> ");
-    printf("Status = %ld, Distance = %5ld mm \n",
-            Result->ZoneResult[target].Status[j],
-            Result->ZoneResult[target].Distance[j]);
+    printf("Status = %d, Distance = %5d mm \n",
+            Result->ZoneResult[zone].Status[j],
+            Result->ZoneResult[zone].Distance[j]);
          
 }
   
@@ -172,14 +174,13 @@
     sensor = new CUSTOM_SENSOR();
     
     printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\r\n");
+    printf("VL53L3CX_NoShield_1Sensors_interrupt\r\n");   
 
     MX_53L3A2_MultiSensorRanging_Init();
         
     while (1)
     {
-        /* USER CODE END WHILE */
          MX_53L3A2_MultiSensorRanging_Process();
-        /* USER CODE BEGIN 3 */
     }
 
 }