Rev 4 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4 | Rev 6 | ||
---|---|---|---|
Line 29... | Line 29... | ||
29 | chprintf(chp,"Range Status: %i : %s\r\n", RangeStatus, buf); |
29 | chprintf(chp,"Range Status: %i : %s\r\n", RangeStatus, buf); |
30 | 30 | ||
31 | } |
31 | } |
32 | 32 | ||
33 | 33 | ||
- | 34 | VL53L0X_Error VL53L0XdeviceSetup(VL53L0X_Dev_t *pMyDevice) |
|
- | 35 | { |
|
- | 36 | VL53L0X_Error Status = VL53L0X_ERROR_NONE; |
|
- | 37 | VL53L0X_RangingMeasurementData_t RangingMeasurementData; |
|
- | 38 | int i; |
|
- | 39 | uint32_t refSpadCount; |
|
- | 40 | uint8_t isApertureSpads; |
|
- | 41 | uint8_t VhvSettings; |
|
- | 42 | uint8_t PhaseCal; |
|
- | 43 | ||
- | 44 | // Initialize Comms |
|
- | 45 | pMyDevice->I2cDevAddr = 0x29; // chibi-style |
|
- | 46 | pMyDevice->comms_type = 1; |
|
- | 47 | pMyDevice->comms_speed_khz = 100; |
|
- | 48 | ||
- | 49 | // call init anyway |
|
- | 50 | VL53L0X_comms_initialise(0,0); |
|
- | 51 | ||
- | 52 | ||
- | 53 | if(Status == VL53L0X_ERROR_NONE) |
|
- | 54 | { |
|
- | 55 | Status = VL53L0X_StaticInit(pMyDevice); // Device Initialization |
|
- | 56 | } |
|
- | 57 | ||
- | 58 | if(Status == VL53L0X_ERROR_NONE) |
|
- | 59 | { |
|
- | 60 | Status = VL53L0X_PerformRefCalibration(pMyDevice, |
|
- | 61 | &VhvSettings, &PhaseCal); // Device Initialization |
|
- | 62 | } |
|
- | 63 | ||
- | 64 | if(Status == VL53L0X_ERROR_NONE) |
|
- | 65 | { |
|
- | 66 | Status = VL53L0X_PerformRefSpadManagement(pMyDevice, |
|
- | 67 | &refSpadCount, &isApertureSpads); // Device Initialization |
|
- | 68 | } |
|
- | 69 | ||
- | 70 | if(Status == VL53L0X_ERROR_NONE) |
|
- | 71 | { |
|
- | 72 | // no need to do this when we use VL53L0X_PerformSingleRangingMeasurement |
|
- | 73 | Status = VL53L0X_SetDeviceMode(pMyDevice, VL53L0X_DEVICEMODE_SINGLE_RANGING); // Setup in single ranging mode |
|
- | 74 | } |
|
- | 75 | ||
- | 76 | // Enable/Disable Sigma and Signal check |
|
- | 77 | ||
- | 78 | /* if (Status == VL53L0X_ERROR_NONE) { |
|
- | 79 | Status = VL53L0X_SetSequenceStepEnable(pMyDevice,VL53L0X_SEQUENCESTEP_DSS, 1); |
|
- | 80 | }*/ |
|
- | 81 | ||
- | 82 | if (Status == VL53L0X_ERROR_NONE) { |
|
- | 83 | Status = VL53L0X_SetLimitCheckEnable(pMyDevice, |
|
- | 84 | VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE, 1); |
|
- | 85 | } |
|
- | 86 | if (Status == VL53L0X_ERROR_NONE) { |
|
- | 87 | Status = VL53L0X_SetLimitCheckEnable(pMyDevice, |
|
- | 88 | VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE, 1); |
|
- | 89 | } |
|
- | 90 | ||
- | 91 | if (Status == VL53L0X_ERROR_NONE) { |
|
- | 92 | Status = VL53L0X_SetLimitCheckValue(pMyDevice, |
|
- | 93 | VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE, |
|
- | 94 | (FixPoint1616_t)(0.1*65536)); |
|
- | 95 | } |
|
- | 96 | if (Status == VL53L0X_ERROR_NONE) { |
|
- | 97 | Status = VL53L0X_SetLimitCheckValue(pMyDevice, |
|
- | 98 | VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE, |
|
- | 99 | (FixPoint1616_t)(60*65536)); |
|
- | 100 | } |
|
- | 101 | if (Status == VL53L0X_ERROR_NONE) { |
|
- | 102 | Status = VL53L0X_SetMeasurementTimingBudgetMicroSeconds(pMyDevice, |
|
- | 103 | 33000); |
|
- | 104 | } |
|
- | 105 | ||
- | 106 | if (Status == VL53L0X_ERROR_NONE) { |
|
- | 107 | Status = VL53L0X_SetVcselPulsePeriod(pMyDevice, |
|
- | 108 | VL53L0X_VCSEL_PERIOD_PRE_RANGE, 18); |
|
- | 109 | } |
|
- | 110 | if (Status == VL53L0X_ERROR_NONE) { |
|
- | 111 | Status = VL53L0X_SetVcselPulsePeriod(pMyDevice, |
|
- | 112 | VL53L0X_VCSEL_PERIOD_FINAL_RANGE, 14); |
|
- | 113 | } |
|
- | 114 | return Status; |
|
- | 115 | ||
- | 116 | } |
|
- | 117 | ||
- | 118 | ||
- | 119 | ||
- | 120 | ||
34 | VL53L0X_Error rangingTest(BaseSequentialStream *chp,VL53L0X_Dev_t *pMyDevice) |
121 | VL53L0X_Error rangingTest(BaseSequentialStream *chp,VL53L0X_Dev_t *pMyDevice) |
35 | { |
122 | { |
36 | VL53L0X_Error Status = VL53L0X_ERROR_NONE; |
123 | VL53L0X_Error Status = VL53L0X_ERROR_NONE; |
37 | VL53L0X_RangingMeasurementData_t RangingMeasurementData; |
124 | VL53L0X_RangingMeasurementData_t RangingMeasurementData; |
38 | int i; |
125 | int i; |
Line 137... | Line 224... | ||
137 | } |
224 | } |
138 | } |
225 | } |
139 | return Status; |
226 | return Status; |
140 | } |
227 | } |
141 | // make this into a shell command |
228 | // make this into a shell command |
- | 229 | extern void setPause(bool pause); |
|
142 | 230 | ||
143 | void shellLidar(BaseSequentialStream *chp, int argc, char *argv[]) |
231 | void shellLidar(BaseSequentialStream *chp, int argc, char *argv[]) |
144 | { |
232 | { |
145 | VL53L0X_Error Status = VL53L0X_ERROR_NONE; |
233 | VL53L0X_Error Status = VL53L0X_ERROR_NONE; |
146 | VL53L0X_Dev_t MyDevice; |
234 | VL53L0X_Dev_t MyDevice; |
Line 151... | Line 239... | ||
151 | 239 | ||
152 | int32_t status_int; |
240 | int32_t status_int; |
153 | int32_t init_done = 0; |
241 | int32_t init_done = 0; |
154 | // TCHAR SerialCommStr[MAX_VALUE_NAME]; |
242 | // TCHAR SerialCommStr[MAX_VALUE_NAME]; |
155 | 243 | ||
156 | - | ||
- | 244 | setPause(true); |
|
157 | 245 | ||
158 | chprintf(chp,"VL53L0X API Simple Ranging example\r\n\r\n"); |
246 | chprintf(chp,"VL53L0X API Simple Ranging example\r\n\r\n"); |
159 | // chprintf(chp,"Press a Key to continue!\r\n\r\n"); |
247 | // chprintf(chp,"Press a Key to continue!\r\n\r\n"); |
160 | // getchar(); |
248 | // getchar(); |
161 | 249 | ||
Line 163... | Line 251... | ||
163 | // Initialize Comms |
251 | // Initialize Comms |
164 | pMyDevice->I2cDevAddr = 0x29; // chibi-style |
252 | pMyDevice->I2cDevAddr = 0x29; // chibi-style |
165 | pMyDevice->comms_type = 1; |
253 | pMyDevice->comms_type = 1; |
166 | pMyDevice->comms_speed_khz = 100; |
254 | pMyDevice->comms_speed_khz = 100; |
167 | 255 | ||
168 | - | ||
- | 256 | // call init anyway |
|
- | 257 | VL53L0X_comms_initialise(0,0); |
|
169 | /* |
258 | /* |
170 | * Disable VL53L0X API logging if you want to run at full speed |
259 | * Disable VL53L0X API logging if you want to run at full speed |
171 | */ |
260 | */ |
172 | #ifdef VL53L0X_LOG_ENABLE |
261 | #ifdef VL53L0X_LOG_ENABLE |
173 | VL53L0X_trace_config("test.log", TRACE_MODULE_ALL, TRACE_LEVEL_ALL, TRACE_FUNCTION_ALL); |
262 | VL53L0X_trace_config("test.log", TRACE_MODULE_ALL, TRACE_LEVEL_ALL, TRACE_FUNCTION_ALL); |
Line 252... | Line 341... | ||
252 | 341 | ||
253 | print_pal_error(chp,Status); |
342 | print_pal_error(chp,Status); |
254 | 343 | ||
255 | // chprintf(chp,"\r\nPress a Key to continue!"); |
344 | // chprintf(chp,"\r\nPress a Key to continue!"); |
256 | // getchar(); |
345 | // getchar(); |
- | 346 | setPause(false); |
|
257 | 347 | ||
258 | return (0); |
348 | return (0); |
259 | } |
349 | } |
260 | 350 |