Jerry Szczurak / Mbed 2 deprecated Display_53L0A1_IntSatelites

Dependencies:   X_NUCLEO_53L0A1 mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "x_nucleo_53l0a1.h"
00003 #include <string.h>
00004 #include <stdlib.h>
00005 #include <stdio.h>
00006 #include <assert.h>
00007 
00008 /* This VL53L0X Expansion board test application performs a range measurement in interrupt mode
00009    on the center embedded sensor. 
00010    The measured data is displayed on the on-board 4-digit display, and sent to com port
00011 
00012    User Blue button stops the current measurement and the entire program, releasing all resources.
00013    Reset button is used to restart the program. 
00014 
00015    Interrupt mode requires callback function which handles IRQ from given sensor.
00016 */
00017 
00018 #define VL53L0_I2C_SDA   D14 
00019 #define VL53L0_I2C_SCL   D15 
00020 
00021 static X_NUCLEO_53L0A1 *board=NULL;
00022 VL53L0X_RangingMeasurementData_t data_sensor;
00023 OperatingMode operating_mode;
00024     
00025 /* flags that handle interrupt request for sensor and user blue button*/
00026 volatile bool int_sensor_centre=false;
00027 volatile bool int_measuring_stop = false;
00028 
00029 
00030 /* ISR callback function of the center sensor */
00031 void SensorCenterIRQ(void)
00032 {
00033    int_sensor_centre=true;
00034    board->sensor_centre->DisableInterruptMeasureDetectionIRQ();
00035 }   
00036 
00037 /* ISR callback function of the user blue button to switch measuring sensor. */
00038 void MeasuringStopIRQ(void)
00039 {
00040     int_measuring_stop = true;
00041 }
00042 
00043 /* On board 4 digit local display refresh */
00044 void DisplayRefresh(const VL53L0X_RangingMeasurementData_t &data)
00045 {   
00046     char str[4];
00047     if (data.RangeStatus == 0) // we have a valid range.
00048     {
00049         printf("%4d; ", data.RangeMilliMeter);
00050         sprintf(str,"%4d", data.RangeMilliMeter);
00051     }
00052     else
00053     {
00054         sprintf(str,"%s", "----");   
00055     }       
00056     board->display->DisplayString(str);
00057 }
00058 
00059 void RangeMeasure(DevI2C *device_i2c) {
00060    int status;
00061 
00062    /* creates the 53L0A1 expansion board singleton obj */
00063    board=X_NUCLEO_53L0A1::Instance(device_i2c, A2, D8, D2);
00064     
00065    board->display->DisplayString("53L0");
00066    
00067    /* setting operating mode to continuous interrupt */
00068    operating_mode=range_continuous_interrupt;
00069    
00070    /* init the 53L0A1 expansion board with default values */
00071    status=board->InitBoard();
00072    if(status)
00073    {
00074         printf("Failed to init board!\n\r");   
00075         return;
00076    }
00077    //Stop any measurement before setting sensor
00078    status=board->sensor_centre->StopMeasurement(operating_mode);
00079    status=board->sensor_centre->StartMeasurement(operating_mode, &SensorCenterIRQ); 
00080    
00081    if(!status)
00082    {
00083      printf ("Entering loop mode\r\n");
00084      while (true)
00085      { 
00086         if (int_sensor_centre)
00087         {
00088             int_sensor_centre = false;
00089             status = board->sensor_centre->HandleIRQ(operating_mode, &data_sensor);
00090             DisplayRefresh(data_sensor);
00091         }
00092 
00093         if (int_measuring_stop)
00094         {
00095             printf("\r\nEnding loop mode \r\n");
00096             break;
00097         }
00098      }
00099    }
00100    board->display->DisplayString("BYE");
00101    delete board;        
00102 }    
00103 
00104 /*=================================== Main ==================================
00105  Press the blue user button to stop the measurements in progress    
00106 =============================================================================*/
00107 int main()
00108 {   
00109 #if USER_BUTTON==PC_13  // we are cross compiling for Nucleo-f401 
00110    InterruptIn stop_button (USER_BUTTON);
00111    stop_button.rise (&MeasuringStopIRQ);  
00112 #endif   
00113    DevI2C *device_i2c =new DevI2C(VL53L0_I2C_SDA, VL53L0_I2C_SCL);        
00114    RangeMeasure(device_i2c);  // start continuous measures
00115 }
00116 
00117