as per name
Dependencies: VL53L1CB
Revision 4:64f1d9db74fa, committed 2021-06-23
- Comitter:
- johnAlexander
- Date:
- Wed Jun 23 14:52:32 2021 +0000
- Parent:
- 3:1fcfc77e6dae
- Child:
- 5:c59b6c183c8c
- Commit message:
- Use sensor class exposing default constructor.
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/VL53L1CB.lib Wed Jun 23 14:52:32 2021 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/teams/ST-Expansion-SW-Team/code/VL53L1CB/#ca0ce4daf573
--- a/X_NUCLEO_53L1A2.lib Mon Jun 21 08:04:21 2021 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://os.mbed.com/teams/ST-Expansion-SW-Team/code/X_NUCLEO_53L1A2/#7f3717ad9007
--- a/main.cpp Mon Jun 21 08:04:21 2021 +0000
+++ b/main.cpp Wed Jun 23 14:52:32 2021 +0000
@@ -1,10 +1,17 @@
/*
- * This VL53L1CB Expansion board test application performs range measurements
- * using the onboard embedded sensor, in polling mode.
+ * This VL53L1CB test application performs range measurements, using a satellite
+ * board plugged directly in to the motherboard.
* Measured ranges are ouput on the Serial Port, running at 115200 baud.
*
* This is designed to work with MBed v2.x, & MBedOS v5.x / v6.x.
*
+ * The satellite board is expected to be connected as follows :
+ *
+ * I2C_SDA D14 / Arduino Connector CN5, pin 9
+ * I2C_SCL D15 / Arduino Connector CN5, pin 10
+ * Sensor xShutdown D07 / Arduino Connector CN9, pin 8
+ * Sensor Interrupt A02 / Arduino Connector CN8, pin 3
+ *
* The Reset button can be used to restart the program.
*
* *** NOTE :
@@ -35,7 +42,7 @@
#include "mbed.h"
-#include "NoShield53L1A1.h"
+#include "VL53L1CB.h"
#include "ToF_I2C.h"
// i2c comms port pins
@@ -56,7 +63,7 @@
PinName LeftIntPin = D9;
//PinName RightIntPin = D4;
-static NoShield53L1 *board=NULL;
+//static NoShield53L1 *board=NULL;
#if (MBED_VERSION > 60300)
UnbufferedSerial pc(USBTX, USBRX);
@@ -68,37 +75,15 @@
void print_results(int devNumber, VL53L1_MultiRangingData_t *pMultiRangingData );
-VL53L1_Dev_t devCentre;
-VL53L1_DEV Dev = &devCentre;
-VL53L1CB *Sensor;
-
-
+VL53L1CB *Sensor = NULL;
-/* flags that handle interrupt request for sensor and user blue button*/
-volatile bool int_sensor = false;
-volatile bool int_stop = false;
-
-/* ISR callback function of the centre sensor */
-void sensor_irq(void)
-{
- int_sensor = true;
- board->sensor_centre->disable_interrupt_measure_detection_irq();
-}
/* Start the sensor ranging */
int init_sensor()
{
int status = 0;
- Dev=&devCentre;
- Sensor=board->sensor_centre;
-
- // configure the sensors
- Dev->comms_speed_khz = 400;
- Dev->comms_type = 1;
- Dev->i2c_slave_address = NEW_SENSOR_CENTRE_ADDRESS;
-
- printf("configuring centre channel \n");
+ printf("configuring sensor \n");
/* Device Initialization and setting */
status = Sensor->VL53L1CB_DataInit();
@@ -115,8 +100,8 @@
status = Sensor->VL53L1CB_SetSequenceStepEnable(VL53L1_SEQUENCESTEP_MM2, 0);
// create interrupt handler and start measurements
- if (board->sensor_centre!= NULL) {
- status = board->sensor_centre->stop_measurement();
+ if (Sensor != NULL) {
+ status = Sensor->stop_measurement();
if (status != 0) {
return status;
}
@@ -129,17 +114,14 @@
return status;
}
-/* ISR callback function of the user blue button to switch measuring sensor. */
-void measuring_stop_irq(void)
-{
- int_stop = true;
-}
/*=================================== Main ==================================
=============================================================================*/
int main()
{
int status;
+
+ DigitalOut xshutdown(D7);
pc.baud(115200); // baud rate is important as printf statements take a lot of time
@@ -147,24 +129,25 @@
/* create i2c interface */
ToF_DevI2C *dev_I2C = new ToF_DevI2C(I2C_SDA, I2C_SCL);
+
/* creates the sensor singleton obj */
- board = NoShield53L1::instance(dev_I2C, A2, D8, D2);
+ Sensor = new VL53L1CB(dev_I2C, &xshutdown, A2);
- printf("board created!\r\n");
+ printf("sensor created!\r\n");
/* init the sensor interface with default values */
- status = board->init_board(D9,D4,D3);
+ status = Sensor->InitSensor(0x52);
if (status) {
- printf("Failed to init board!\r\n");
+ printf("Failed to init sensor!\r\n");
return status;
}
- printf("board initiated! - %d\r\n", status);
+ printf("sensor initialised! - %d\r\n", status);
/* init an array with chars to id the sensors */
status = init_sensor();
if (status != 0) {
- printf("Failed to init sensors!\r\n");
+ printf("Failed to configure sensors!\r\n");
return status;
}
@@ -178,12 +161,12 @@
while (true) {
pMultiRangingData = &MultiRangingData;
- status = board->sensor_centre->VL53L1CB_WaitMeasurementDataReady();
+ status = Sensor->VL53L1CB_WaitMeasurementDataReady();
if ( status == 0) {
- status = board->sensor_centre->VL53L1CB_GetMultiRangingData( pMultiRangingData);
- print_results( devCentre.i2c_slave_address, pMultiRangingData );
+ status = Sensor->VL53L1CB_GetMultiRangingData( pMultiRangingData);
+ print_results( 0x52, pMultiRangingData );
}
- status = board->sensor_centre->VL53L1CB_ClearInterrupt();
+ status = Sensor->VL53L1CB_ClearInterrupt();
}
printf("Terminating.\n");