as per name
Dependencies: VL53L1CB
Revision 5:c59b6c183c8c, committed 2021-06-24
- Comitter:
- johnAlexander
- Date:
- Thu Jun 24 12:36:04 2021 +0000
- Parent:
- 4:64f1d9db74fa
- Commit message:
- Use default sensor constructor. Add delay after power-on, before init sequence.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 64f1d9db74fa -r c59b6c183c8c main.cpp --- a/main.cpp Wed Jun 23 14:52:32 2021 +0000 +++ b/main.cpp Thu Jun 24 12:36:04 2021 +0000 @@ -50,7 +50,8 @@ #define I2C_SCL D15 -#define NUM_SENSORS 3 +#define NEW_SENSOR_CENTRE_ADDRESS 0x52 + // define interrupt pins PinName CentreIntPin = A2; @@ -63,7 +64,6 @@ PinName LeftIntPin = D9; //PinName RightIntPin = D4; -//static NoShield53L1 *board=NULL; #if (MBED_VERSION > 60300) UnbufferedSerial pc(USBTX, USBRX); @@ -75,7 +75,7 @@ void print_results(int devNumber, VL53L1_MultiRangingData_t *pMultiRangingData ); -VL53L1CB *Sensor = NULL; +VL53L1CB *Sensor; /* Start the sensor ranging */ @@ -83,7 +83,7 @@ { int status = 0; - printf("configuring sensor \n"); + printf("configuring sensor\n"); /* Device Initialization and setting */ status = Sensor->VL53L1CB_DataInit(); @@ -99,8 +99,9 @@ status = Sensor->VL53L1CB_SetSequenceStepEnable(VL53L1_SEQUENCESTEP_MM1, 0); status = Sensor->VL53L1CB_SetSequenceStepEnable(VL53L1_SEQUENCESTEP_MM2, 0); + // create interrupt handler and start measurements - if (Sensor != NULL) { + if (Sensor != NULL) { status = Sensor->stop_measurement(); if (status != 0) { return status; @@ -120,34 +121,45 @@ int main() { int status; - DigitalOut xshutdown(D7); + pc.baud(115200); // baud rate is important as printf statements take a lot of time printf("mbed version : %d \r\n",MBED_VERSION); - /* create i2c interface */ +// create i2c interface ToF_DevI2C *dev_I2C = new ToF_DevI2C(I2C_SDA, I2C_SCL); - - /* creates the sensor singleton obj */ + Sensor = new VL53L1CB(dev_I2C, &xshutdown, A2); printf("sensor created!\r\n"); - /* init the sensor interface with default values */ - status = Sensor->InitSensor(0x52); + /* init the 53L1A1 expansion board with default values */ + Sensor->VL53L1CB_Off(); + + Sensor->VL53L1CB_On(); + status = Sensor->InitSensor(NEW_SENSOR_CENTRE_ADDRESS); if (status) { - printf("Failed to init sensor!\r\n"); - return status; + delete Sensor; + Sensor = NULL; + printf("Sensor not present\n\r"); + } else { + printf("Sensor present\n\r"); } - printf("sensor initialised! - %d\r\n", status); +#if (MBED_VERSION > 60300) + thread_sleep_for(100); +#else + wait_ms(100); // NEEDS A DELAY BETWEEN SENSORS +#endif + + printf("board initialised! - %d\r\n", status); /* init an array with chars to id the sensors */ status = init_sensor(); if (status != 0) { - printf("Failed to configure sensors!\r\n"); + printf("Failed to init sensors!\r\n"); return status; } @@ -156,16 +168,15 @@ VL53L1_MultiRangingData_t MultiRangingData; VL53L1_MultiRangingData_t *pMultiRangingData = NULL; - // polling for data. VL53L1CB_WaitMeasurementDataReady returns when data or after a timeout - // ignore the timeouts i.e. status != 0 while (true) { pMultiRangingData = &MultiRangingData; status = Sensor->VL53L1CB_WaitMeasurementDataReady(); - if ( status == 0) { - status = Sensor->VL53L1CB_GetMultiRangingData( pMultiRangingData); - print_results( 0x52, pMultiRangingData ); - } + + status = Sensor->VL53L1CB_GetMultiRangingData( pMultiRangingData); + + print_results(NEW_SENSOR_CENTRE_ADDRESS, pMultiRangingData ); + status = Sensor->VL53L1CB_ClearInterrupt(); } @@ -193,13 +204,23 @@ pMultiRangingData->RangeData[j].RangeStatus, pMultiRangingData->RangeData[j].RangeMilliMeter, signal_rate, - ambient_rate); + ambient_rate); +/* +// online compiler disables printf() / floating-point support, for code-size reasons. +// offline compiler can switch it on. + printf("\t i2cAddr=%d \t RoiNumber=%d \t status=%d, \t D=%5dmm, \t Signal=%2.2f Mcps, \t Ambient=%2.2f Mcps \n", + devNumber, RoiNumber, + pMultiRangingData->RangeData[j].RangeStatus, + pMultiRangingData->RangeData[j].RangeMilliMeter, + pMultiRangingData->RangeData[j].SignalRateRtnMegaCps / 65535.0, + pMultiRangingData->RangeData[j].AmbientRateRtnMegaCps / 65535.0); +*/ } } } // if (( no_of_object_found < 10 ) && ( no_of_object_found != 0)) } -// wait_ms does not exist in later mbeds so create our own. + #if (MBED_VERSION > 60300) extern "C" void wait_ms(int ms) { @@ -208,4 +229,3 @@ #endif -