test

Dependencies:   X_NUCLEO_53L0A1 mbed

Fork of Display_53L0A1 by ST

Files at this revision

API Documentation at this revision

Comitter:
johnAlexander
Date:
Mon Aug 07 14:33:34 2017 +0000
Parent:
1:c1c10e0c32b2
Child:
3:f767577b7aab
Commit message:
Aligned to ARM mbed coding style.

Changed in this revision

X_NUCLEO_53L0A1.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- a/X_NUCLEO_53L0A1.lib	Tue Jun 13 15:31:26 2017 +0000
+++ b/X_NUCLEO_53L0A1.lib	Mon Aug 07 14:33:34 2017 +0000
@@ -1,1 +1,1 @@
-https://developer.mbed.org/teams/ST/code/X_NUCLEO_53L0A1/#ceaa5a026412
+https://developer.mbed.org/teams/ST/code/X_NUCLEO_53L0A1/#8320b5ff96fa
--- a/main.cpp	Tue Jun 13 15:31:26 2017 +0000
+++ b/main.cpp	Mon Aug 07 14:33:34 2017 +0000
@@ -1,12 +1,12 @@
-/* 
+/*
  *  This VL53L0X Expansion board test application performs range measurements
- *  using the onboard embedded centre sensor, in singleshot, polling mode. 
+ *  using the onboard embedded centre sensor, in singleshot, polling mode.
  *  Measured ranges are displayed on the on-board 4-digit display.
  *
- *  The User Blue button stops the current measurement and entire program, 
+ *  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.
  */
 
 #include <string.h>
@@ -14,78 +14,74 @@
 
 #include "mbed.h"
 #include "x_nucleo_53l0a1.h"
+#include "vl53l0x_class.h"
 
-#define VL53L0_I2C_SDA   D14 
-#define VL53L0_I2C_SCL   D15 
+#define VL53L0_I2C_SDA   D14
+#define VL53L0_I2C_SCL   D15
 
 static X_NUCLEO_53L0A1 *board = NULL;
 VL53L0X_RangingMeasurementData_t data_sensor_centre;
 OperatingMode operating_mode;
-    
+
 /* flags that handle interrupt request */
-bool int_stop_measure = false;   
+bool int_stop_measure = false;
 
 /* ISR callback function of the user blue button to stop program */
-void StopMeasureIRQ(void)
+void stop_measure_irq(void)
 {
-   int_stop_measure = true;
+    int_stop_measure = true;
 }
 
 /* On board 4 digit local display refresh */
-void DisplayRefresh(VL53L0X_RangingMeasurementData_t sensor_range_data)
-{   
-   char str[5];
-   
-   if (sensor_range_data.RangeStatus == 0) // we have a valid range.
-   {
-      sprintf(str,"%d", sensor_range_data.RangeMilliMeter);
-   }
-   else
-   {
-      sprintf(str,"%s","----");
-   }
-     
-   board->display->DisplayString(str);
+void display_refresh(VL53L0X_RangingMeasurementData_t sensor_range_data)
+{
+    char str[5];
+
+    if (sensor_range_data.RangeStatus == 0) {   // we have a valid range.
+        sprintf(str, "%d", sensor_range_data.RangeMilliMeter);
+    } else {
+        sprintf(str, "%s", "----");
+    }
+
+    board->display->display_string(str);
 }
 
 /*=================================== Main ==================================
- Press the blue user button to stop measurements in progress    
+ Press the blue user button to stop measurements in progress
 =============================================================================*/
 int main()
 {
 #if USER_BUTTON == PC_13  // we are cross compiling for Nucleo-f401 
-   InterruptIn stop_button(USER_BUTTON);
-   stop_button.rise(&StopMeasureIRQ);  
-#endif   
+    InterruptIn stop_button(USER_BUTTON);
+    stop_button.rise(&stop_measure_irq);
+#endif
+
+    DevI2C *device_i2c = new DevI2C(VL53L0_I2C_SDA, VL53L0_I2C_SCL);
+    int status;
+
+    /* creates the 53L0A1 expansion board singleton obj */
+    board = X_NUCLEO_53L0A1::instance(device_i2c, A2, D8, D2);
 
-   DevI2C *device_i2c = new DevI2C(VL53L0_I2C_SDA, VL53L0_I2C_SCL);     
-   int status;
-        
-   /* creates the 53L0A1 expansion board singleton obj */
-   board=X_NUCLEO_53L0A1::Instance(device_i2c, A2, D8, D2);
-    
-   board->display->DisplayString("53L0");
-   /* init the 53L0A1 expansion board with default values */
-   status = board->InitBoard();
-   if (status) printf("Failed to init board!\n\r");   
-   operating_mode = range_single_shot_polling;
-   /* start the measure on sensor centre */
-   status = board->sensor_centre->StartMeasurement(operating_mode, NULL);
-   if (!status)
-   {
-      while (1) // infinite loop. can be broken by pressing Blue (User) button.
-      {
-         status = board->sensor_centre->GetMeasurement(operating_mode, &data_sensor_centre);
-         DisplayRefresh(data_sensor_centre);
-         if (int_stop_measure) // Blue Button isr was triggered
-         {
-            status = board->sensor_centre->StopMeasurement(operating_mode); // stop the measure and exit
-            int_stop_measure = false;
-            printf("\nProgram stopped!\n\n\r");
-            break;
-         }
-      }
-   }
-   board->display->DisplayString("BYE");
-   delete board;        
+    board->display->display_string("53L0");
+    /* init the 53L0A1 expansion board with default values */
+    status = board->init_board();
+    if (status)
+        printf("Failed to init board!\n\r");
+    operating_mode = range_single_shot_polling;
+    /* start the measure on sensor centre */
+    status = board->sensor_centre->start_measurement(operating_mode, NULL);
+    if (!status) {
+        while (1) {   // infinite loop. can be broken by pressing Blue (User) button.
+            status = board->sensor_centre->get_measurement(operating_mode, &data_sensor_centre);
+            display_refresh(data_sensor_centre);
+            if (int_stop_measure) {   // Blue Button isr was triggered
+                status = board->sensor_centre->stop_measurement(operating_mode);   // stop the measure and exit
+                int_stop_measure = false;
+                printf("\nProgram stopped!\n\n\r");
+                break;
+            }
+        }
+    }
+    board->display->display_string("BYE");
+    delete board;
 }
--- a/mbed.bld	Tue Jun 13 15:31:26 2017 +0000
+++ b/mbed.bld	Mon Aug 07 14:33:34 2017 +0000
@@ -1,1 +1,1 @@
-https://mbed.org/users/mbed_official/code/mbed/builds/0f02307a0877
\ No newline at end of file
+https://mbed.org/users/mbed_official/code/mbed/builds/64910690c574
\ No newline at end of file