Sample ranging application, using X_Nucleo_53L3A2 expansion board and supporting Satellite boards, to ranging from each sensor, using interrupts. Targetting MbedOS v6.10.
Dependencies: X_NUCLEO_53L3A2
main.cpp@5:92a861d48253, 2021-05-07 (annotated)
- Committer:
- johnAlexander
- Date:
- Fri May 07 14:46:18 2021 +0000
- Revision:
- 5:92a861d48253
- Parent:
- 4:360dc34c3769
- Child:
- 7:5b8a91c3bafc
Reformatted with astyle, to mbed contributing guidelines.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
charlesmn | 0:c77591fc308d | 1 | /* |
johnAlexander | 4:360dc34c3769 | 2 | * This VL53L3 Expansion board test application performs range measurements |
johnAlexander | 4:360dc34c3769 | 3 | * using the onboard embedded centre sensor, in singleshot, polling mode. |
johnAlexander | 4:360dc34c3769 | 4 | * Measured ranges are ouput on the Serial Port, running at 115200 baud. |
johnAlexander | 4:360dc34c3769 | 5 | * |
johnAlexander | 4:360dc34c3769 | 6 | * The User Blue button stops the current measurement and entire program, |
johnAlexander | 4:360dc34c3769 | 7 | * releasing all resources. |
charlesmn | 0:c77591fc308d | 8 | * |
johnAlexander | 4:360dc34c3769 | 9 | * The Reset button can be used to restart the program. |
charlesmn | 0:c77591fc308d | 10 | * |
johnAlexander | 5:92a861d48253 | 11 | * *** Note : |
johnAlexander | 4:360dc34c3769 | 12 | * Default Mbed build system settings disable print floating-point support. |
johnAlexander | 4:360dc34c3769 | 13 | * Offline builds can enable this, again. |
johnAlexander | 4:360dc34c3769 | 14 | * https://github.com/ARMmbed/mbed-os/blob/master/platform/source/minimal-printf/README.md |
johnAlexander | 4:360dc34c3769 | 15 | * .\mbed-os\platform\mbed_lib.json |
johnAlexander | 4:360dc34c3769 | 16 | * |
charlesmn | 0:c77591fc308d | 17 | */ |
johnAlexander | 5:92a861d48253 | 18 | |
charlesmn | 0:c77591fc308d | 19 | #include <stdio.h> |
johnAlexander | 3:42c96c9c627b | 20 | #include <time.h> |
charlesmn | 0:c77591fc308d | 21 | |
charlesmn | 0:c77591fc308d | 22 | #include "mbed.h" |
johnAlexander | 4:360dc34c3769 | 23 | |
johnAlexander | 3:42c96c9c627b | 24 | #include "XNucleo53L3A2.h" |
charlesmn | 2:86876e590f28 | 25 | #include "vl53L3_I2c.h" |
charlesmn | 0:c77591fc308d | 26 | |
charlesmn | 0:c77591fc308d | 27 | |
johnAlexander | 5:92a861d48253 | 28 | #define I2C_SDA D14 |
johnAlexander | 5:92a861d48253 | 29 | #define I2C_SCL D15 |
charlesmn | 0:c77591fc308d | 30 | |
johnAlexander | 5:92a861d48253 | 31 | #define MEASUREMENTTIMING 55 |
charlesmn | 0:c77591fc308d | 32 | |
johnAlexander | 3:42c96c9c627b | 33 | static XNucleo53L3A2 *board=NULL; |
johnAlexander | 3:42c96c9c627b | 34 | #if (MBED_VERSION > 60300) |
johnAlexander | 5:92a861d48253 | 35 | UnbufferedSerial pc(USBTX, USBRX); |
johnAlexander | 5:92a861d48253 | 36 | extern "C" void wait_ms(int ms); |
johnAlexander | 3:42c96c9c627b | 37 | #else |
johnAlexander | 5:92a861d48253 | 38 | Serial pc(SERIAL_TX, SERIAL_RX); |
johnAlexander | 3:42c96c9c627b | 39 | #endif |
charlesmn | 0:c77591fc308d | 40 | |
charlesmn | 0:c77591fc308d | 41 | static int int_centre_result = 0; |
charlesmn | 0:c77591fc308d | 42 | static int int_left_result = 0; |
charlesmn | 0:c77591fc308d | 43 | static int int_right_result = 0; |
charlesmn | 0:c77591fc308d | 44 | |
charlesmn | 0:c77591fc308d | 45 | |
johnAlexander | 5:92a861d48253 | 46 | class WaitForMeasurement |
johnAlexander | 5:92a861d48253 | 47 | { |
johnAlexander | 5:92a861d48253 | 48 | |
charlesmn | 0:c77591fc308d | 49 | public: |
charlesmn | 0:c77591fc308d | 50 | |
charlesmn | 0:c77591fc308d | 51 | |
charlesmn | 0:c77591fc308d | 52 | // this class services the interrupts from the ToF sensors. |
charlesmn | 0:c77591fc308d | 53 | // There is a limited amount you can do in an interrupt routine; printfs,mutexes break them among other things. |
charlesmn | 0:c77591fc308d | 54 | // We keep things simple by only raising a flag so all the real work is done outside the interrupt. |
charlesmn | 0:c77591fc308d | 55 | // This is designed around MBED V2 which doesn't have the RTOS features that would make this work nicely e.g. semaphores/queues. |
johnAlexander | 5:92a861d48253 | 56 | WaitForMeasurement(): _interrupt(A1) |
johnAlexander | 5:92a861d48253 | 57 | { |
johnAlexander | 5:92a861d48253 | 58 | } |
charlesmn | 0:c77591fc308d | 59 | |
charlesmn | 0:c77591fc308d | 60 | |
charlesmn | 0:c77591fc308d | 61 | // constructor - Sensor is not used and can be removed |
charlesmn | 0:c77591fc308d | 62 | WaitForMeasurement(PinName pin,VL53LX_DEV Dev) : _interrupt(pin) // create the InterruptIn on the pin specified to Counter |
charlesmn | 0:c77591fc308d | 63 | { |
johnAlexander | 5:92a861d48253 | 64 | Devlocal = Dev; |
charlesmn | 0:c77591fc308d | 65 | _interrupt.rise(callback(this, &WaitForMeasurement::got_interrupt)); // attach increment function of this counter instance |
johnAlexander | 5:92a861d48253 | 66 | |
charlesmn | 0:c77591fc308d | 67 | } |
johnAlexander | 5:92a861d48253 | 68 | |
charlesmn | 0:c77591fc308d | 69 | void process_right_interrupt() |
charlesmn | 0:c77591fc308d | 70 | { |
johnAlexander | 5:92a861d48253 | 71 | printf("processing right interrupt\n"); |
charlesmn | 0:c77591fc308d | 72 | } |
charlesmn | 0:c77591fc308d | 73 | |
johnAlexander | 5:92a861d48253 | 74 | // function is called every time an interupt is seen. A flag is raised which allows the main routine to service the interupt. |
charlesmn | 0:c77591fc308d | 75 | void got_interrupt() |
charlesmn | 0:c77591fc308d | 76 | { |
charlesmn | 0:c77591fc308d | 77 | _count++; |
charlesmn | 0:c77591fc308d | 78 | |
charlesmn | 0:c77591fc308d | 79 | if (Devlocal->I2cDevAddr == NEW_SENSOR_CENTRE_ADDRESS) |
charlesmn | 0:c77591fc308d | 80 | int_centre_result = 1; //flag to main that interrupt happened |
charlesmn | 0:c77591fc308d | 81 | if (Devlocal->I2cDevAddr == NEW_SENSOR_LEFT_ADDRESS) |
charlesmn | 0:c77591fc308d | 82 | int_left_result = 1; //flag to main that interrupt happened |
charlesmn | 0:c77591fc308d | 83 | if (Devlocal->I2cDevAddr == NEW_SENSOR_RIGHT_ADDRESS) |
charlesmn | 0:c77591fc308d | 84 | int_right_result = 1; //flag to main that interrupt happened |
charlesmn | 0:c77591fc308d | 85 | } |
charlesmn | 0:c77591fc308d | 86 | |
johnAlexander | 5:92a861d48253 | 87 | |
charlesmn | 0:c77591fc308d | 88 | //destructor |
charlesmn | 0:c77591fc308d | 89 | ~WaitForMeasurement() |
charlesmn | 0:c77591fc308d | 90 | { |
charlesmn | 0:c77591fc308d | 91 | printf("destruction \n"); |
charlesmn | 0:c77591fc308d | 92 | } |
charlesmn | 0:c77591fc308d | 93 | |
charlesmn | 0:c77591fc308d | 94 | private: |
johnAlexander | 4:360dc34c3769 | 95 | |
charlesmn | 0:c77591fc308d | 96 | InterruptIn _interrupt; |
charlesmn | 0:c77591fc308d | 97 | volatile int _count; |
charlesmn | 0:c77591fc308d | 98 | VL53LX_DEV Devlocal; |
johnAlexander | 5:92a861d48253 | 99 | int status; |
charlesmn | 0:c77591fc308d | 100 | }; |
charlesmn | 0:c77591fc308d | 101 | |
charlesmn | 0:c77591fc308d | 102 | |
charlesmn | 0:c77591fc308d | 103 | |
charlesmn | 0:c77591fc308d | 104 | VL53LX_Dev_t devCentre; |
charlesmn | 0:c77591fc308d | 105 | VL53LX_Dev_t devLeft; |
charlesmn | 0:c77591fc308d | 106 | VL53LX_Dev_t devRight; |
charlesmn | 0:c77591fc308d | 107 | VL53LX_DEV Dev = &devCentre; |
charlesmn | 0:c77591fc308d | 108 | |
charlesmn | 0:c77591fc308d | 109 | |
charlesmn | 0:c77591fc308d | 110 | |
charlesmn | 0:c77591fc308d | 111 | |
johnAlexander | 5:92a861d48253 | 112 | |
charlesmn | 0:c77591fc308d | 113 | /*=================================== Main ================================== |
charlesmn | 0:c77591fc308d | 114 | =============================================================================*/ |
charlesmn | 0:c77591fc308d | 115 | int main() |
johnAlexander | 5:92a861d48253 | 116 | { |
charlesmn | 0:c77591fc308d | 117 | int status; |
johnAlexander | 3:42c96c9c627b | 118 | VL53L3 * Sensor; |
charlesmn | 0:c77591fc308d | 119 | uint16_t wordData; |
charlesmn | 0:c77591fc308d | 120 | uint8_t ToFSensor = 1; // 0=Left, 1=Center(default), 2=Right |
johnAlexander | 5:92a861d48253 | 121 | |
johnAlexander | 5:92a861d48253 | 122 | |
charlesmn | 0:c77591fc308d | 123 | WaitForMeasurement* int2; |
charlesmn | 0:c77591fc308d | 124 | WaitForMeasurement* int1; |
charlesmn | 0:c77591fc308d | 125 | WaitForMeasurement* int3; |
charlesmn | 0:c77591fc308d | 126 | |
charlesmn | 0:c77591fc308d | 127 | pc.baud(115200); // baud rate is important as printf statements take a lot of time |
charlesmn | 0:c77591fc308d | 128 | |
charlesmn | 0:c77591fc308d | 129 | printf("Hello world!\r\n"); |
charlesmn | 0:c77591fc308d | 130 | |
charlesmn | 2:86876e590f28 | 131 | vl53L3_DevI2C *dev_I2C = new vl53L3_DevI2C(I2C_SDA, I2C_SCL); |
charlesmn | 0:c77591fc308d | 132 | |
charlesmn | 0:c77591fc308d | 133 | /* creates the 53L1A1 expansion board singleton obj */ |
johnAlexander | 3:42c96c9c627b | 134 | board = XNucleo53L3A2::instance(dev_I2C, A2, D8, D2); |
charlesmn | 0:c77591fc308d | 135 | printf("board created!\r\n"); |
charlesmn | 0:c77591fc308d | 136 | |
charlesmn | 0:c77591fc308d | 137 | /* init the 53L1A1 expansion board with default values */ |
charlesmn | 0:c77591fc308d | 138 | status = board->init_board(); |
charlesmn | 0:c77591fc308d | 139 | if (status) { |
charlesmn | 0:c77591fc308d | 140 | printf("Failed to init board!\r\n"); |
charlesmn | 0:c77591fc308d | 141 | return 0; |
charlesmn | 0:c77591fc308d | 142 | } |
johnAlexander | 5:92a861d48253 | 143 | |
johnAlexander | 5:92a861d48253 | 144 | |
charlesmn | 0:c77591fc308d | 145 | printf("board initiated! - %d\r\n", status); |
johnAlexander | 5:92a861d48253 | 146 | |
johnAlexander | 5:92a861d48253 | 147 | for (ToFSensor=0; ToFSensor<3; ToFSensor++) { |
charlesmn | 0:c77591fc308d | 148 | wait_ms(15); |
johnAlexander | 5:92a861d48253 | 149 | switch(ToFSensor) { |
charlesmn | 0:c77591fc308d | 150 | case 0: |
charlesmn | 0:c77591fc308d | 151 | if (board->sensor_centre== NULL ) continue; |
charlesmn | 0:c77591fc308d | 152 | Dev=&devCentre; |
charlesmn | 0:c77591fc308d | 153 | Sensor=board->sensor_centre; |
charlesmn | 0:c77591fc308d | 154 | Dev->I2cDevAddr = NEW_SENSOR_CENTRE_ADDRESS; |
charlesmn | 0:c77591fc308d | 155 | printf("configuring centre channel \n"); |
charlesmn | 0:c77591fc308d | 156 | break; |
charlesmn | 0:c77591fc308d | 157 | case 1: |
charlesmn | 0:c77591fc308d | 158 | if (board->sensor_left== NULL ) continue; |
johnAlexander | 5:92a861d48253 | 159 | Dev=&devLeft; |
charlesmn | 0:c77591fc308d | 160 | Sensor=board->sensor_left; |
charlesmn | 0:c77591fc308d | 161 | Dev->I2cDevAddr = NEW_SENSOR_LEFT_ADDRESS; |
charlesmn | 0:c77591fc308d | 162 | printf("configuring left channel \n"); |
charlesmn | 0:c77591fc308d | 163 | break; |
charlesmn | 0:c77591fc308d | 164 | case 2: |
charlesmn | 0:c77591fc308d | 165 | if (board->sensor_right== NULL ) continue; |
johnAlexander | 5:92a861d48253 | 166 | Dev=&devRight; |
charlesmn | 0:c77591fc308d | 167 | Sensor=board->sensor_right; |
charlesmn | 0:c77591fc308d | 168 | Dev->I2cDevAddr = NEW_SENSOR_RIGHT_ADDRESS; |
charlesmn | 0:c77591fc308d | 169 | printf("configuring right channel \n"); |
johnAlexander | 5:92a861d48253 | 170 | break; |
charlesmn | 0:c77591fc308d | 171 | default: |
johnAlexander | 5:92a861d48253 | 172 | printf(" error in switch, invalid ToF sensor \n"); |
charlesmn | 0:c77591fc308d | 173 | } |
johnAlexander | 5:92a861d48253 | 174 | |
charlesmn | 0:c77591fc308d | 175 | // configure the sensors |
charlesmn | 0:c77591fc308d | 176 | Dev->comms_speed_khz = 400; |
charlesmn | 0:c77591fc308d | 177 | |
charlesmn | 0:c77591fc308d | 178 | Dev->comms_type = 1; |
charlesmn | 0:c77591fc308d | 179 | |
charlesmn | 0:c77591fc308d | 180 | Sensor->VL53LX_RdWord(Dev, 0x01, &wordData); |
charlesmn | 0:c77591fc308d | 181 | printf("VL53L1X: %02X %d\n\r", wordData,Dev->I2cDevAddr); |
johnAlexander | 5:92a861d48253 | 182 | /* Device Initialization and setting */ |
charlesmn | 0:c77591fc308d | 183 | |
charlesmn | 0:c77591fc308d | 184 | status = Sensor->VL53LX_DataInit(); |
charlesmn | 0:c77591fc308d | 185 | status = Sensor->VL53LX_SetDistanceMode(VL53LX_DISTANCEMODE_LONG); |
johnAlexander | 5:92a861d48253 | 186 | status = Sensor->VL53LX_SetMeasurementTimingBudgetMicroSeconds( MEASUREMENTTIMING * 1000); |
charlesmn | 0:c77591fc308d | 187 | status = Sensor->VL53LX_SmudgeCorrectionEnable(VL53LX_SMUDGE_CORRECTION_SINGLE); |
charlesmn | 0:c77591fc308d | 188 | status = Sensor->VL53LX_SetXTalkCompensationEnable(1); |
charlesmn | 0:c77591fc308d | 189 | |
johnAlexander | 5:92a861d48253 | 190 | |
johnAlexander | 5:92a861d48253 | 191 | } |
johnAlexander | 5:92a861d48253 | 192 | |
johnAlexander | 5:92a861d48253 | 193 | if (board->sensor_centre!= NULL ) { |
johnAlexander | 5:92a861d48253 | 194 | printf("starting interrupt centre\n"); |
johnAlexander | 5:92a861d48253 | 195 | Sensor=board->sensor_centre; |
johnAlexander | 5:92a861d48253 | 196 | devCentre.I2cDevAddr = NEW_SENSOR_CENTRE_ADDRESS; |
johnAlexander | 5:92a861d48253 | 197 | int1 = new WaitForMeasurement(A2,&devCentre); |
johnAlexander | 5:92a861d48253 | 198 | status = Sensor->VL53LX_StartMeasurement(); |
johnAlexander | 5:92a861d48253 | 199 | printf("VL53L1_StartMeasurement %d \n",status); |
johnAlexander | 5:92a861d48253 | 200 | status = board->sensor_centre->VL53LX_ClearInterruptAndStartMeasurement(); |
johnAlexander | 5:92a861d48253 | 201 | } |
johnAlexander | 5:92a861d48253 | 202 | |
johnAlexander | 5:92a861d48253 | 203 | |
johnAlexander | 5:92a861d48253 | 204 | if (board->sensor_left!= NULL ) { |
johnAlexander | 5:92a861d48253 | 205 | printf("starting interrupt left\n"); |
johnAlexander | 5:92a861d48253 | 206 | Sensor=board->sensor_left; |
johnAlexander | 5:92a861d48253 | 207 | devLeft.I2cDevAddr = NEW_SENSOR_LEFT_ADDRESS; |
johnAlexander | 5:92a861d48253 | 208 | int2 = new WaitForMeasurement(D8,&devLeft); |
johnAlexander | 5:92a861d48253 | 209 | status = Sensor->VL53LX_StartMeasurement(); |
johnAlexander | 5:92a861d48253 | 210 | printf("VL53L1_StartMeasurement %d \n",status); |
johnAlexander | 5:92a861d48253 | 211 | status = board->sensor_left->VL53LX_ClearInterruptAndStartMeasurement(); |
johnAlexander | 5:92a861d48253 | 212 | } |
johnAlexander | 5:92a861d48253 | 213 | |
johnAlexander | 5:92a861d48253 | 214 | if (board->sensor_right!= NULL ) { |
johnAlexander | 5:92a861d48253 | 215 | printf("starting interrupt right\n"); |
johnAlexander | 5:92a861d48253 | 216 | Sensor=board->sensor_right; |
johnAlexander | 5:92a861d48253 | 217 | devRight.I2cDevAddr = NEW_SENSOR_RIGHT_ADDRESS; |
johnAlexander | 5:92a861d48253 | 218 | int3 = new WaitForMeasurement(D2,&devRight); |
johnAlexander | 5:92a861d48253 | 219 | status = Sensor->VL53LX_StartMeasurement(); |
johnAlexander | 5:92a861d48253 | 220 | printf("VL53L1_StartMeasurement %d \n",status); |
johnAlexander | 5:92a861d48253 | 221 | status = board->sensor_right->VL53LX_ClearInterruptAndStartMeasurement(); |
johnAlexander | 5:92a861d48253 | 222 | } |
johnAlexander | 5:92a861d48253 | 223 | |
johnAlexander | 5:92a861d48253 | 224 | |
johnAlexander | 5:92a861d48253 | 225 | // loop waiting for interrupts to happen. This is signaled by int_centre_result,int_left_result or int_right_result |
johnAlexander | 5:92a861d48253 | 226 | // being non zero. The are set back to zero when processing is completed |
johnAlexander | 5:92a861d48253 | 227 | while (1) { |
johnAlexander | 5:92a861d48253 | 228 | |
johnAlexander | 5:92a861d48253 | 229 | VL53LX_MultiRangingData_t MultiRangingData; |
johnAlexander | 5:92a861d48253 | 230 | VL53LX_MultiRangingData_t *pMultiRangingData = &MultiRangingData; |
johnAlexander | 5:92a861d48253 | 231 | |
johnAlexander | 5:92a861d48253 | 232 | wait_ms(10); |
johnAlexander | 5:92a861d48253 | 233 | |
johnAlexander | 5:92a861d48253 | 234 | if (int_centre_result != 0) { |
johnAlexander | 5:92a861d48253 | 235 | int_centre_result = 0; |
johnAlexander | 5:92a861d48253 | 236 | status = board->sensor_centre->VL53LX_GetMultiRangingData( pMultiRangingData); |
johnAlexander | 5:92a861d48253 | 237 | int no_of_object_found=pMultiRangingData->NumberOfObjectsFound; |
johnAlexander | 5:92a861d48253 | 238 | if (( no_of_object_found < 10 ) && ( no_of_object_found != 0 )) { |
johnAlexander | 5:92a861d48253 | 239 | for(int j=0; j<no_of_object_found; j++) { |
johnAlexander | 5:92a861d48253 | 240 | if (pMultiRangingData->RangeData[j].RangeStatus == 0) { |
johnAlexander | 5:92a861d48253 | 241 | printf("centre\t status=%d, \t D=%5dmm, \t Signal=%2.2f Mcps, \t Ambient=%2.2f Mcps \n", |
johnAlexander | 5:92a861d48253 | 242 | pMultiRangingData->RangeData[j].RangeStatus, |
johnAlexander | 5:92a861d48253 | 243 | pMultiRangingData->RangeData[j].RangeMilliMeter, |
johnAlexander | 5:92a861d48253 | 244 | (pMultiRangingData->RangeData[j].SignalRateRtnMegaCps/65535.0), |
johnAlexander | 5:92a861d48253 | 245 | (pMultiRangingData->RangeData[j].AmbientRateRtnMegaCps/65535.0)); |
johnAlexander | 5:92a861d48253 | 246 | } |
johnAlexander | 5:92a861d48253 | 247 | } |
johnAlexander | 5:92a861d48253 | 248 | } |
johnAlexander | 5:92a861d48253 | 249 | int_centre_result = 0; |
johnAlexander | 5:92a861d48253 | 250 | wait_ms( MEASUREMENTTIMING ); |
charlesmn | 0:c77591fc308d | 251 | status = board->sensor_centre->VL53LX_ClearInterruptAndStartMeasurement(); |
charlesmn | 0:c77591fc308d | 252 | } |
johnAlexander | 5:92a861d48253 | 253 | |
charlesmn | 0:c77591fc308d | 254 | |
johnAlexander | 5:92a861d48253 | 255 | if (int_left_result != 0) { |
johnAlexander | 5:92a861d48253 | 256 | int_left_result = 0; |
johnAlexander | 5:92a861d48253 | 257 | status = board->sensor_left->VL53LX_GetMultiRangingData( pMultiRangingData); |
johnAlexander | 5:92a861d48253 | 258 | if ( status == 0) { |
johnAlexander | 5:92a861d48253 | 259 | int no_of_object_found=pMultiRangingData->NumberOfObjectsFound; |
johnAlexander | 5:92a861d48253 | 260 | if (( no_of_object_found < 10 ) && ( no_of_object_found != 0 )) { |
johnAlexander | 5:92a861d48253 | 261 | for(int j=0; j<no_of_object_found; j++) { |
johnAlexander | 5:92a861d48253 | 262 | if (pMultiRangingData->RangeData[j].RangeStatus == 0) { |
johnAlexander | 5:92a861d48253 | 263 | printf("left \t status=%d, \t D=%5dmm, \t Signal=%2.2f Mcps, \t Ambient=%2.2f Mcps \n", |
johnAlexander | 5:92a861d48253 | 264 | pMultiRangingData->RangeData[j].RangeStatus, |
johnAlexander | 5:92a861d48253 | 265 | pMultiRangingData->RangeData[j].RangeMilliMeter, |
johnAlexander | 5:92a861d48253 | 266 | (pMultiRangingData->RangeData[j].SignalRateRtnMegaCps / 65535.0), |
johnAlexander | 5:92a861d48253 | 267 | (pMultiRangingData->RangeData[j].AmbientRateRtnMegaCps / 65535.0) ); |
johnAlexander | 5:92a861d48253 | 268 | } |
johnAlexander | 5:92a861d48253 | 269 | } |
johnAlexander | 5:92a861d48253 | 270 | } |
johnAlexander | 5:92a861d48253 | 271 | } |
johnAlexander | 5:92a861d48253 | 272 | wait_ms( MEASUREMENTTIMING ); |
charlesmn | 0:c77591fc308d | 273 | status = board->sensor_left->VL53LX_ClearInterruptAndStartMeasurement(); |
charlesmn | 0:c77591fc308d | 274 | } |
charlesmn | 0:c77591fc308d | 275 | |
charlesmn | 0:c77591fc308d | 276 | |
johnAlexander | 5:92a861d48253 | 277 | if (int_right_result != 0) { |
johnAlexander | 5:92a861d48253 | 278 | // clear interrupt flag |
johnAlexander | 5:92a861d48253 | 279 | int_right_result = 0; |
johnAlexander | 5:92a861d48253 | 280 | status = board->sensor_right->VL53LX_GetMultiRangingData( pMultiRangingData); |
johnAlexander | 5:92a861d48253 | 281 | if ( status == 0) { |
johnAlexander | 5:92a861d48253 | 282 | // if valid result print it |
charlesmn | 0:c77591fc308d | 283 | int no_of_object_found=pMultiRangingData->NumberOfObjectsFound; |
johnAlexander | 5:92a861d48253 | 284 | if (( no_of_object_found < 10 ) && ( no_of_object_found != 0 )) { |
johnAlexander | 5:92a861d48253 | 285 | for(int j=0; j<no_of_object_found; j++) { |
johnAlexander | 5:92a861d48253 | 286 | if (pMultiRangingData->RangeData[j].RangeStatus == 0) { |
johnAlexander | 5:92a861d48253 | 287 | printf("right \t status=%d, \t D=%5dmm, \t Signal=%2.2f Mcps, \t Ambient=%2.2f Mcps \n", |
johnAlexander | 5:92a861d48253 | 288 | pMultiRangingData->RangeData[j].RangeStatus, |
johnAlexander | 5:92a861d48253 | 289 | pMultiRangingData->RangeData[j].RangeMilliMeter, |
johnAlexander | 5:92a861d48253 | 290 | (pMultiRangingData->RangeData[j].SignalRateRtnMegaCps/65535.0), |
johnAlexander | 5:92a861d48253 | 291 | (pMultiRangingData->RangeData[j].AmbientRateRtnMegaCps/65535.0) ); |
charlesmn | 0:c77591fc308d | 292 | } |
charlesmn | 0:c77591fc308d | 293 | } |
charlesmn | 0:c77591fc308d | 294 | } |
charlesmn | 0:c77591fc308d | 295 | } |
johnAlexander | 5:92a861d48253 | 296 | wait_ms( MEASUREMENTTIMING ); |
johnAlexander | 5:92a861d48253 | 297 | // clear theinterrupt and wait for another result |
johnAlexander | 5:92a861d48253 | 298 | status = board->sensor_right->VL53LX_ClearInterruptAndStartMeasurement(); |
charlesmn | 0:c77591fc308d | 299 | |
johnAlexander | 5:92a861d48253 | 300 | } |
johnAlexander | 5:92a861d48253 | 301 | } |
johnAlexander | 5:92a861d48253 | 302 | printf("terminated"); |
johnAlexander | 5:92a861d48253 | 303 | } |
charlesmn | 0:c77591fc308d | 304 | |
johnAlexander | 3:42c96c9c627b | 305 | #if (MBED_VERSION > 60300) |
johnAlexander | 3:42c96c9c627b | 306 | extern "C" void wait_ms(int ms) |
johnAlexander | 5:92a861d48253 | 307 | { |
johnAlexander | 3:42c96c9c627b | 308 | thread_sleep_for(ms); |
johnAlexander | 5:92a861d48253 | 309 | } |
johnAlexander | 3:42c96c9c627b | 310 | #endif |
charlesmn | 0:c77591fc308d | 311 |