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_53L0A1
Fork of Display_53L0A1_WithSatelites by
main.cpp
00001 #include "mbed.h" 00002 #include "XNucleo53L0A1.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 polling mode 00009 on the sensors. The demo supports the centre sensor and up to 2 satellites boards. 00010 00011 The User Blue button controls the selected sensor. Measurements from this sensor are displayed 00012 on the 4-digit display. 00013 Data collected from all sensors is also sent on the com port. 00014 00015 The Reset button is used to restart the program. 00016 */ 00017 00018 #define VL53L0_I2C_SDA D14 00019 #define VL53L0_I2C_SCL D15 00020 00021 static XNucleo53L0A1 *board = NULL; 00022 VL53L0X_RangingMeasurementData_t data_sensor; 00023 OperatingMode operating_mode; 00024 00025 /* Current sensor number*/ 00026 int currentSensor = 0; 00027 /* Installed sensors count */ 00028 int sensorCnt = 0; 00029 00030 /* array storing pointers to the sensors and their prefixes for the display purpouse*/ 00031 struct Sensors { 00032 char prefix; 00033 VL53L0X *sensorPtr; 00034 } installedSensors[3]; 00035 00036 int init_sensors_array() 00037 { 00038 int status = 1; 00039 /* start the measure on sensor top */ 00040 if (NULL != board->sensor_centre) { 00041 installedSensors[sensorCnt].prefix = 'C'; 00042 installedSensors[sensorCnt].sensorPtr = board->sensor_centre; 00043 ++sensorCnt; 00044 status = board->sensor_centre->start_measurement(operating_mode, NULL); 00045 } 00046 /* start the measure on sensor left if present */ 00047 if (NULL != board->sensor_left) { 00048 installedSensors[sensorCnt].prefix = 'L'; 00049 installedSensors[sensorCnt].sensorPtr = board->sensor_left; 00050 ++sensorCnt; 00051 status = board->sensor_left->start_measurement(operating_mode, NULL); 00052 } 00053 /* start the measure on sensor right if present */ 00054 if (NULL != board->sensor_right) { 00055 installedSensors[sensorCnt].prefix = 'R'; 00056 installedSensors[sensorCnt].sensorPtr = board->sensor_right; 00057 ++sensorCnt; 00058 status = board->sensor_right->start_measurement(operating_mode, NULL); 00059 } 00060 /* set first displayed sensor to embedded top */ 00061 currentSensor = 0; 00062 return status; 00063 } 00064 00065 /* ISR callback function of the user blue button to switch measuring sensor. */ 00066 void switch_measuring_sensor_irq(void) 00067 { 00068 ++currentSensor; 00069 if (currentSensor == sensorCnt) 00070 currentSensor = 0; 00071 printf("Sensor changed to %c\r\n", installedSensors[currentSensor].prefix); 00072 } 00073 00074 /* On board 4 digit local display refresh*/ 00075 void display_refresh(OperatingMode op_mode) 00076 { 00077 char str[4]; 00078 00079 for (int t = 0; t < sensorCnt; t++) { 00080 installedSensors[t].sensorPtr->get_measurement(op_mode, &data_sensor); 00081 if (data_sensor.RangeStatus == 0) { // we have a valid range. 00082 printf("%c %4d; ", installedSensors[t].prefix, data_sensor.RangeMilliMeter); 00083 if (currentSensor == t) { 00084 sprintf(str, "%c%3d", installedSensors[t].prefix, data_sensor.RangeMilliMeter); 00085 } 00086 } else { 00087 printf("%c ----; ", installedSensors[t].prefix); 00088 if (currentSensor == t) { 00089 sprintf(str, "%c%s", installedSensors[t].prefix, "---"); 00090 } 00091 } 00092 } 00093 printf("\r\n"); 00094 board->display->display_string(str); 00095 } 00096 00097 void range_measure(DevI2C *device_i2c) 00098 { 00099 int status; 00100 00101 /* creates the 53L0A1 expansion board singleton obj */ 00102 board = XNucleo53L0A1::instance(device_i2c, A2, D8, D2); 00103 00104 board->display->display_string("53L0"); 00105 /* init the 53L0A1 expansion board with default values */ 00106 status = board->init_board(); 00107 if (status) 00108 printf("Failed to init board!\n\r"); 00109 operating_mode = range_single_shot_polling; 00110 00111 status = init_sensors_array(); 00112 00113 if (!status) { 00114 while (1) { 00115 display_refresh(operating_mode); 00116 } 00117 } 00118 board->display->display_string("BYE"); 00119 delete board; 00120 } 00121 00122 /*=================================== Main ================================== 00123 Press the blue user button to switch the sensor. 00124 =============================================================================*/ 00125 int main() 00126 { 00127 #if USER_BUTTON==PC_13 // we are cross compiling for Nucleo-f401 00128 InterruptIn stop_button(USER_BUTTON); 00129 stop_button.rise(&switch_measuring_sensor_irq); 00130 #endif 00131 DevI2C *device_i2c = new DevI2C(VL53L0_I2C_SDA, VL53L0_I2C_SCL); 00132 range_measure(device_i2c); // start continuous measures 00133 } 00134
Generated on Wed Jul 20 2022 03:56:32 by
1.7.2
