Try to work but compile time error

Dependencies:   VL53L0X mbed

Committer:
oldmon
Date:
Sun Jun 24 06:18:52 2018 +0000
Revision:
0:4879420eb6e3
Warning:compile time error

Who changed what in which revision?

UserRevisionLine numberNew contents of line
oldmon 0:4879420eb6e3 1 #include "mbed.h"
oldmon 0:4879420eb6e3 2 #include "VL53L0X.h"
oldmon 0:4879420eb6e3 3 #define USE_I2C_2V8
oldmon 0:4879420eb6e3 4
oldmon 0:4879420eb6e3 5 Serial pc(USBTX, USBRX);
oldmon 0:4879420eb6e3 6 DigitalOut shutdown_pin(D4);
oldmon 0:4879420eb6e3 7
oldmon 0:4879420eb6e3 8 DevI2C i2c(I2C_SDA, I2C_SCL);
oldmon 0:4879420eb6e3 9 VL53L0X sensor(&i2c,&shutdown_pin,NC);
oldmon 0:4879420eb6e3 10
oldmon 0:4879420eb6e3 11 void print_pal_error(VL53L0X_Error Status){
oldmon 0:4879420eb6e3 12 char buf[VL53L0X_MAX_STRING_LENGTH];
oldmon 0:4879420eb6e3 13 sensor.VL53L0X_get_pal_error_string(Status, buf);
oldmon 0:4879420eb6e3 14 pc.printf("API Status: %i : %s\n", Status, buf);
oldmon 0:4879420eb6e3 15 }
oldmon 0:4879420eb6e3 16
oldmon 0:4879420eb6e3 17 void print_range_status(VL53L0X_RangingMeasurementData_t* pRangingMeasurementData){
oldmon 0:4879420eb6e3 18 char buf[VL53L0X_MAX_STRING_LENGTH];
oldmon 0:4879420eb6e3 19 uint8_t RangeStatus;
oldmon 0:4879420eb6e3 20 /*
oldmon 0:4879420eb6e3 21 * New Range Status: data is valid when pRangingMeasurementData->RangeStatus = 0
oldmon 0:4879420eb6e3 22 */
oldmon 0:4879420eb6e3 23 RangeStatus = pRangingMeasurementData->RangeStatus;
oldmon 0:4879420eb6e3 24 sensor.VL53L0X_get_range_status_string(RangeStatus, buf);
oldmon 0:4879420eb6e3 25 pc.printf("Range Status: %i : %s\n", RangeStatus, buf);
oldmon 0:4879420eb6e3 26 }
oldmon 0:4879420eb6e3 27
oldmon 0:4879420eb6e3 28 VL53L0X_Error rangingTest(VL53L0X_Dev_t *pMyDevice){
oldmon 0:4879420eb6e3 29 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
oldmon 0:4879420eb6e3 30 VL53L0X_RangingMeasurementData_t RangingMeasurementData;
oldmon 0:4879420eb6e3 31 int i;
oldmon 0:4879420eb6e3 32 FixPoint1616_t LimitCheckCurrent;
oldmon 0:4879420eb6e3 33 uint32_t refSpadCount;
oldmon 0:4879420eb6e3 34 uint8_t isApertureSpads;
oldmon 0:4879420eb6e3 35 uint8_t VhvSettings;
oldmon 0:4879420eb6e3 36 uint8_t PhaseCal;
oldmon 0:4879420eb6e3 37
oldmon 0:4879420eb6e3 38 if(Status == VL53L0X_ERROR_NONE){
oldmon 0:4879420eb6e3 39 pc.printf ("Call of VL53L0X_StaticInit\n");
oldmon 0:4879420eb6e3 40 Status = sensor.VL53L0X_static_init(pMyDevice); // Device Initialization
oldmon 0:4879420eb6e3 41 print_pal_error(Status);
oldmon 0:4879420eb6e3 42 }
oldmon 0:4879420eb6e3 43
oldmon 0:4879420eb6e3 44 if(Status == VL53L0X_ERROR_NONE){
oldmon 0:4879420eb6e3 45 pc.printf ("Call of VL53L0X_PerformRefCalibration\n");
oldmon 0:4879420eb6e3 46 Status = sensor.VL53L0X_perform_ref_calibration(pMyDevice,
oldmon 0:4879420eb6e3 47 &VhvSettings, &PhaseCal); // Device Initialization
oldmon 0:4879420eb6e3 48 print_pal_error(Status);
oldmon 0:4879420eb6e3 49 }
oldmon 0:4879420eb6e3 50
oldmon 0:4879420eb6e3 51 if(Status == VL53L0X_ERROR_NONE){
oldmon 0:4879420eb6e3 52 pc.printf ("Call of VL53L0X_PerformRefSpadManagement\n");
oldmon 0:4879420eb6e3 53 Status = sensor.VL53L0X_perform_ref_spad_management(pMyDevice,
oldmon 0:4879420eb6e3 54 &refSpadCount, &isApertureSpads); // Device Initialization
oldmon 0:4879420eb6e3 55 pc.printf ("refSpadCount = %d, isApertureSpads = %d\n", refSpadCount, isApertureSpads);
oldmon 0:4879420eb6e3 56 print_pal_error(Status);
oldmon 0:4879420eb6e3 57 }
oldmon 0:4879420eb6e3 58
oldmon 0:4879420eb6e3 59 if(Status == VL53L0X_ERROR_NONE){
oldmon 0:4879420eb6e3 60 // no need to do this when we use VL53L0X_PerformSingleRangingMeasurement
oldmon 0:4879420eb6e3 61 pc.printf ("Call of VL53L0X_SetDeviceMode\n");
oldmon 0:4879420eb6e3 62 Status = sensor.VL53L0X_set_device_mode(pMyDevice, VL53L0X_DEVICEMODE_SINGLE_RANGING); // Setup in single ranging mode
oldmon 0:4879420eb6e3 63 print_pal_error(Status);
oldmon 0:4879420eb6e3 64 }
oldmon 0:4879420eb6e3 65
oldmon 0:4879420eb6e3 66 // Enable/Disable Sigma and Signal check
oldmon 0:4879420eb6e3 67 if (Status == VL53L0X_ERROR_NONE){
oldmon 0:4879420eb6e3 68 Status = sensor.VL53L0X_set_limit_check_enable(pMyDevice,
oldmon 0:4879420eb6e3 69 VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE, 1);
oldmon 0:4879420eb6e3 70 }
oldmon 0:4879420eb6e3 71 if (Status == VL53L0X_ERROR_NONE){
oldmon 0:4879420eb6e3 72 Status = sensor.VL53L0X_set_limit_check_enable(pMyDevice,
oldmon 0:4879420eb6e3 73 VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE, 1);
oldmon 0:4879420eb6e3 74 }
oldmon 0:4879420eb6e3 75
oldmon 0:4879420eb6e3 76 if (Status == VL53L0X_ERROR_NONE){
oldmon 0:4879420eb6e3 77 Status = sensor.VL53L0X_set_limit_check_enable(pMyDevice,
oldmon 0:4879420eb6e3 78 VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD, 1);
oldmon 0:4879420eb6e3 79 }
oldmon 0:4879420eb6e3 80
oldmon 0:4879420eb6e3 81 if (Status == VL53L0X_ERROR_NONE){
oldmon 0:4879420eb6e3 82 Status = sensor.VL53L0X_set_limit_check_value(pMyDevice,
oldmon 0:4879420eb6e3 83 VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD,
oldmon 0:4879420eb6e3 84 (FixPoint1616_t)(1.5*0.023*65536));
oldmon 0:4879420eb6e3 85 }
oldmon 0:4879420eb6e3 86
oldmon 0:4879420eb6e3 87
oldmon 0:4879420eb6e3 88 /*
oldmon 0:4879420eb6e3 89 * Step 4 : Test ranging mode
oldmon 0:4879420eb6e3 90 */
oldmon 0:4879420eb6e3 91
oldmon 0:4879420eb6e3 92 if(Status == VL53L0X_ERROR_NONE){
oldmon 0:4879420eb6e3 93 for(i=0;i<10;i++){
oldmon 0:4879420eb6e3 94 pc.printf ("Call of VL53L0X_PerformSingleRangingMeasurement\n");
oldmon 0:4879420eb6e3 95 Status = sensor.VL53L0X_perform_single_ranging_measurement(pMyDevice,
oldmon 0:4879420eb6e3 96 &RangingMeasurementData);
oldmon 0:4879420eb6e3 97
oldmon 0:4879420eb6e3 98 print_pal_error(Status);
oldmon 0:4879420eb6e3 99 print_range_status(&RangingMeasurementData);
oldmon 0:4879420eb6e3 100
oldmon 0:4879420eb6e3 101 sensor.VL53L0X_get_limit_check_current(pMyDevice,
oldmon 0:4879420eb6e3 102 VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD, &LimitCheckCurrent);
oldmon 0:4879420eb6e3 103
oldmon 0:4879420eb6e3 104 pc.printf("RANGE IGNORE THRESHOLD: %f\n\n", (double)LimitCheckCurrent/65536.0);
oldmon 0:4879420eb6e3 105
oldmon 0:4879420eb6e3 106 if (Status != VL53L0X_ERROR_NONE) break;
oldmon 0:4879420eb6e3 107
oldmon 0:4879420eb6e3 108 pc.printf("Measured distance: %i\n\n", RangingMeasurementData.RangeMilliMeter);
oldmon 0:4879420eb6e3 109
oldmon 0:4879420eb6e3 110
oldmon 0:4879420eb6e3 111 }
oldmon 0:4879420eb6e3 112 }
oldmon 0:4879420eb6e3 113 return Status;
oldmon 0:4879420eb6e3 114 }
oldmon 0:4879420eb6e3 115
oldmon 0:4879420eb6e3 116 int main(){
oldmon 0:4879420eb6e3 117 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
oldmon 0:4879420eb6e3 118 VL53L0X_Dev_t MyDevice;
oldmon 0:4879420eb6e3 119 VL53L0X_Dev_t *pMyDevice = &MyDevice;
oldmon 0:4879420eb6e3 120 VL53L0X_Version_t Version;
oldmon 0:4879420eb6e3 121 VL53L0X_Version_t *pVersion = &Version;
oldmon 0:4879420eb6e3 122 VL53L0X_DeviceInfo_t DeviceInfo;
oldmon 0:4879420eb6e3 123
oldmon 0:4879420eb6e3 124 int32_t status_int;
oldmon 0:4879420eb6e3 125 //int32_t init_done = 0;
oldmon 0:4879420eb6e3 126
oldmon 0:4879420eb6e3 127 pc.printf ("VL53L0X API Simple Ranging example\n\n");
oldmon 0:4879420eb6e3 128
oldmon 0:4879420eb6e3 129 /*
oldmon 0:4879420eb6e3 130 * Disable VL53L0X API logging if you want to run at full speed
oldmon 0:4879420eb6e3 131 */
oldmon 0:4879420eb6e3 132 #ifdef VL53L0X_LOG_ENABLE
oldmon 0:4879420eb6e3 133 VL53L0X_trace_config("test.log", TRACE_MODULE_ALL, TRACE_LEVEL_ALL, TRACE_FUNCTION_ALL);
oldmon 0:4879420eb6e3 134 #endif
oldmon 0:4879420eb6e3 135
oldmon 0:4879420eb6e3 136 /*
oldmon 0:4879420eb6e3 137 * Get the version of the VL53L0X API running in the firmware
oldmon 0:4879420eb6e3 138 */
oldmon 0:4879420eb6e3 139
oldmon 0:4879420eb6e3 140 if(Status == VL53L0X_ERROR_NONE){
oldmon 0:4879420eb6e3 141 status_int = sensor.VL53L0X_get_version(pVersion);
oldmon 0:4879420eb6e3 142 if (status_int != 0)
oldmon 0:4879420eb6e3 143 Status = VL53L0X_ERROR_CONTROL_INTERFACE;
oldmon 0:4879420eb6e3 144 }
oldmon 0:4879420eb6e3 145
oldmon 0:4879420eb6e3 146 /*
oldmon 0:4879420eb6e3 147 * Verify the version of the VL53L0X API running in the firmware
oldmon 0:4879420eb6e3 148 */
oldmon 0:4879420eb6e3 149
oldmon 0:4879420eb6e3 150 if(Status == VL53L0X_ERROR_NONE) {
oldmon 0:4879420eb6e3 151 pc.printf ("Call of VL53L0X_DataInit\n");
oldmon 0:4879420eb6e3 152 Status = sensor.VL53L0X_data_init(&MyDevice); // Data initialization
oldmon 0:4879420eb6e3 153 print_pal_error(Status);
oldmon 0:4879420eb6e3 154 }
oldmon 0:4879420eb6e3 155
oldmon 0:4879420eb6e3 156 if(Status == VL53L0X_ERROR_NONE){
oldmon 0:4879420eb6e3 157 Status = sensor.VL53L0X_get_device_info(&MyDevice, &DeviceInfo);
oldmon 0:4879420eb6e3 158 if(Status == VL53L0X_ERROR_NONE){
oldmon 0:4879420eb6e3 159 pc.printf("VL53L0X_GetDeviceInfo:\n");
oldmon 0:4879420eb6e3 160 pc.printf("Device Name : %s\n", DeviceInfo.Name);
oldmon 0:4879420eb6e3 161 pc.printf("Device Type : %s\n", DeviceInfo.Type);
oldmon 0:4879420eb6e3 162 pc.printf("Device ID : %s\n", DeviceInfo.ProductId);
oldmon 0:4879420eb6e3 163 pc.printf("ProductRevisionMajor : %d\n", DeviceInfo.ProductRevisionMajor);
oldmon 0:4879420eb6e3 164 pc.printf("ProductRevisionMinor : %d\n", DeviceInfo.ProductRevisionMinor);
oldmon 0:4879420eb6e3 165
oldmon 0:4879420eb6e3 166 if ((DeviceInfo.ProductRevisionMinor != 1) && (DeviceInfo.ProductRevisionMinor != 1)) {
oldmon 0:4879420eb6e3 167 pc.printf("Error expected cut 1.1 but found cut %d.%d\n",
oldmon 0:4879420eb6e3 168 DeviceInfo.ProductRevisionMajor, DeviceInfo.ProductRevisionMinor);
oldmon 0:4879420eb6e3 169 Status = VL53L0X_ERROR_NOT_SUPPORTED;
oldmon 0:4879420eb6e3 170 }
oldmon 0:4879420eb6e3 171 }
oldmon 0:4879420eb6e3 172 print_pal_error(Status);
oldmon 0:4879420eb6e3 173 }
oldmon 0:4879420eb6e3 174
oldmon 0:4879420eb6e3 175 if(Status == VL53L0X_ERROR_NONE)
oldmon 0:4879420eb6e3 176 Status = rangingTest(pMyDevice);
oldmon 0:4879420eb6e3 177
oldmon 0:4879420eb6e3 178 print_pal_error(Status);
oldmon 0:4879420eb6e3 179
oldmon 0:4879420eb6e3 180 // Implementation specific
oldmon 0:4879420eb6e3 181
oldmon 0:4879420eb6e3 182 /*
oldmon 0:4879420eb6e3 183 * Disconnect comms - part of VL53L0X_platform.c
oldmon 0:4879420eb6e3 184 */
oldmon 0:4879420eb6e3 185
oldmon 0:4879420eb6e3 186 /*if(init_done == 0){
oldmon 0:4879420eb6e3 187 pc.printf ("Close Comms\n");
oldmon 0:4879420eb6e3 188 status_int = VL53L0X_comms_close();
oldmon 0:4879420eb6e3 189 if (status_int != 0)
oldmon 0:4879420eb6e3 190 Status = VL53L0X_ERROR_CONTROL_INTERFACE;
oldmon 0:4879420eb6e3 191 }*/
oldmon 0:4879420eb6e3 192
oldmon 0:4879420eb6e3 193 print_pal_error(Status);
oldmon 0:4879420eb6e3 194
oldmon 0:4879420eb6e3 195 // printf ("\nPress a Key to continue!");
oldmon 0:4879420eb6e3 196 // getchar();
oldmon 0:4879420eb6e3 197
oldmon 0:4879420eb6e3 198 return (0);
oldmon 0:4879420eb6e3 199 }