Lecture des données en 4x4
This commit is contained in:
commit
19d50b56fa
30 files changed
+28570
No files matched your search
@@ -0,0 +1,204 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2020, STMicroelectronics - All Rights Reserved
|
||||
*
|
||||
* This file is part of the VL53L8CX Ultra Lite Driver and is dual licensed,
|
||||
* either 'STMicroelectronics Proprietary license'
|
||||
* or 'BSD 3-clause "New" or "Revised" License' , at your option.
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* 'STMicroelectronics Proprietary license'
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* License terms: STMicroelectronics Proprietary in accordance with licensing
|
||||
* terms at www.st.com/sla0081
|
||||
*
|
||||
* STMicroelectronics confidential
|
||||
* Reproduction and Communication of this document is strictly prohibited unless
|
||||
* specifically authorized in writing by STMicroelectronics.
|
||||
*
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* Alternatively, the VL53L8CX Ultra Lite Driver may be distributed under the
|
||||
* terms of 'BSD 3-clause "New" or "Revised" License', in which case the
|
||||
* following provisions apply instead of the ones mentioned above :
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* License terms: BSD 3-clause "New" or "Revised" License.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/***********************************/
|
||||
/* VL53L8CX ULD motion indicator */
|
||||
/***********************************/
|
||||
/*
|
||||
* This example shows the VL53L8CX motion indicator capabilities.
|
||||
* To use this example, user needs to be sure that macro
|
||||
* VL53L8CX_DISABLE_MOTION_INDICATOR is NOT enabled (see file platform.h).
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "vl53l8cx_api.h"
|
||||
#include "vl53l8cx_plugin_motion_indicator.h"
|
||||
|
||||
int example10(void)
|
||||
{
|
||||
|
||||
/*********************************/
|
||||
/* VL53L8CX ranging variables */
|
||||
/*********************************/
|
||||
|
||||
uint8_t status, loop, isAlive, isReady, i;
|
||||
VL53L8CX_Configuration Dev; /* Sensor configuration */
|
||||
VL53L8CX_Motion_Configuration motion_config; /* Motion configuration*/
|
||||
VL53L8CX_ResultsData Results; /* Results data from VL53L8CX */
|
||||
|
||||
|
||||
/*********************************/
|
||||
/* Customer platform */
|
||||
/*********************************/
|
||||
|
||||
/* Fill the platform structure with customer's implementation. For this
|
||||
* example, only the I2C address is used.
|
||||
*/
|
||||
Dev.platform.address = VL53L8CX_DEFAULT_I2C_ADDRESS;
|
||||
|
||||
/* (Optional) Reset sensor toggling PINs (see platform, not in API) */
|
||||
//Reset_Sensor(&(Dev.platform));
|
||||
|
||||
/* (Optional) Set a new I2C address if the wanted address is different
|
||||
* from the default one (filled with 0x20 for this example).
|
||||
*/
|
||||
//status = vl53l8cx_set_i2c_address(&Dev, 0x20);
|
||||
|
||||
|
||||
/*********************************/
|
||||
/* Power on sensor and init */
|
||||
/*********************************/
|
||||
|
||||
/* (Optional) Check if there is a VL53L8CX sensor connected */
|
||||
status = vl53l8cx_is_alive(&Dev, &isAlive);
|
||||
if(!isAlive || status)
|
||||
{
|
||||
printf("VL53L8CX not detected at requested address\n");
|
||||
return status;
|
||||
}
|
||||
|
||||
/* (Mandatory) Init VL53L8CX sensor */
|
||||
status = vl53l8cx_init(&Dev);
|
||||
if(status)
|
||||
{
|
||||
printf("VL53L8CX ULD Loading failed\n");
|
||||
return status;
|
||||
}
|
||||
|
||||
printf("VL53L8CX ULD ready ! (Version : %s)\n",
|
||||
VL53L8CX_API_REVISION);
|
||||
|
||||
|
||||
/*********************************/
|
||||
/* Program motion indicator */
|
||||
/*********************************/
|
||||
|
||||
/* Create motion indicator with resolution 4x4 */
|
||||
status = vl53l8cx_motion_indicator_init(&Dev, &motion_config, VL53L8CX_RESOLUTION_4X4);
|
||||
if(status)
|
||||
{
|
||||
printf("Motion indicator init failed with status : %u\n", status);
|
||||
return status;
|
||||
}
|
||||
|
||||
/* (Optional) Change the min and max distance used to detect motions. The
|
||||
* difference between min and max must never be >1500mm, and minimum never be <400mm,
|
||||
* otherwise the function below returns error 127 */
|
||||
status = vl53l8cx_motion_indicator_set_distance_motion(&Dev, &motion_config, 1000, 2000);
|
||||
if(status)
|
||||
{
|
||||
printf("Motion indicator set distance motion failed with status : %u\n", status);
|
||||
return status;
|
||||
}
|
||||
|
||||
/* If user want to change the resolution, he also needs to update the motion indicator resolution */
|
||||
//status = vl53l8cx_set_resolution(&Dev, VL53L8CX_RESOLUTION_4X4);
|
||||
//status = vl53l8cx_motion_indicator_set_resolution(&Dev, &motion_config, VL53L8CX_RESOLUTION_4X4);
|
||||
|
||||
/* Increase ranging frequency for the example */
|
||||
status = vl53l8cx_set_ranging_frequency_hz(&Dev, 2);
|
||||
|
||||
|
||||
/*********************************/
|
||||
/* Ranging loop */
|
||||
/*********************************/
|
||||
|
||||
status = vl53l8cx_start_ranging(&Dev);
|
||||
|
||||
loop = 0;
|
||||
while(loop < 10)
|
||||
{
|
||||
/* Use polling function to know when a new measurement is ready.
|
||||
* Another way can be to wait for HW interrupt raised on PIN A1
|
||||
* (INT) when a new measurement is ready */
|
||||
|
||||
status = vl53l8cx_check_data_ready(&Dev, &isReady);
|
||||
|
||||
if(isReady)
|
||||
{
|
||||
vl53l8cx_get_ranging_data(&Dev, &Results);
|
||||
|
||||
/* As the sensor is set in 4x4 mode by default, we have a total
|
||||
* of 16 zones to print. For this example, only the data of first zone are
|
||||
* print */
|
||||
printf("Print data no : %3u\n", Dev.streamcount);
|
||||
for(i = 0; i < 16; i++)
|
||||
{
|
||||
printf("Zone : %3d, Motion power : %3lu\n",
|
||||
i,
|
||||
Results.motion_indicator.motion[motion_config.map_id[i]]);
|
||||
}
|
||||
printf("\n");
|
||||
loop++;
|
||||
}
|
||||
|
||||
/* Wait a few ms to avoid too high polling (function in platform
|
||||
* file, not in API) */
|
||||
WaitMs(&(Dev.platform), 5);
|
||||
}
|
||||
|
||||
status = vl53l8cx_stop_ranging(&Dev);
|
||||
printf("End of ULD demo\n");
|
||||
return status;
|
||||
}
|
||||
@@ -0,0 +1,257 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2020, STMicroelectronics - All Rights Reserved
|
||||
*
|
||||
* This file is part of the VL53L8CX Ultra Lite Driver and is dual licensed,
|
||||
* either 'STMicroelectronics Proprietary license'
|
||||
* or 'BSD 3-clause "New" or "Revised" License' , at your option.
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* 'STMicroelectronics Proprietary license'
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* License terms: STMicroelectronics Proprietary in accordance with licensing
|
||||
* terms at www.st.com/sla0081
|
||||
*
|
||||
* STMicroelectronics confidential
|
||||
* Reproduction and Communication of this document is strictly prohibited unless
|
||||
* specifically authorized in writing by STMicroelectronics.
|
||||
*
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* Alternatively, the VL53L8CX Ultra Lite Driver may be distributed under the
|
||||
* terms of 'BSD 3-clause "New" or "Revised" License', in which case the
|
||||
* following provisions apply instead of the ones mentioned above :
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* License terms: BSD 3-clause "New" or "Revised" License.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/************************************************************/
|
||||
/* VL53L8CX ULD motion indicator with detection thresholds */
|
||||
/************************************************************/
|
||||
/*
|
||||
* This example shows how to use the motion indicator with detection threshold.
|
||||
* This kind of configuration might be used for user detection applications.
|
||||
* To use this example, user needs to be sure that macro
|
||||
* VL53L8CX_DISABLE_MOTION_INDICATOR is NOT enabled (see file platform.h).
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "vl53l8cx_api.h"
|
||||
#include "vl53l8cx_plugin_motion_indicator.h"
|
||||
#include "vl53l8cx_plugin_detection_thresholds.h"
|
||||
|
||||
#define UNUSED(x) (void)(x)
|
||||
|
||||
/* This function needs to be filled by the customer. It allows knowing when
|
||||
* the VL53L8CX interrupt is raised on GPIO1. This is the only way to use detection thresholds.
|
||||
*/
|
||||
int WaitForL8CXInterrupt(VL53L8CX_Configuration * pDev) {
|
||||
|
||||
//Add your implementation here ...
|
||||
UNUSED(pDev);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int example11(void)
|
||||
{
|
||||
|
||||
/*********************************/
|
||||
/* VL53L8CX ranging variables */
|
||||
/*********************************/
|
||||
|
||||
uint8_t status, loop, isAlive, isReady, i;
|
||||
VL53L8CX_Configuration Dev; /* Sensor configuration */
|
||||
VL53L8CX_Motion_Configuration motion_config; /* Motion configuration*/
|
||||
VL53L8CX_ResultsData Results; /* Results data from VL53L8CX */
|
||||
|
||||
|
||||
/*********************************/
|
||||
/* Customer platform */
|
||||
/*********************************/
|
||||
|
||||
/* Fill the platform structure with customer's implementation. For this
|
||||
* example, only the I2C address is used.
|
||||
*/
|
||||
Dev.platform.address = VL53L8CX_DEFAULT_I2C_ADDRESS;
|
||||
|
||||
/* (Optional) Reset sensor toggling PINs (see platform, not in API) */
|
||||
//Reset_Sensor(&(Dev.platform));
|
||||
|
||||
/* (Optional) Set a new I2C address if the wanted address is different
|
||||
* from the default one (filled with 0x20 for this example).
|
||||
*/
|
||||
//status = vl53l8cx_set_i2c_address(&Dev, 0x20);
|
||||
|
||||
|
||||
/*********************************/
|
||||
/* Power on sensor and init */
|
||||
/*********************************/
|
||||
|
||||
/* (Optional) Check if there is a VL53L8CX sensor connected */
|
||||
status = vl53l8cx_is_alive(&Dev, &isAlive);
|
||||
if(!isAlive || status)
|
||||
{
|
||||
printf("VL53L8CX not detected at requested address\n");
|
||||
return status;
|
||||
}
|
||||
|
||||
/* (Mandatory) Init VL53L8CX sensor */
|
||||
status = vl53l8cx_init(&Dev);
|
||||
if(status)
|
||||
{
|
||||
printf("VL53L8CX ULD Loading failed\n");
|
||||
return status;
|
||||
}
|
||||
|
||||
printf("VL53L8CX ULD ready ! (Version : %s)\n",
|
||||
VL53L8CX_API_REVISION);
|
||||
|
||||
|
||||
/*********************************/
|
||||
/* Program motion indicator */
|
||||
/*********************************/
|
||||
|
||||
/* Create motion indicator with resolution 8x8 */
|
||||
status = vl53l8cx_motion_indicator_init(&Dev, &motion_config, VL53L8CX_RESOLUTION_8X8);
|
||||
if(status)
|
||||
{
|
||||
printf("Motion indicator init failed with status : %u\n", status);
|
||||
return status;
|
||||
}
|
||||
|
||||
/* (Optional) Change the min and max distance used to detect motions. The
|
||||
* difference between min and max must never be >1500mm, and minimum never be <400mm,
|
||||
* otherwise the function below returns error 127 */
|
||||
status = vl53l8cx_motion_indicator_set_distance_motion(&Dev, &motion_config, 1000, 2000);
|
||||
if(status)
|
||||
{
|
||||
printf("Motion indicator set distance motion failed with status : %u\n", status);
|
||||
return status;
|
||||
}
|
||||
|
||||
/* If user want to change the resolution, he also needs to update the motion indicator resolution */
|
||||
//status = vl53l8cx_set_resolution(&Dev, VL53L8CX_RESOLUTION_4X4);
|
||||
//status = vl53l8cx_motion_indicator_set_resolution(&Dev, &motion_config, VL53L8CX_RESOLUTION_4X4);
|
||||
|
||||
|
||||
/* Set the device in AUTONOMOUS and set a small integration time to reduce power consumption */
|
||||
status = vl53l8cx_set_resolution(&Dev, VL53L8CX_RESOLUTION_8X8);
|
||||
status = vl53l8cx_set_ranging_mode(&Dev, VL53L8CX_RANGING_MODE_AUTONOMOUS);
|
||||
status = vl53l8cx_set_ranging_frequency_hz(&Dev, 2);
|
||||
status = vl53l8cx_set_integration_time_ms(&Dev, 10);
|
||||
|
||||
|
||||
/*********************************/
|
||||
/* Program detection thresholds */
|
||||
/*********************************/
|
||||
|
||||
/* In this example, we want 1 thresholds per zone for a 8x8 resolution */
|
||||
/* Create array of thresholds (size cannot be changed) */
|
||||
VL53L8CX_DetectionThresholds thresholds[VL53L8CX_NB_THRESHOLDS];
|
||||
|
||||
/* Set all values to 0 */
|
||||
memset(&thresholds, 0, sizeof(thresholds));
|
||||
|
||||
/* Add thresholds for all zones (64 zones in resolution 4x4, or 64 in 8x8) */
|
||||
for(i = 0; i < 64; i++){
|
||||
thresholds[i].zone_num = i;
|
||||
thresholds[i].measurement = VL53L8CX_MOTION_INDICATOR;
|
||||
thresholds[i].type = VL53L8CX_GREATER_THAN_MAX_CHECKER;
|
||||
thresholds[i].mathematic_operation = VL53L8CX_OPERATION_NONE;
|
||||
|
||||
/* The value 44 is given as example. All motion above 44 will be considered as a movement */
|
||||
thresholds[i].param_low_thresh = 44;
|
||||
thresholds[i].param_high_thresh = 44;
|
||||
}
|
||||
|
||||
/* The last thresholds must be clearly indicated. As we have 64
|
||||
* checkers, the last one is the 63 */
|
||||
thresholds[63].zone_num = VL53L8CX_LAST_THRESHOLD | thresholds[63].zone_num;
|
||||
|
||||
/* Send array of thresholds to the sensor */
|
||||
vl53l8cx_set_detection_thresholds(&Dev, thresholds);
|
||||
|
||||
/* Enable detection thresholds */
|
||||
vl53l8cx_set_detection_thresholds_enable(&Dev, 1);
|
||||
|
||||
|
||||
/*********************************/
|
||||
/* Ranging loop */
|
||||
/*********************************/
|
||||
|
||||
status = vl53l8cx_start_ranging(&Dev);
|
||||
printf("Waiting for a movement into the FOV between 1m and 2m...\n");
|
||||
|
||||
loop = 0;
|
||||
while(loop < 10)
|
||||
{
|
||||
/* Function WaitForL8CXInterrupt() does not exists, and must be
|
||||
* implemented by user. It allows catching the interrupt raised on
|
||||
* pin A1 (INT), when the checkers detect the programmed
|
||||
* conditions.
|
||||
*/
|
||||
|
||||
isReady = WaitForL8CXInterrupt(&Dev);
|
||||
|
||||
if(isReady)
|
||||
{
|
||||
vl53l8cx_get_ranging_data(&Dev, &Results);
|
||||
|
||||
/* As the sensor is set in 8x8 mode by default, we have a total
|
||||
* of 64 zones to print. For this example, only the data of first zone are
|
||||
* print */
|
||||
for(i = 0; i < 64; i++)
|
||||
{
|
||||
if(Results.motion_indicator.motion[motion_config.map_id[i]] >= 44)
|
||||
{
|
||||
printf(" Movement detected in this zone : %3d !\n", i);
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
loop++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
status = vl53l8cx_stop_ranging(&Dev);
|
||||
printf("End of ULD demo\n");
|
||||
return status;
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2020, STMicroelectronics - All Rights Reserved
|
||||
*
|
||||
* This file is part of the VL53L8CX Ultra Lite Driver and is dual licensed,
|
||||
* either 'STMicroelectronics Proprietary license'
|
||||
* or 'BSD 3-clause "New" or "Revised" License' , at your option.
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* 'STMicroelectronics Proprietary license'
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* License terms: STMicroelectronics Proprietary in accordance with licensing
|
||||
* terms at www.st.com/sla0081
|
||||
*
|
||||
* STMicroelectronics confidential
|
||||
* Reproduction and Communication of this document is strictly prohibited unless
|
||||
* specifically authorized in writing by STMicroelectronics.
|
||||
*
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* Alternatively, the VL53L8CX Ultra Lite Driver may be distributed under the
|
||||
* terms of 'BSD 3-clause "New" or "Revised" License', in which case the
|
||||
* following provisions apply instead of the ones mentioned above :
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* License terms: BSD 3-clause "New" or "Revised" License.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/***********************************/
|
||||
/* VL53L8CX ULD basic example */
|
||||
/***********************************/
|
||||
/*
|
||||
* This example is the most basic. It initializes the VL53L8CX ULD, and starts
|
||||
* a ranging to capture 10 frames.
|
||||
*
|
||||
* By default, ULD is configured to have the following settings :
|
||||
* - Resolution 4x4
|
||||
* - Ranging period 1Hz
|
||||
*
|
||||
* In this example, we also suppose that the number of target per zone is
|
||||
* set to 1 , and all output are enabled (see file platform.h).
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "vl53l8cx_api.h"
|
||||
|
||||
int example1(void)
|
||||
{
|
||||
|
||||
/*********************************/
|
||||
/* VL53L8CX ranging variables */
|
||||
/*********************************/
|
||||
|
||||
uint8_t status, loop, isAlive, isReady, i;
|
||||
VL53L8CX_Configuration Dev; /* Sensor configuration */
|
||||
VL53L8CX_ResultsData Results; /* Results data from VL53L8CX */
|
||||
|
||||
|
||||
/*********************************/
|
||||
/* Customer platform */
|
||||
/*********************************/
|
||||
|
||||
/* Fill the platform structure with customer's implementation. For this
|
||||
* example, only the I2C address is used.
|
||||
*/
|
||||
Dev.platform.address = VL53L8CX_DEFAULT_I2C_ADDRESS;
|
||||
|
||||
/* (Optional) Reset sensor toggling PINs (see platform, not in API) */
|
||||
//Reset_Sensor(&(Dev.platform));
|
||||
|
||||
/* (Optional) Set a new I2C address if the wanted address is different
|
||||
* from the default one (filled with 0x20 for this example).
|
||||
*/
|
||||
//status = vl53l8cx_set_i2c_address(&Dev, 0x20);
|
||||
|
||||
|
||||
/*********************************/
|
||||
/* Power on sensor and init */
|
||||
/*********************************/
|
||||
|
||||
/* (Optional) Check if there is a VL53L8CX sensor connected */
|
||||
status = vl53l8cx_is_alive(&Dev, &isAlive);
|
||||
if(!isAlive || status)
|
||||
{
|
||||
printf("VL53L8CX not detected at requested address\n");
|
||||
return status;
|
||||
}
|
||||
|
||||
/* (Mandatory) Init VL53L8CX sensor */
|
||||
status = vl53l8cx_init(&Dev);
|
||||
if(status)
|
||||
{
|
||||
printf("VL53L8CX ULD Loading failed\n");
|
||||
return status;
|
||||
}
|
||||
|
||||
printf("VL53L8CX ULD ready ! (Version : %s)\n",
|
||||
VL53L8CX_API_REVISION);
|
||||
|
||||
|
||||
/*********************************/
|
||||
/* Ranging loop */
|
||||
/*********************************/
|
||||
|
||||
status = vl53l8cx_start_ranging(&Dev);
|
||||
|
||||
loop = 0;
|
||||
while(loop < 10)
|
||||
{
|
||||
/* Use polling function to know when a new measurement is ready.
|
||||
* Another way can be to wait for HW interrupt raised on PIN A1
|
||||
* (INT) when a new measurement is ready */
|
||||
|
||||
status = vl53l8cx_check_data_ready(&Dev, &isReady);
|
||||
|
||||
if(isReady)
|
||||
{
|
||||
vl53l8cx_get_ranging_data(&Dev, &Results);
|
||||
|
||||
/* As the sensor is set in 4x4 mode by default, we have a total
|
||||
* of 16 zones to print. For this example, only the data of first zone are
|
||||
* print */
|
||||
printf("Print data no : %3u\n", Dev.streamcount);
|
||||
for(i = 0; i < 16; i++)
|
||||
{
|
||||
printf("Zone : %3d, Status : %3u, Distance : %4d mm\n",
|
||||
i,
|
||||
Results.target_status[VL53L8CX_NB_TARGET_PER_ZONE*i],
|
||||
Results.distance_mm[VL53L8CX_NB_TARGET_PER_ZONE*i]);
|
||||
}
|
||||
printf("\n");
|
||||
loop++;
|
||||
}
|
||||
|
||||
/* Wait a few ms to avoid too high polling (function in platform
|
||||
* file, not in API) */
|
||||
WaitMs(&(Dev.platform), 5);
|
||||
}
|
||||
|
||||
status = vl53l8cx_stop_ranging(&Dev);
|
||||
printf("End of ULD demo\n");
|
||||
return status;
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2020, STMicroelectronics - All Rights Reserved
|
||||
*
|
||||
* This file is part of the VL53L8CX Ultra Lite Driver and is dual licensed,
|
||||
* either 'STMicroelectronics Proprietary license'
|
||||
* or 'BSD 3-clause "New" or "Revised" License' , at your option.
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* 'STMicroelectronics Proprietary license'
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* License terms: STMicroelectronics Proprietary in accordance with licensing
|
||||
* terms at www.st.com/sla0081
|
||||
*
|
||||
* STMicroelectronics confidential
|
||||
* Reproduction and Communication of this document is strictly prohibited unless
|
||||
* specifically authorized in writing by STMicroelectronics.
|
||||
*
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* Alternatively, the VL53L8CX Ultra Lite Driver may be distributed under the
|
||||
* terms of 'BSD 3-clause "New" or "Revised" License', in which case the
|
||||
* following provisions apply instead of the ones mentioned above :
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* License terms: BSD 3-clause "New" or "Revised" License.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/***********************************/
|
||||
/* VL53L8CX ULD get/set params */
|
||||
/***********************************/
|
||||
/*
|
||||
* This example shows the possibility of VL53L8CX to get/set params. It
|
||||
* initializes the VL53L8CX ULD, set a configuration, and starts
|
||||
* a ranging to capture 10 frames.
|
||||
*
|
||||
* In this example, we also suppose that the number of target per zone is
|
||||
* set to 1 , and all output are enabled (see file platform.h).
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "vl53l8cx_api.h"
|
||||
|
||||
int example2(void)
|
||||
{
|
||||
|
||||
/*********************************/
|
||||
/* VL53L8CX ranging variables */
|
||||
/*********************************/
|
||||
|
||||
uint8_t status, loop, isAlive, isReady, i;
|
||||
uint32_t integration_time_ms;
|
||||
VL53L8CX_Configuration Dev; /* Sensor configuration */
|
||||
VL53L8CX_ResultsData Results; /* Results data from VL53L8CX */
|
||||
|
||||
|
||||
/*********************************/
|
||||
/* Customer platform */
|
||||
/*********************************/
|
||||
|
||||
/* Fill the platform structure with customer's implementation. For this
|
||||
* example, only the I2C address is used.
|
||||
*/
|
||||
Dev.platform.address = VL53L8CX_DEFAULT_I2C_ADDRESS;
|
||||
|
||||
/* (Optional) Reset sensor toggling PINs (see platform, not in API) */
|
||||
//Reset_Sensor(&(Dev.platform));
|
||||
|
||||
/* (Optional) Set a new I2C address if the wanted address is different
|
||||
* from the default one (filled with 0x20 for this example).
|
||||
*/
|
||||
//status = vl53l8cx_set_i2c_address(&Dev, 0x20);
|
||||
|
||||
|
||||
/*********************************/
|
||||
/* Power on sensor and init */
|
||||
/*********************************/
|
||||
|
||||
/* (Optional) Check if there is a VL53L8CX sensor connected */
|
||||
status = vl53l8cx_is_alive(&Dev, &isAlive);
|
||||
if(!isAlive || status)
|
||||
{
|
||||
printf("VL53L8CX not detected at requested address\n");
|
||||
return status;
|
||||
}
|
||||
|
||||
/* (Mandatory) Init VL53L8CX sensor */
|
||||
status = vl53l8cx_init(&Dev);
|
||||
if(status)
|
||||
{
|
||||
printf("VL53L8CX ULD Loading failed\n");
|
||||
return status;
|
||||
}
|
||||
|
||||
printf("VL53L8CX ULD ready ! (Version : %s)\n",
|
||||
VL53L8CX_API_REVISION);
|
||||
|
||||
|
||||
/*********************************/
|
||||
/* Set some params */
|
||||
/*********************************/
|
||||
|
||||
/* Set resolution in 8x8. WARNING : As others settings depend to this
|
||||
* one, it must be the first to use.
|
||||
*/
|
||||
status = vl53l8cx_set_resolution(&Dev, VL53L8CX_RESOLUTION_8X8);
|
||||
if(status)
|
||||
{
|
||||
printf("vl53l8cx_set_resolution failed, status %u\n", status);
|
||||
return status;
|
||||
}
|
||||
|
||||
/* Set ranging frequency to 10Hz.
|
||||
* Using 4x4, min frequency is 1Hz and max is 60Hz
|
||||
* Using 8x8, min frequency is 1Hz and max is 15Hz
|
||||
*/
|
||||
status = vl53l8cx_set_ranging_frequency_hz(&Dev, 10);
|
||||
if(status)
|
||||
{
|
||||
printf("vl53l8cx_set_ranging_frequency_hz failed, status %u\n", status);
|
||||
return status;
|
||||
}
|
||||
|
||||
/* Set target order to closest */
|
||||
status = vl53l8cx_set_target_order(&Dev, VL53L8CX_TARGET_ORDER_CLOSEST);
|
||||
if(status)
|
||||
{
|
||||
printf("vl53l8cx_set_target_order failed, status %u\n", status);
|
||||
return status;
|
||||
}
|
||||
|
||||
/* Get current integration time */
|
||||
status = vl53l8cx_get_integration_time_ms(&Dev, &integration_time_ms);
|
||||
if(status)
|
||||
{
|
||||
printf("vl53l8cx_get_integration_time_ms failed, status %u\n", status);
|
||||
return status;
|
||||
}
|
||||
printf("Current integration time is : %d ms\n", (int)integration_time_ms);
|
||||
|
||||
|
||||
/*********************************/
|
||||
/* Ranging loop */
|
||||
/*********************************/
|
||||
|
||||
status = vl53l8cx_start_ranging(&Dev);
|
||||
|
||||
loop = 0;
|
||||
while(loop < 10)
|
||||
{
|
||||
/* Use polling function to know when a new measurement is ready.
|
||||
* Another way can be to wait for HW interrupt raised on PIN A1
|
||||
* (INT) when a new measurement is ready */
|
||||
|
||||
status = vl53l8cx_check_data_ready(&Dev, &isReady);
|
||||
|
||||
if(isReady)
|
||||
{
|
||||
vl53l8cx_get_ranging_data(&Dev, &Results);
|
||||
|
||||
/* As the sensor is set in 8x8 mode, we have a total
|
||||
* of 64 zones to print. For this example, only the data of
|
||||
* first zone are print */
|
||||
printf("Print data no : %3u\n", Dev.streamcount);
|
||||
for(i = 0; i < 64; i++)
|
||||
{
|
||||
printf("Zone : %3d, Status : %3u, Distance : %4d mm\n",
|
||||
i,
|
||||
Results.target_status[VL53L8CX_NB_TARGET_PER_ZONE*i],
|
||||
Results.distance_mm[VL53L8CX_NB_TARGET_PER_ZONE*i]);
|
||||
}
|
||||
printf("\n");
|
||||
loop++;
|
||||
}
|
||||
|
||||
/* Wait a few ms to avoid too high polling (function in platform
|
||||
* file, not in API) */
|
||||
WaitMs(&(Dev.platform), 5);
|
||||
}
|
||||
|
||||
status = vl53l8cx_stop_ranging(&Dev);
|
||||
printf("End of ULD demo\n");
|
||||
return status;
|
||||
}
|
||||
@@ -0,0 +1,239 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2020, STMicroelectronics - All Rights Reserved
|
||||
*
|
||||
* This file is part of the VL53L8CX Ultra Lite Driver and is dual licensed,
|
||||
* either 'STMicroelectronics Proprietary license'
|
||||
* or 'BSD 3-clause "New" or "Revised" License' , at your option.
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* 'STMicroelectronics Proprietary license'
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* License terms: STMicroelectronics Proprietary in accordance with licensing
|
||||
* terms at www.st.com/sla0081
|
||||
*
|
||||
* STMicroelectronics confidential
|
||||
* Reproduction and Communication of this document is strictly prohibited unless
|
||||
* specifically authorized in writing by STMicroelectronics.
|
||||
*
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* Alternatively, the VL53L8CX Ultra Lite Driver may be distributed under the
|
||||
* terms of 'BSD 3-clause "New" or "Revised" License', in which case the
|
||||
* following provisions apply instead of the ones mentioned above :
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* License terms: BSD 3-clause "New" or "Revised" License.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/***********************************/
|
||||
/* VL53L8CX ULD ranging mode */
|
||||
/***********************************/
|
||||
/*
|
||||
* This example shows the differences between ranging modes of VL53L8CX
|
||||
* (mode continuous and autonomous). For both modes, it initializes the VL53L8CX
|
||||
* ULD, set the mode, and starts a ranging to capture 10 frames.
|
||||
*
|
||||
* In this example, we also suppose that the number of target per zone is
|
||||
* set to 1 , and all output are enabled (see file platform.h).
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "vl53l8cx_api.h"
|
||||
|
||||
int example3(void)
|
||||
{
|
||||
|
||||
/*********************************/
|
||||
/* VL53L8CX ranging variables */
|
||||
/*********************************/
|
||||
|
||||
uint8_t status, loop, isAlive, isReady, i;
|
||||
VL53L8CX_Configuration Dev; /* Sensor configuration */
|
||||
VL53L8CX_ResultsData Results; /* Results data from VL53L8CX */
|
||||
|
||||
|
||||
/*********************************/
|
||||
/* Customer platform */
|
||||
/*********************************/
|
||||
|
||||
/* Fill the platform structure with customer's implementation. For this
|
||||
* example, only the I2C address is used.
|
||||
*/
|
||||
Dev.platform.address = VL53L8CX_DEFAULT_I2C_ADDRESS;
|
||||
|
||||
/* (Optional) Reset sensor toggling PINs (see platform, not in API) */
|
||||
//Reset_Sensor(&(Dev.platform));
|
||||
|
||||
/* (Optional) Set a new I2C address if the wanted address is different
|
||||
* from the default one (filled with 0x20 for this example).
|
||||
*/
|
||||
//status = vl53l8cx_set_i2c_address(&Dev, 0x20);
|
||||
|
||||
|
||||
/*********************************/
|
||||
/* Power on sensor and init */
|
||||
/*********************************/
|
||||
|
||||
/* (Optional) Check if there is a VL53L8CX sensor connected */
|
||||
status = vl53l8cx_is_alive(&Dev, &isAlive);
|
||||
if(!isAlive || status)
|
||||
{
|
||||
printf("VL53L8CX not detected at requested address\n");
|
||||
return status;
|
||||
}
|
||||
|
||||
/* (Mandatory) Init VL53L8CX sensor */
|
||||
status = vl53l8cx_init(&Dev);
|
||||
if(status)
|
||||
{
|
||||
printf("VL53L8CX ULD Loading failed\n");
|
||||
return status;
|
||||
}
|
||||
|
||||
printf("VL53L8CX ULD ready ! (Version : %s)\n",
|
||||
VL53L8CX_API_REVISION);
|
||||
|
||||
|
||||
/*********************************/
|
||||
/* Set ranging mode autonomous */
|
||||
/*********************************/
|
||||
|
||||
status = vl53l8cx_set_ranging_mode(&Dev, VL53L8CX_RANGING_MODE_AUTONOMOUS);
|
||||
if(status)
|
||||
{
|
||||
printf("vl53l8cx_set_ranging_mode failed, status %u\n", status);
|
||||
return status;
|
||||
}
|
||||
|
||||
/* Using autonomous mode, the integration time can be updated (not possible
|
||||
* using continuous) */
|
||||
status = vl53l8cx_set_integration_time_ms(&Dev, 20);
|
||||
|
||||
/* Start a ranging session */
|
||||
status = vl53l8cx_start_ranging(&Dev);
|
||||
printf("Start ranging autonomous\n");
|
||||
|
||||
loop = 0;
|
||||
while(loop < 10)
|
||||
{
|
||||
status = vl53l8cx_check_data_ready(&Dev, &isReady);
|
||||
if(isReady)
|
||||
{
|
||||
vl53l8cx_get_ranging_data(&Dev, &Results);
|
||||
|
||||
/* As the sensor is set in 4x4 mode by default, we have a total
|
||||
* of 16 zones to print. For this example, only the data of first zone are
|
||||
* print */
|
||||
printf("Print data no : %3u\n", Dev.streamcount);
|
||||
for(i = 0; i < 16; i++)
|
||||
{
|
||||
printf("Zone : %3d, Status : %3u, Distance : %4d mm\n",
|
||||
i,
|
||||
Results.target_status[VL53L8CX_NB_TARGET_PER_ZONE*i],
|
||||
Results.distance_mm[VL53L8CX_NB_TARGET_PER_ZONE*i]);
|
||||
}
|
||||
printf("\n");
|
||||
loop++;
|
||||
}
|
||||
|
||||
/* Wait a few ms to avoid too high polling (function in platform
|
||||
* file, not in API) */
|
||||
WaitMs(&(Dev.platform), 5);
|
||||
}
|
||||
|
||||
status = vl53l8cx_stop_ranging(&Dev);
|
||||
printf("Stop ranging autonomous\n");
|
||||
WaitMs(&(Dev.platform), 1);
|
||||
|
||||
|
||||
/*********************************/
|
||||
/* Set ranging mode continuous */
|
||||
/*********************************/
|
||||
|
||||
/* In continuous mode, the integration time cannot be programmed
|
||||
* (automatically set to maximum value) */
|
||||
|
||||
status = vl53l8cx_set_ranging_mode(&Dev, VL53L8CX_RANGING_MODE_CONTINUOUS);
|
||||
if(status)
|
||||
{
|
||||
printf("vl53l8cx_set_ranging_mode failed, status %u\n", status);
|
||||
return status;
|
||||
}
|
||||
|
||||
/* Trying to update value below will have no impact on integration time */
|
||||
//status = vl53l8cx_set_integration_time_ms(&Dev, 20);
|
||||
|
||||
/* Start a ranging session */
|
||||
status = vl53l8cx_start_ranging(&Dev);
|
||||
printf("Start ranging continuous\n");
|
||||
|
||||
loop = 0;
|
||||
while(loop < 10)
|
||||
{
|
||||
status = vl53l8cx_check_data_ready(&Dev, &isReady);
|
||||
if(isReady)
|
||||
{
|
||||
vl53l8cx_get_ranging_data(&Dev, &Results);
|
||||
|
||||
/* As the sensor is set in 4x4 mode by default, we have a total
|
||||
* of 16 zones to print */
|
||||
printf("Print data no : %3u\n", Dev.streamcount);
|
||||
for(i = 0; i < 16; i++)
|
||||
{
|
||||
printf("Zone : %3d, Status : %3u, Distance : %4d mm\n",
|
||||
i,
|
||||
Results.target_status[VL53L8CX_NB_TARGET_PER_ZONE*i],
|
||||
Results.distance_mm[VL53L8CX_NB_TARGET_PER_ZONE*i]);
|
||||
}
|
||||
printf("\n");
|
||||
loop++;
|
||||
}
|
||||
|
||||
/* Wait a few ms to avoid too high polling (function in platform
|
||||
* file, not in API) */
|
||||
WaitMs(&(Dev.platform), 5);
|
||||
}
|
||||
|
||||
status = vl53l8cx_stop_ranging(&Dev);
|
||||
printf("Stop ranging continuous\n");
|
||||
|
||||
printf("End of ULD demo\n");
|
||||
return status;
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2020, STMicroelectronics - All Rights Reserved
|
||||
*
|
||||
* This file is part of the VL53L8CX Ultra Lite Driver and is dual licensed,
|
||||
* either 'STMicroelectronics Proprietary license'
|
||||
* or 'BSD 3-clause "New" or "Revised" License' , at your option.
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* 'STMicroelectronics Proprietary license'
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* License terms: STMicroelectronics Proprietary in accordance with licensing
|
||||
* terms at www.st.com/sla0081
|
||||
*
|
||||
* STMicroelectronics confidential
|
||||
* Reproduction and Communication of this document is strictly prohibited unless
|
||||
* specifically authorized in writing by STMicroelectronics.
|
||||
*
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* Alternatively, the VL53L8CX Ultra Lite Driver may be distributed under the
|
||||
* terms of 'BSD 3-clause "New" or "Revised" License', in which case the
|
||||
* following provisions apply instead of the ones mentioned above :
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* License terms: BSD 3-clause "New" or "Revised" License.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/***********************************/
|
||||
/* VL53L8CX ULD power mode */
|
||||
/***********************************/
|
||||
/*
|
||||
* This example shows the possibility of VL53L8CX to change power mode. It
|
||||
* initializes the VL53L8CX ULD, set a configuration, change the power mode, and
|
||||
* starts a ranging to capture 10 frames.
|
||||
*
|
||||
* In this example, we also suppose that the number of target per zone is
|
||||
* set to 1 , and all output are enabled (see file platform.h).
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "vl53l8cx_api.h"
|
||||
|
||||
int example4(void)
|
||||
{
|
||||
|
||||
/*********************************/
|
||||
/* VL53L8CX ranging variables */
|
||||
/*********************************/
|
||||
|
||||
uint8_t status, loop, isAlive, isReady, i;
|
||||
VL53L8CX_Configuration Dev; /* Sensor configuration */
|
||||
VL53L8CX_ResultsData Results; /* Results data from VL53L8CX */
|
||||
|
||||
|
||||
/*********************************/
|
||||
/* Customer platform */
|
||||
/*********************************/
|
||||
|
||||
/* Fill the platform structure with customer's implementation. For this
|
||||
* example, only the I2C address is used.
|
||||
*/
|
||||
Dev.platform.address = VL53L8CX_DEFAULT_I2C_ADDRESS;
|
||||
|
||||
/* (Optional) Reset sensor toggling PINs (see platform, not in API) */
|
||||
//Reset_Sensor(&(Dev.platform));
|
||||
|
||||
/* (Optional) Set a new I2C address if the wanted address is different
|
||||
* from the default one (filled with 0x20 for this example).
|
||||
*/
|
||||
//status = vl53l8cx_set_i2c_address(&Dev, 0x20);
|
||||
|
||||
|
||||
/*********************************/
|
||||
/* Power on sensor and init */
|
||||
/*********************************/
|
||||
|
||||
/* (Optional) Check if there is a VL53L8CX sensor connected */
|
||||
status = vl53l8cx_is_alive(&Dev, &isAlive);
|
||||
if(!isAlive || status)
|
||||
{
|
||||
printf("VL53L8CX not detected at requested address\n");
|
||||
return status;
|
||||
}
|
||||
|
||||
/* (Mandatory) Init VL53L8CX sensor */
|
||||
status = vl53l8cx_init(&Dev);
|
||||
if(status)
|
||||
{
|
||||
printf("VL53L8CX ULD Loading failed\n");
|
||||
return status;
|
||||
}
|
||||
|
||||
printf("VL53L8CX ULD ready ! (Version : %s)\n",
|
||||
VL53L8CX_API_REVISION);
|
||||
|
||||
/*********************************/
|
||||
/* Change the power mode */
|
||||
/*********************************/
|
||||
|
||||
/* For the example, we don't want to use the sensor during 10 seconds. In order to reduce
|
||||
* the power consumption, the sensor is set to low power mode.
|
||||
*/
|
||||
status = vl53l8cx_set_power_mode(&Dev, VL53L8CX_POWER_MODE_SLEEP);
|
||||
if(status)
|
||||
{
|
||||
printf("vl53l8cx_set_power_mode failed, status %u\n", status);
|
||||
return status;
|
||||
}
|
||||
printf("VL53L8CX is now sleeping\n");
|
||||
|
||||
/* We wait 5 seconds, only for the example */
|
||||
printf("Waiting 5 seconds for the example...\n");
|
||||
WaitMs(&(Dev.platform), 5000);
|
||||
|
||||
/* After 5 seconds, the sensor needs to be restarted */
|
||||
status = vl53l8cx_set_power_mode(&Dev, VL53L8CX_POWER_MODE_WAKEUP);
|
||||
if(status)
|
||||
{
|
||||
printf("vl53l8cx_set_power_mode failed, status %u\n", status);
|
||||
return status;
|
||||
}
|
||||
printf("VL53L8CX is now waking up\n");
|
||||
|
||||
/*********************************/
|
||||
/* Ranging loop */
|
||||
/*********************************/
|
||||
|
||||
status = vl53l8cx_start_ranging(&Dev);
|
||||
|
||||
loop = 0;
|
||||
while(loop < 10)
|
||||
{
|
||||
/* Use polling function to know when a new measurement is ready.
|
||||
* Another way can be to wait for HW interrupt raised on PIN A1
|
||||
* (INT) when a new measurement is ready */
|
||||
|
||||
status = vl53l8cx_check_data_ready(&Dev, &isReady);
|
||||
|
||||
if(isReady)
|
||||
{
|
||||
vl53l8cx_get_ranging_data(&Dev, &Results);
|
||||
|
||||
/* As the sensor is set in 4x4 mode by default, we have a total
|
||||
* of 16 zones to print. For this example, only the data of first zone are
|
||||
* print */
|
||||
printf("Print data no : %3u\n", Dev.streamcount);
|
||||
for(i = 0; i < 16; i++)
|
||||
{
|
||||
printf("Zone : %3d, Status : %3u, Distance : %4d mm\n",
|
||||
i,
|
||||
Results.target_status[VL53L8CX_NB_TARGET_PER_ZONE*i],
|
||||
Results.distance_mm[VL53L8CX_NB_TARGET_PER_ZONE*i]);
|
||||
}
|
||||
printf("\n");
|
||||
loop++;
|
||||
}
|
||||
|
||||
/* Wait a few ms to avoid too high polling (function in platform
|
||||
* file, not in API) */
|
||||
WaitMs(&(Dev.platform), 5);
|
||||
}
|
||||
|
||||
status = vl53l8cx_stop_ranging(&Dev);
|
||||
printf("End of ULD demo\n");
|
||||
return status;
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2020, STMicroelectronics - All Rights Reserved
|
||||
*
|
||||
* This file is part of the VL53L8CX Ultra Lite Driver and is dual licensed,
|
||||
* either 'STMicroelectronics Proprietary license'
|
||||
* or 'BSD 3-clause "New" or "Revised" License' , at your option.
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* 'STMicroelectronics Proprietary license'
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* License terms: STMicroelectronics Proprietary in accordance with licensing
|
||||
* terms at www.st.com/sla0081
|
||||
*
|
||||
* STMicroelectronics confidential
|
||||
* Reproduction and Communication of this document is strictly prohibited unless
|
||||
* specifically authorized in writing by STMicroelectronics.
|
||||
*
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* Alternatively, the VL53L8CX Ultra Lite Driver may be distributed under the
|
||||
* terms of 'BSD 3-clause "New" or "Revised" License', in which case the
|
||||
* following provisions apply instead of the ones mentioned above :
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* License terms: BSD 3-clause "New" or "Revised" License.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/***********************************/
|
||||
/* VL53L8CX ULD multiple targets */
|
||||
/***********************************/
|
||||
/*
|
||||
* This example shows the possibility of VL53L8CX to get/set params. It
|
||||
* initializes the VL53L8CX ULD, set a configuration, and starts
|
||||
* a ranging to capture 10 frames.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "vl53l8cx_api.h"
|
||||
|
||||
int example5(void)
|
||||
{
|
||||
/*********************************/
|
||||
/* VL53L8CX ranging variables */
|
||||
/*********************************/
|
||||
|
||||
uint8_t status, loop, isAlive, isReady, i, j;
|
||||
VL53L8CX_Configuration Dev; /* Sensor configuration */
|
||||
VL53L8CX_ResultsData Results; /* Results data from VL53L8CX */
|
||||
|
||||
|
||||
/*********************************/
|
||||
/* Customer platform */
|
||||
/*********************************/
|
||||
|
||||
/* Fill the platform structure with customer's implementation. For this
|
||||
* example, only the I2C address is used.
|
||||
*/
|
||||
Dev.platform.address = VL53L8CX_DEFAULT_I2C_ADDRESS;
|
||||
|
||||
/* (Optional) Reset sensor toggling PINs (see platform, not in API) */
|
||||
//Reset_Sensor(&(Dev.platform));
|
||||
|
||||
/* (Optional) Set a new I2C address if the wanted address is different
|
||||
* from the default one (filled with 0x20 for this example).
|
||||
*/
|
||||
//status = vl53l8cx_set_i2c_address(&Dev, 0x20);
|
||||
|
||||
|
||||
/*********************************/
|
||||
/* Power on sensor and init */
|
||||
/*********************************/
|
||||
|
||||
/* (Optional) Check if there is a VL53L8CX sensor connected */
|
||||
status = vl53l8cx_is_alive(&Dev, &isAlive);
|
||||
if(!isAlive || status)
|
||||
{
|
||||
printf("VL53L8CX not detected at requested address\n");
|
||||
return status;
|
||||
}
|
||||
|
||||
/* (Mandatory) Init VL53L8CX sensor */
|
||||
status = vl53l8cx_init(&Dev);
|
||||
if(status)
|
||||
{
|
||||
printf("VL53L8CX ULD Loading failed\n");
|
||||
return status;
|
||||
}
|
||||
|
||||
printf("VL53L8CX ULD ready ! (Version : %s)\n",
|
||||
VL53L8CX_API_REVISION);
|
||||
|
||||
|
||||
/*********************************/
|
||||
/* Set nb target per zone */
|
||||
/*********************************/
|
||||
|
||||
/* Each zone can output between 1 and 4 targets. By default the output
|
||||
* is set to 1 targets, but user can change it using macro
|
||||
* VL53L8CX_NB_TARGET_PER_ZONE located in file 'platform.h'.
|
||||
*/
|
||||
|
||||
/*********************************/
|
||||
/* Ranging loop */
|
||||
/*********************************/
|
||||
|
||||
status = vl53l8cx_start_ranging(&Dev);
|
||||
|
||||
loop = 0;
|
||||
while(loop < 10)
|
||||
{
|
||||
/* Use polling function to know when a new measurement is ready.
|
||||
* Another way can be to wait for HW interrupt raised on PIN A1
|
||||
* (INT) when a new measurement is ready */
|
||||
|
||||
status = vl53l8cx_check_data_ready(&Dev, &isReady);
|
||||
|
||||
if(isReady)
|
||||
{
|
||||
vl53l8cx_get_ranging_data(&Dev, &Results);
|
||||
|
||||
/* As the sensor is set in 4x4 mode by default, we have a total
|
||||
* of 16 zones to print */
|
||||
printf("Print data no : %3u\n", Dev.streamcount);
|
||||
for(i = 0; i < 16; i++)
|
||||
{
|
||||
/* Print per zone results. These results are the same for all targets */
|
||||
printf("Zone %3u : %2u, %6lu, %6lu, ",
|
||||
i,
|
||||
Results.nb_target_detected[i],
|
||||
Results.ambient_per_spad[i],
|
||||
Results.nb_spads_enabled[i]);
|
||||
|
||||
for(j = 0; j < VL53L8CX_NB_TARGET_PER_ZONE; j++)
|
||||
{
|
||||
/* Print per target results. These results depends of the target nb */
|
||||
uint16_t idx = VL53L8CX_NB_TARGET_PER_ZONE * i + j;
|
||||
printf("Target[%1u] : %2u, %4d, %6lu, %3u, ",
|
||||
j,
|
||||
Results.target_status[idx],
|
||||
Results.distance_mm[idx],
|
||||
Results.signal_per_spad[idx],
|
||||
Results.range_sigma_mm[idx]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
loop++;
|
||||
}
|
||||
|
||||
/* Wait a few ms to avoid too high polling (function in platform
|
||||
* file, not in API) */
|
||||
WaitMs(&(Dev.platform), 5);
|
||||
}
|
||||
|
||||
status = vl53l8cx_stop_ranging(&Dev);
|
||||
printf("End of ULD demo\n");
|
||||
return status;
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2020, STMicroelectronics - All Rights Reserved
|
||||
*
|
||||
* This file is part of the VL53L8CX Ultra Lite Driver and is dual licensed,
|
||||
* either 'STMicroelectronics Proprietary license'
|
||||
* or 'BSD 3-clause "New" or "Revised" License' , at your option.
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* 'STMicroelectronics Proprietary license'
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* License terms: STMicroelectronics Proprietary in accordance with licensing
|
||||
* terms at www.st.com/sla0081
|
||||
*
|
||||
* STMicroelectronics confidential
|
||||
* Reproduction and Communication of this document is strictly prohibited unless
|
||||
* specifically authorized in writing by STMicroelectronics.
|
||||
*
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* Alternatively, the VL53L8CX Ultra Lite Driver may be distributed under the
|
||||
* terms of 'BSD 3-clause "New" or "Revised" License', in which case the
|
||||
* following provisions apply instead of the ones mentioned above :
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* License terms: BSD 3-clause "New" or "Revised" License.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**************************************/
|
||||
/* VL53L8CX ULD I2C/RAM optimization */
|
||||
/**************************************/
|
||||
/*
|
||||
* This example shows the possibility of VL53L8CX to reduce I2C transactions
|
||||
* and RAM footprint. It initializes the VL53L8CX ULD, and starts
|
||||
* a ranging to capture 10 frames.
|
||||
*
|
||||
* In this example, we also suppose that the number of target per zone is
|
||||
* set to 1 , and all output are enabled (see file platform.h).
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "vl53l8cx_api.h"
|
||||
|
||||
int example6(void)
|
||||
{
|
||||
|
||||
/*********************************/
|
||||
/* VL53L8CX ranging variables */
|
||||
/*********************************/
|
||||
|
||||
uint8_t status, loop, isAlive, isReady, i;
|
||||
VL53L8CX_Configuration Dev; /* Sensor configuration */
|
||||
VL53L8CX_ResultsData Results; /* Results data from VL53L8CX */
|
||||
|
||||
|
||||
/*********************************/
|
||||
/* Customer platform */
|
||||
/*********************************/
|
||||
|
||||
/* Fill the platform structure with customer's implementation. For this
|
||||
* example, only the I2C address is used.
|
||||
*/
|
||||
Dev.platform.address = VL53L8CX_DEFAULT_I2C_ADDRESS;
|
||||
|
||||
/* (Optional) Reset sensor toggling PINs (see platform, not in API) */
|
||||
//Reset_Sensor(&(Dev.platform));
|
||||
|
||||
/* (Optional) Set a new I2C address if the wanted address is different
|
||||
* from the default one (filled with 0x20 for this example).
|
||||
*/
|
||||
//status = vl53l8cx_set_i2c_address(&Dev, 0x20);
|
||||
|
||||
|
||||
/*********************************/
|
||||
/* Power on sensor and init */
|
||||
/*********************************/
|
||||
|
||||
/* (Optional) Check if there is a VL53L8CX sensor connected */
|
||||
status = vl53l8cx_is_alive(&Dev, &isAlive);
|
||||
if(!isAlive || status)
|
||||
{
|
||||
printf("VL53L8CX not detected at requested address\n");
|
||||
return status;
|
||||
}
|
||||
|
||||
/* (Mandatory) Init VL53L8CX sensor */
|
||||
status = vl53l8cx_init(&Dev);
|
||||
if(status)
|
||||
{
|
||||
printf("VL53L8CX ULD Loading failed\n");
|
||||
return status;
|
||||
}
|
||||
|
||||
printf("VL53L8CX ULD ready ! (Version : %s)\n",
|
||||
VL53L8CX_API_REVISION);
|
||||
|
||||
|
||||
/*********************************/
|
||||
/* Reduce RAM & I2C access */
|
||||
/*********************************/
|
||||
|
||||
/* Results can be tuned in order to reduce I2C access and RAM footprints.
|
||||
* The 'platform.h' file contains macros used to disable output. If user declare
|
||||
* one of these macros, the results will not be sent through I2C, and the array will not
|
||||
* be created into the VL53L8CX_ResultsData structure.
|
||||
* For the minimum size, ST recommends 1 targets per zone, and only keep distance_mm,
|
||||
* target_status, and nb_target_detected. The following macros can be defined into file 'platform.h':
|
||||
*
|
||||
* #define VL53L8CX_DISABLE_AMBIENT_PER_SPAD
|
||||
* #define VL53L8CX_DISABLE_NB_SPADS_ENABLED
|
||||
* #define VL53L8CX_DISABLE_SIGNAL_PER_SPAD
|
||||
* #define VL53L8CX_DISABLE_RANGE_SIGMA_MM
|
||||
* #define VL53L8CX_DISABLE_REFLECTANCE_PERCENT
|
||||
* #define VL53L8CX_DISABLE_MOTION_INDICATOR
|
||||
*/
|
||||
|
||||
/*********************************/
|
||||
/* Ranging loop */
|
||||
/*********************************/
|
||||
|
||||
status = vl53l8cx_start_ranging(&Dev);
|
||||
|
||||
loop = 0;
|
||||
while(loop < 10)
|
||||
{
|
||||
/* Use polling function to know when a new measurement is ready.
|
||||
* Another way can be to wait for HW interrupt raised on PIN A1
|
||||
* (INT) when a new measurement is ready */
|
||||
|
||||
status = vl53l8cx_check_data_ready(&Dev, &isReady);
|
||||
|
||||
if(isReady)
|
||||
{
|
||||
vl53l8cx_get_ranging_data(&Dev, &Results);
|
||||
|
||||
/* As the sensor is set in 4x4 mode by default, we have a total
|
||||
* of 16 zones to print. For this example, only the data of first zone are
|
||||
* print */
|
||||
printf("Print data no : %3u\n", Dev.streamcount);
|
||||
for(i = 0; i < 16; i++)
|
||||
{
|
||||
printf("Zone : %3d, Status : %3u, Distance : %4d mm\n",
|
||||
i,
|
||||
Results.target_status[VL53L8CX_NB_TARGET_PER_ZONE*i],
|
||||
Results.distance_mm[VL53L8CX_NB_TARGET_PER_ZONE*i]);
|
||||
}
|
||||
printf("\n");
|
||||
loop++;
|
||||
}
|
||||
|
||||
/* Wait a few ms to avoid too high polling (function in platform
|
||||
* file, not in API) */
|
||||
WaitMs(&(Dev.platform), 5);
|
||||
}
|
||||
|
||||
status = vl53l8cx_stop_ranging(&Dev);
|
||||
printf("End of ULD demo\n");
|
||||
return status;
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2020, STMicroelectronics - All Rights Reserved
|
||||
*
|
||||
* This file is part of the VL53L8CX Ultra Lite Driver and is dual licensed,
|
||||
* either 'STMicroelectronics Proprietary license'
|
||||
* or 'BSD 3-clause "New" or "Revised" License' , at your option.
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* 'STMicroelectronics Proprietary license'
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* License terms: STMicroelectronics Proprietary in accordance with licensing
|
||||
* terms at www.st.com/sla0081
|
||||
*
|
||||
* STMicroelectronics confidential
|
||||
* Reproduction and Communication of this document is strictly prohibited unless
|
||||
* specifically authorized in writing by STMicroelectronics.
|
||||
*
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* Alternatively, the VL53L8CX Ultra Lite Driver may be distributed under the
|
||||
* terms of 'BSD 3-clause "New" or "Revised" License', in which case the
|
||||
* following provisions apply instead of the ones mentioned above :
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* License terms: BSD 3-clause "New" or "Revised" License.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/***********************************/
|
||||
/* VL53L8CX ULD calibrate Xtalk */
|
||||
/***********************************/
|
||||
/*
|
||||
* This example shows the possibility of VL53L8CX to calibrate Xtalk. It
|
||||
* initializes the VL53L8CX ULD, perform a Xtalk calibration, and starts
|
||||
* a ranging to capture 10 frames.
|
||||
|
||||
* In this example, we also suppose that the number of target per zone is
|
||||
* set to 1 , and all output are enabled (see file platform.h).
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "vl53l8cx_api.h"
|
||||
#include "vl53l8cx_plugin_xtalk.h"
|
||||
|
||||
int example7(void)
|
||||
{
|
||||
|
||||
/*********************************/
|
||||
/* VL53L8CX ranging variables */
|
||||
/*********************************/
|
||||
|
||||
uint8_t status, loop, isAlive, isReady, i;
|
||||
VL53L8CX_Configuration Dev; /* Sensor configuration */
|
||||
VL53L8CX_ResultsData Results; /* Results data from VL53L8CX */
|
||||
|
||||
/* Buffer containing Xtalk data */
|
||||
uint8_t xtalk_data[VL53L8CX_XTALK_BUFFER_SIZE];
|
||||
|
||||
/*********************************/
|
||||
/* Customer platform */
|
||||
/*********************************/
|
||||
|
||||
/* Fill the platform structure with customer's implementation. For this
|
||||
* example, only the I2C address is used.
|
||||
*/
|
||||
Dev.platform.address = VL53L8CX_DEFAULT_I2C_ADDRESS;
|
||||
|
||||
/* (Optional) Reset sensor toggling PINs (see platform, not in API) */
|
||||
//Reset_Sensor(&(Dev.platform));
|
||||
|
||||
/* (Optional) Set a new I2C address if the wanted address is different
|
||||
* from the default one (filled with 0x20 for this example).
|
||||
*/
|
||||
//status = vl53l8cx_set_i2c_address(&Dev, 0x20);
|
||||
|
||||
|
||||
/*********************************/
|
||||
/* Power on sensor and init */
|
||||
/*********************************/
|
||||
|
||||
/* (Optional) Check if there is a VL53L8CX sensor connected */
|
||||
status = vl53l8cx_is_alive(&Dev, &isAlive);
|
||||
if(!isAlive || status)
|
||||
{
|
||||
printf("VL53L8CX not detected at requested address\n");
|
||||
return status;
|
||||
}
|
||||
|
||||
/* (Mandatory) Init VL53L8CX sensor */
|
||||
status = vl53l8cx_init(&Dev);
|
||||
if(status)
|
||||
{
|
||||
printf("VL53L8CX ULD Loading failed\n");
|
||||
return status;
|
||||
}
|
||||
|
||||
printf("VL53L8CX ULD ready ! (Version : %s)\n",
|
||||
VL53L8CX_API_REVISION);
|
||||
|
||||
|
||||
/*********************************/
|
||||
/* Start Xtalk calibration */
|
||||
/*********************************/
|
||||
|
||||
/* Start Xtalk calibration with a 3% reflective target at 600mm for the
|
||||
* sensor, using 4 samples.
|
||||
*/
|
||||
printf("Running Xtalk calibration...\n");
|
||||
|
||||
status = vl53l8cx_calibrate_xtalk(&Dev, 3, 4, 600);
|
||||
if(status)
|
||||
{
|
||||
printf("vl53l8cx_calibrate_xtalk failed, status %u\n", status);
|
||||
return status;
|
||||
}else
|
||||
{
|
||||
printf("Xtalk calibration done\n");
|
||||
|
||||
/* Get Xtalk calibration data, in order to use them later */
|
||||
status = vl53l8cx_get_caldata_xtalk(&Dev, xtalk_data);
|
||||
|
||||
/* Set Xtalk calibration data */
|
||||
status = vl53l8cx_set_caldata_xtalk(&Dev, xtalk_data);
|
||||
}
|
||||
|
||||
|
||||
/*********************************/
|
||||
/* Ranging loop */
|
||||
/*********************************/
|
||||
|
||||
status = vl53l8cx_start_ranging(&Dev);
|
||||
|
||||
loop = 0;
|
||||
while(loop < 10)
|
||||
{
|
||||
/* Use polling function to know when a new measurement is ready.
|
||||
* Another way can be to wait for HW interrupt raised on PIN A1
|
||||
* (INT) when a new measurement is ready */
|
||||
|
||||
status = vl53l8cx_check_data_ready(&Dev, &isReady);
|
||||
|
||||
if(isReady)
|
||||
{
|
||||
vl53l8cx_get_ranging_data(&Dev, &Results);
|
||||
|
||||
/* As the sensor is set in 4x4 mode by default, we have a total
|
||||
* of 16 zones to print. For this example, only the data of first zone are
|
||||
* print */
|
||||
printf("Print data no : %3u\n", Dev.streamcount);
|
||||
for(i = 0; i < 16; i++)
|
||||
{
|
||||
printf("Zone : %3d, Status : %3u, Distance : %4d mm\n",
|
||||
i,
|
||||
Results.target_status[VL53L8CX_NB_TARGET_PER_ZONE*i],
|
||||
Results.distance_mm[VL53L8CX_NB_TARGET_PER_ZONE*i]);
|
||||
}
|
||||
printf("\n");
|
||||
loop++;
|
||||
}
|
||||
|
||||
/* Wait a few ms to avoid too high polling (function in platform
|
||||
* file, not in API) */
|
||||
WaitMs(&(Dev.platform), 5);
|
||||
}
|
||||
|
||||
status = vl53l8cx_stop_ranging(&Dev);
|
||||
printf("End of ULD demo\n");
|
||||
return status;
|
||||
}
|
||||
@@ -0,0 +1,240 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2020, STMicroelectronics - All Rights Reserved
|
||||
*
|
||||
* This file is part of the VL53L8CX Ultra Lite Driver and is dual licensed,
|
||||
* either 'STMicroelectronics Proprietary license'
|
||||
* or 'BSD 3-clause "New" or "Revised" License' , at your option.
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* 'STMicroelectronics Proprietary license'
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* License terms: STMicroelectronics Proprietary in accordance with licensing
|
||||
* terms at www.st.com/sla0081
|
||||
*
|
||||
* STMicroelectronics confidential
|
||||
* Reproduction and Communication of this document is strictly prohibited unless
|
||||
* specifically authorized in writing by STMicroelectronics.
|
||||
*
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* Alternatively, the VL53L8CX Ultra Lite Driver may be distributed under the
|
||||
* terms of 'BSD 3-clause "New" or "Revised" License', in which case the
|
||||
* following provisions apply instead of the ones mentioned above :
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* License terms: BSD 3-clause "New" or "Revised" License.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/***********************************/
|
||||
/* VL53L8CX ULD visualize Xtalk */
|
||||
/***********************************/
|
||||
/*
|
||||
* This example shows the possibility of VL53L8CX to visualize Xtalk data. It
|
||||
* initializes the VL53L8CX ULD, perform a Xtalk calibration, and starts
|
||||
* a ranging to capture 10 frames.
|
||||
|
||||
* In this example, we also suppose that the number of target per zone is
|
||||
* set to 1 , and all output are enabled (see file platform.h).
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "vl53l8cx_api.h"
|
||||
#include "vl53l8cx_plugin_xtalk.h"
|
||||
|
||||
int example8(void)
|
||||
{
|
||||
|
||||
/*********************************/
|
||||
/* VL53L8CX ranging variables */
|
||||
/*********************************/
|
||||
|
||||
uint8_t status, loop, isAlive, isReady;
|
||||
VL53L8CX_Configuration Dev; /* Sensor configuration */
|
||||
VL53L8CX_ResultsData Results; /* Results data from VL53L8CX */
|
||||
|
||||
/* Buffer containing Xtalk data */
|
||||
uint8_t xtalk_data[VL53L8CX_XTALK_BUFFER_SIZE];
|
||||
|
||||
|
||||
/*********************************/
|
||||
/* Customer platform */
|
||||
/*********************************/
|
||||
|
||||
/* Fill the platform structure with customer's implementation. For this
|
||||
* example, only the I2C address is used.
|
||||
*/
|
||||
Dev.platform.address = VL53L8CX_DEFAULT_I2C_ADDRESS;
|
||||
|
||||
/* (Optional) Reset sensor toggling PINs (see platform, not in API) */
|
||||
//Reset_Sensor(&(Dev.platform));
|
||||
|
||||
/* (Optional) Set a new I2C address if the wanted address is different
|
||||
* from the default one (filled with 0x20 for this example).
|
||||
*/
|
||||
//status = vl53l8cx_set_i2c_address(&Dev, 0x20);
|
||||
|
||||
|
||||
/*********************************/
|
||||
/* Power on sensor and init */
|
||||
/*********************************/
|
||||
|
||||
/* (Optional) Check if there is a VL53L8CX sensor connected */
|
||||
status = vl53l8cx_is_alive(&Dev, &isAlive);
|
||||
if(!isAlive || status)
|
||||
{
|
||||
printf("VL53L8CX not detected at requested address\n");
|
||||
return status;
|
||||
}
|
||||
|
||||
/* (Mandatory) Init VL53L8CX sensor */
|
||||
status = vl53l8cx_init(&Dev);
|
||||
if(status)
|
||||
{
|
||||
printf("VL53L8CX ULD Loading failed\n");
|
||||
return status;
|
||||
}
|
||||
|
||||
printf("VL53L8CX ULD ready ! (Version : %s)\n",
|
||||
VL53L8CX_API_REVISION);
|
||||
|
||||
|
||||
/*********************************/
|
||||
/* Start Xtalk calibration */
|
||||
/*********************************/
|
||||
|
||||
/* Start Xtalk calibration with a 3% reflective target at 600mm for the
|
||||
* sensor, using 4 samples.
|
||||
*/
|
||||
|
||||
printf("Running Xtalk calibration...\n");
|
||||
|
||||
status = vl53l8cx_calibrate_xtalk(&Dev, 3, 4, 600);
|
||||
if(status)
|
||||
{
|
||||
printf("vl53l8cx_calibrate_xtalk failed, status %u\n", status);
|
||||
return status;
|
||||
}else
|
||||
{
|
||||
printf("Xtalk calibration done\n");
|
||||
|
||||
/* Get Xtalk calibration data, in order to use them later */
|
||||
status = vl53l8cx_get_caldata_xtalk(&Dev, xtalk_data);
|
||||
|
||||
/* Set Xtalk calibration data */
|
||||
status = vl53l8cx_set_caldata_xtalk(&Dev, xtalk_data);
|
||||
}
|
||||
|
||||
/* (Optional) Visualize Xtalk grid and Xtalk shape */
|
||||
uint32_t i, j;
|
||||
union Block_header *bh_ptr;
|
||||
uint32_t xtalk_signal_kcps_grid[VL53L8CX_RESOLUTION_8X8];
|
||||
uint16_t xtalk_shape_bins[144];
|
||||
|
||||
/* Swap buffer */
|
||||
SwapBuffer(xtalk_data, VL53L8CX_XTALK_BUFFER_SIZE);
|
||||
|
||||
/* Get data */
|
||||
for(i = 0; i < VL53L8CX_XTALK_BUFFER_SIZE; i = i + 4)
|
||||
{
|
||||
bh_ptr = (union Block_header *)&(xtalk_data[i]);
|
||||
if (bh_ptr->idx == 0xA128){
|
||||
printf("Xtalk shape bins located at position %#06x\n", (int)i);
|
||||
for (j = 0; j < 144; j++){
|
||||
memcpy(&(xtalk_shape_bins[j]), &(xtalk_data[i + 4 + j * 2]), 2);
|
||||
printf("xtalk_shape_bins[%d] = %d\n", (int)j, (int)xtalk_shape_bins[j]);
|
||||
}
|
||||
}
|
||||
if (bh_ptr->idx == 0x9FFC){
|
||||
printf("Xtalk signal kcps located at position %#06x\n", (int)i);
|
||||
for (j = 0; j < VL53L8CX_RESOLUTION_8X8; j++){
|
||||
memcpy(&(xtalk_signal_kcps_grid[j]), &(xtalk_data[i + 4 + j * 4]), 4);
|
||||
xtalk_signal_kcps_grid[j] /= 2048;
|
||||
printf("xtalk_signal_kcps_grid[%d] = %d\n", (int)j, (int)xtalk_signal_kcps_grid[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Re-Swap buffer (in case of re-using data later) */
|
||||
SwapBuffer(xtalk_data, VL53L8CX_XTALK_BUFFER_SIZE);
|
||||
|
||||
|
||||
/*********************************/
|
||||
/* Ranging loop */
|
||||
/*********************************/
|
||||
|
||||
status = vl53l8cx_start_ranging(&Dev);
|
||||
|
||||
loop = 0;
|
||||
while(loop < 10)
|
||||
{
|
||||
/* Use polling function to know when a new measurement is ready.
|
||||
* Another way can be to wait for HW interrupt raised on PIN A1
|
||||
* (INT) when a new measurement is ready */
|
||||
|
||||
status = vl53l8cx_check_data_ready(&Dev, &isReady);
|
||||
|
||||
if(isReady)
|
||||
{
|
||||
vl53l8cx_get_ranging_data(&Dev, &Results);
|
||||
|
||||
/* As the sensor is set in 4x4 mode by default, we have a total
|
||||
* of 16 zones to print. For this example, only the data of first zone are
|
||||
* print */
|
||||
printf("Print data no : %3u\n", Dev.streamcount);
|
||||
for(i = 0; i < 16; i++)
|
||||
{
|
||||
printf("Zone : %3d, Status : %3u, Distance : %4d mm\n",
|
||||
(int)i,
|
||||
Results.target_status[VL53L8CX_NB_TARGET_PER_ZONE*i],
|
||||
Results.distance_mm[VL53L8CX_NB_TARGET_PER_ZONE*i]);
|
||||
}
|
||||
printf("\n");
|
||||
loop++;
|
||||
}
|
||||
|
||||
/* Wait a few ms to avoid too high polling (function in platform
|
||||
* file, not in API) */
|
||||
WaitMs(&(Dev.platform), 5);
|
||||
}
|
||||
|
||||
status = vl53l8cx_stop_ranging(&Dev);
|
||||
printf("End of ULD demo\n");
|
||||
return status;
|
||||
}
|
||||
@@ -0,0 +1,245 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2020, STMicroelectronics - All Rights Reserved
|
||||
*
|
||||
* This file is part of the VL53L8CX Ultra Lite Driver and is dual licensed,
|
||||
* either 'STMicroelectronics Proprietary license'
|
||||
* or 'BSD 3-clause "New" or "Revised" License' , at your option.
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* 'STMicroelectronics Proprietary license'
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* License terms: STMicroelectronics Proprietary in accordance with licensing
|
||||
* terms at www.st.com/sla0081
|
||||
*
|
||||
* STMicroelectronics confidential
|
||||
* Reproduction and Communication of this document is strictly prohibited unless
|
||||
* specifically authorized in writing by STMicroelectronics.
|
||||
*
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* Alternatively, the VL53L8CX Ultra Lite Driver may be distributed under the
|
||||
* terms of 'BSD 3-clause "New" or "Revised" License', in which case the
|
||||
* following provisions apply instead of the ones mentioned above :
|
||||
*
|
||||
********************************************************************************
|
||||
*
|
||||
* License terms: BSD 3-clause "New" or "Revised" License.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/***********************************/
|
||||
/* VL53L8CX ULD interrupt checkers */
|
||||
/***********************************/
|
||||
/*
|
||||
* This example shows the possibility of VL53L8CX to program detection thresholds. It
|
||||
* initializes the VL53L8CX ULD, create 2 thresholds per zone for a 4x4 resolution,
|
||||
* and starts a ranging to capture 10 frames.
|
||||
|
||||
* In this example, we also suppose that the number of target per zone is
|
||||
* set to 1 , and all output are enabled (see file platform.h).
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "vl53l8cx_api.h"
|
||||
#include "vl53l8cx_plugin_detection_thresholds.h"
|
||||
|
||||
#define UNUSED(x) (void)(x)
|
||||
|
||||
/* This function needs to be filled by the customer. It allows knowing when
|
||||
* the VL53L8CX interrupt is raised on GPIO1. This is the only way to use detection thresholds.
|
||||
*/
|
||||
int WaitForL8CXInterrupt(VL53L8CX_Configuration * pDev) {
|
||||
|
||||
//Add your implementation here ...
|
||||
UNUSED(pDev);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int example9(void)
|
||||
{
|
||||
|
||||
/*********************************/
|
||||
/* VL53L8CX ranging variables */
|
||||
/*********************************/
|
||||
|
||||
uint8_t status, loop, isAlive, isReady, i;
|
||||
VL53L8CX_Configuration Dev; /* Sensor configuration */
|
||||
VL53L8CX_ResultsData Results; /* Results data from VL53L8CX */
|
||||
|
||||
|
||||
/*********************************/
|
||||
/* Customer platform */
|
||||
/*********************************/
|
||||
|
||||
/* Fill the platform structure with customer's implementation. For this
|
||||
* example, only the I2C address is used.
|
||||
*/
|
||||
Dev.platform.address = VL53L8CX_DEFAULT_I2C_ADDRESS;
|
||||
|
||||
/* (Optional) Reset sensor toggling PINs (see platform, not in API) */
|
||||
//Reset_Sensor(&(Dev.platform));
|
||||
|
||||
/* (Optional) Set a new I2C address if the wanted address is different
|
||||
* from the default one (filled with 0x20 for this example).
|
||||
*/
|
||||
//status = vl53l8cx_set_i2c_address(&Dev, 0x20);
|
||||
|
||||
|
||||
/*********************************/
|
||||
/* Power on sensor and init */
|
||||
/*********************************/
|
||||
|
||||
/* (Optional) Check if there is a VL53L8CX sensor connected */
|
||||
status = vl53l8cx_is_alive(&Dev, &isAlive);
|
||||
if(!isAlive || status)
|
||||
{
|
||||
printf("VL53L8CX not detected at requested address\n");
|
||||
return status;
|
||||
}
|
||||
|
||||
/* (Mandatory) Init VL53L8CX sensor */
|
||||
status = vl53l8cx_init(&Dev);
|
||||
if(status)
|
||||
{
|
||||
printf("VL53L8CX ULD Loading failed\n");
|
||||
return status;
|
||||
}
|
||||
|
||||
printf("VL53L8CX ULD ready ! (Version : %s)\n",
|
||||
VL53L8CX_API_REVISION);
|
||||
|
||||
/*********************************/
|
||||
/* Program detection thresholds */
|
||||
/*********************************/
|
||||
|
||||
/* In this example, we want 2 thresholds per zone for a 4x4 resolution */
|
||||
/* Create array of thresholds (size cannot be changed) */
|
||||
VL53L8CX_DetectionThresholds thresholds[VL53L8CX_NB_THRESHOLDS];
|
||||
|
||||
/* Set all values to 0 */
|
||||
memset(&thresholds, 0, sizeof(thresholds));
|
||||
|
||||
/* Add thresholds for all zones (16 zones in resolution 4x4, or 64 in 8x8) */
|
||||
for(i = 0; i < 16; i++){
|
||||
/* The first wanted thresholds is GREATER_THAN mode. Please note that the
|
||||
* first one must always be set with a mathematic_operation
|
||||
* VL53L8CX_OPERATION_NONE.
|
||||
* For this example, the signal thresholds is set to 150 kcps/spads
|
||||
* (the format is automatically updated inside driver)
|
||||
*/
|
||||
thresholds[2*i].zone_num = i;
|
||||
thresholds[2*i].measurement = VL53L8CX_SIGNAL_PER_SPAD_KCPS;
|
||||
thresholds[2*i].type = VL53L8CX_GREATER_THAN_MAX_CHECKER;
|
||||
thresholds[2*i].mathematic_operation = VL53L8CX_OPERATION_NONE;
|
||||
thresholds[2*i].param_low_thresh = 150;
|
||||
thresholds[2*i].param_high_thresh = 150;
|
||||
|
||||
/* The second wanted checker is IN_WINDOW mode. We will set a
|
||||
* mathematical thresholds VL53L8CX_OPERATION_OR, to add the previous
|
||||
* checker to this one.
|
||||
* For this example, distance thresholds are set between 200mm and
|
||||
* 400mm (the format is automatically updated inside driver).
|
||||
*/
|
||||
thresholds[2*i+1].zone_num = i;
|
||||
thresholds[2*i+1].measurement = VL53L8CX_DISTANCE_MM;
|
||||
thresholds[2*i+1].type = VL53L8CX_IN_WINDOW;
|
||||
thresholds[2*i+1].mathematic_operation = VL53L8CX_OPERATION_OR;
|
||||
thresholds[2*i+1].param_low_thresh = 200;
|
||||
thresholds[2*i+1].param_high_thresh = 400;
|
||||
}
|
||||
|
||||
/* The last thresholds must be clearly indicated. As we have 32
|
||||
* checkers (16 zones x 2), the last one is the 31 */
|
||||
thresholds[31].zone_num = VL53L8CX_LAST_THRESHOLD | thresholds[31].zone_num;
|
||||
|
||||
/* Send array of thresholds to the sensor */
|
||||
vl53l8cx_set_detection_thresholds(&Dev, thresholds);
|
||||
|
||||
/* Enable detection thresholds */
|
||||
vl53l8cx_set_detection_thresholds_enable(&Dev, 1);
|
||||
|
||||
/*********************************/
|
||||
/* Ranging loop */
|
||||
/*********************************/
|
||||
|
||||
status = vl53l8cx_set_ranging_frequency_hz(&Dev, 10);
|
||||
|
||||
IntCount = 0;
|
||||
status = vl53l8cx_start_ranging(&Dev);
|
||||
printf("Put an object between 200mm and 400mm to catch an interrupt\n");
|
||||
|
||||
loop = 0;
|
||||
while(loop < 100)
|
||||
{
|
||||
/* Function WaitForL8CXInterrupt() does not exists, and must be
|
||||
* implemented by user. It allows catching the interrupt raised on
|
||||
* pin A1 (INT), when the checkers detect the programmed
|
||||
* conditions.
|
||||
*/
|
||||
|
||||
isReady = WaitForL8CXInterrupt(&Dev);
|
||||
if(isReady)
|
||||
{
|
||||
vl53l8cx_get_ranging_data(&Dev, &Results);
|
||||
|
||||
/* As the sensor is set in 4x4 mode by default, we have a total
|
||||
* of 16 zones to print. For this example, only the data of
|
||||
* first zone are print */
|
||||
printf("Print data no : %3u\n", Dev.streamcount);
|
||||
for(i = 0; i < 16; i++)
|
||||
{
|
||||
printf("Zone : %3d, Status : %3u, Distance : %4d mm, Signal : %5lu kcps/SPADs\n",
|
||||
i,
|
||||
Results.target_status[VL53L8CX_NB_TARGET_PER_ZONE*i],
|
||||
Results.distance_mm[VL53L8CX_NB_TARGET_PER_ZONE*i],
|
||||
Results.signal_per_spad[VL53L8CX_NB_TARGET_PER_ZONE*i]);
|
||||
}
|
||||
printf("\n");
|
||||
loop++;
|
||||
}
|
||||
|
||||
/* Wait a few ms to avoid too high polling (function in platform
|
||||
* file, not in API) */
|
||||
WaitMs(&(Dev.platform), 5);
|
||||
}
|
||||
|
||||
status = vl53l8cx_stop_ranging(&Dev);
|
||||
printf("End of ULD demo\n");
|
||||
return status;
|
||||
}
|
||||
Reference in new issue
Block a user