remove the setting of VL53L1CB_SetThresholdConfig() from main.c
Dependencies: VL53L1CB
Revision 2:42baa92189c9, committed 2021-06-24
- Comitter:
- johnAlexander
- Date:
- Thu Jun 24 12:48:51 2021 +0000
- Parent:
- 1:4bbc3be70bc9
- Commit message:
- Use sensor class with default constructor enabled.
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/VL53L1CB.lib Thu Jun 24 12:48:51 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:09:02 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:09:02 2021 +0000
+++ b/main.cpp Thu Jun 24 12:48:51 2021 +0000
@@ -1,10 +1,17 @@
/*
- * This VL53L1CB test application performs range measurements
- * using the onboard embedded sensor, in interrupt mode.
+ * This VL53L1CB test application performs range measurements, in interrupt mode,
+ * 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
@@ -43,7 +50,7 @@
#define I2C_SCL D15
-#define NUM_SENSORS 3
+#define NEW_SENSOR_CENTRE_ADDRESS 0x52
// define interrupt pins
PinName CentreIntPin = A2;
@@ -56,7 +63,6 @@
PinName LeftIntPin = D9;
//PinName RightIntPin = D4;
-static NoShield53L1 *board=NULL;
#if (MBED_VERSION > 60300)
UnbufferedSerial pc(USBTX, USBRX);
@@ -68,9 +74,7 @@
void print_results(int devNumber, VL53L1_MultiRangingData_t *pMultiRangingData );
-VL53L1_Dev_t devCentre;
-VL53L1_DEV Dev = &devCentre;
-VL53L1CB *Sensor;
+VL53L1CB *Sensor = NULL;
@@ -82,7 +86,13 @@
void sensor_irq(void)
{
int_sensor = true;
- board->sensor_centre->disable_interrupt_measure_detection_irq();
+ Sensor->disable_interrupt_measure_detection_irq();
+}
+
+/* ISR callback function of the user blue button to switch measuring sensor. */
+void measuring_stop_irq(void)
+{
+ int_stop = true;
}
/* Start the sensor ranging */
@@ -90,15 +100,7 @@
{
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();
@@ -117,14 +119,13 @@
status = Sensor->VL53L1CB_GetDeviceInfo(&device_info);
printf("device name %s \n",device_info.Name);
-
// 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;
}
- wait_ms(100);
+
status = Sensor->start_measurement(&sensor_irq);
if (status != 0) {
return status;
@@ -133,11 +134,6 @@
return status;
}
-/* ISR callback function of the user blue button to switch measuring sensor. */
-void measuring_stop_irq(void)
-{
- int_stop = true;
-}
/*=================================== Main ==================================
=============================================================================*/
@@ -145,25 +141,40 @@
{
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 */
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 53L1A1 expansion board with default values */
+ Sensor->VL53L1CB_Off();
- /* init the sensor interface with default values */
- status = board->init_board(D9,D4,D3);
+ Sensor->VL53L1CB_On();
+ status = Sensor->InitSensor(NEW_SENSOR_CENTRE_ADDRESS);
if (status) {
- printf("Failed to init board!\r\n");
- return status;
+ delete Sensor;
+ Sensor = NULL;
+ printf("Sensor not present\n\r");
+ } else {
+ printf("Sensor present\n\r");
}
- printf("board initiated! - %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();
@@ -183,12 +194,12 @@
if (int_sensor) { // if interrupt happened
int_sensor = false;
- status = board->sensor_centre->VL53L1CB_GetMultiRangingData( pMultiRangingData);
+ status = Sensor->VL53L1CB_GetMultiRangingData( pMultiRangingData);
if (status == 0) {
- print_results( devCentre.i2c_slave_address, pMultiRangingData );
- status = board->sensor_centre->VL53L1CB_ClearInterrupt();
+ print_results(NEW_SENSOR_CENTRE_ADDRESS, pMultiRangingData );
+ status = Sensor->VL53L1CB_ClearInterrupt();
}
- board->sensor_centre->enable_interrupt_measure_detection_irq();
+ Sensor->enable_interrupt_measure_detection_irq();
}
}