examples/vl53l1x: Add VL53L1X example demo.
This commit is contained in:
parent
27766d7cdf
commit
94ac7dceab
12
examples/vl53l1x/.gitignore
vendored
Normal file
12
examples/vl53l1x/.gitignore
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
/hello
|
||||
/Make.dep
|
||||
/.depend
|
||||
/.built
|
||||
/*.asm
|
||||
/*.obj
|
||||
/*.rel
|
||||
/*.lst
|
||||
/*.sym
|
||||
/*.adb
|
||||
/*.lib
|
||||
/*.src
|
30
examples/vl53l1x/Kconfig
Normal file
30
examples/vl53l1x/Kconfig
Normal file
@ -0,0 +1,30 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
config EXAMPLES_VL53L1X
|
||||
tristate "\"VL53L1X\" example"
|
||||
default n
|
||||
---help---
|
||||
Enable the \"VL53L1X\" example
|
||||
|
||||
if EXAMPLES_VL53L1X
|
||||
|
||||
config EXAMPLES_VL53L1X_PROGNAME
|
||||
string "Program name"
|
||||
default "vl53l1x"
|
||||
depends on BUILD_LOADABLE
|
||||
---help---
|
||||
This is the name of the program that will be use when the NSH ELF
|
||||
program is installed.
|
||||
|
||||
config EXAMPLES_VL53L1X_PRIORITY
|
||||
int "VL53L1X priority"
|
||||
default 100
|
||||
|
||||
config EXAMPLES_VL53L1X_STACKSIZE
|
||||
int "VL53L1X stack size"
|
||||
default 2048
|
||||
|
||||
endif
|
39
examples/vl53l1x/Make.defs
Normal file
39
examples/vl53l1x/Make.defs
Normal file
@ -0,0 +1,39 @@
|
||||
############################################################################
|
||||
# apps/examples/vl53l1x/Make.defs
|
||||
# Adds selected applications to apps/ build
|
||||
#
|
||||
# Copyright (C) 2019 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# 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 NuttX 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 OWNER 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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
ifneq ($(CONFIG_EXAMPLES_VL53L1X),)
|
||||
CONFIGURED_APPS += examples/vl53l1x
|
||||
endif
|
55
examples/vl53l1x/Makefile
Normal file
55
examples/vl53l1x/Makefile
Normal file
@ -0,0 +1,55 @@
|
||||
############################################################################
|
||||
# apps/examples/vl53l1x/Makefile
|
||||
#
|
||||
# Copyright (C) 2019 Acutronics Robotics. All rights reserved.
|
||||
# Author: Acutronics Robotics (Juan Flores Muñoz) <juan@erlerobotics.com>
|
||||
#
|
||||
# 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 NuttX 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 OWNER 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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
-include $(TOPDIR)/Make.defs
|
||||
|
||||
CONFIG_EXAMPLES_VL53L1X_PRIORITY ?= SCHED_PRIORITY_DEFAULT
|
||||
CONFIG_EXAMPLES_VL53L1X_STACKSIZE ?= 2048
|
||||
|
||||
APPNAME = vl53l1x
|
||||
|
||||
PRIORITY = $(CONFIG_EXAMPLES_VL53L1X_PRIORITY)
|
||||
STACKSIZE = $(CONFIG_EXAMPLES_VL53L1X_STACKSIZE)
|
||||
|
||||
ASRCS =
|
||||
CSRCS =
|
||||
MAINSRC = vl53l1x_main.c
|
||||
|
||||
CONFIG_EXAMPLES_VL53L1X_PROGNAME ?= vl53l1x$(EXEEXT)
|
||||
PROGNAME = $(CONFIG_EXAMPLES_VL53L1X_PROGNAME)
|
||||
|
||||
MODULE = CONFIG_EXAMPLES_VL53L1X
|
||||
|
||||
include $(APPDIR)/Application.mk
|
135
examples/vl53l1x/vl53l1x_main.c
Normal file
135
examples/vl53l1x/vl53l1x_main.c
Normal file
@ -0,0 +1,135 @@
|
||||
/****************************************************************************
|
||||
* examples/vl53l1x/vl53l1x_main.c
|
||||
*
|
||||
* Copyright (C) 2019 Acutronics Robotics. All rights reserved.
|
||||
* Author: Acutronics Robotics (Juan Flores Muñoz) <juan@erlerobotics.com>
|
||||
*
|
||||
* 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 NuttX 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 OWNER 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <nuttx/sensors/vl53l1x.h>
|
||||
#include <nuttx/sensors/ioctl.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
static void error_message()
|
||||
{
|
||||
printf("VL53L1X help usage:\n");
|
||||
printf("vl53l1x -m <measure_mode> -c <calibration_distance>\n ");
|
||||
printf("measure_mode:\n");
|
||||
printf(" short-> Up to 1.3 mtr and higher precision\n");
|
||||
printf(" long-> Up to 4 mtr and lower precision\n");
|
||||
printf("calibration_distance:\n");
|
||||
printf(" Set a object to a known distance. "
|
||||
"Valid value between 10mm and 400mm or none\n");
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* hello_main
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(BUILD_MODULE)
|
||||
int main(int argc, FAR char *argv[])
|
||||
#else
|
||||
int vl53l1x_main(int argc, char *argv[])
|
||||
#endif
|
||||
{
|
||||
uint16_t calib_value = 0; /* Variable to save the calibration value */
|
||||
int fd; /* VL53L1X file descriptor */
|
||||
uint16_t result; /* Variable to save the return data of the
|
||||
* read.
|
||||
*/
|
||||
|
||||
if (argc == 1 || (argc == 2) && !strcmp(argv[1], "-h") || argc > 5 ||
|
||||
argc < 4)
|
||||
{
|
||||
error_message(); /* Just show the instructions of how to set-up
|
||||
* this App
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Opening the sensor with read only permission */
|
||||
|
||||
fd = open("/dev/tof0", O_RDONLY);
|
||||
|
||||
/* Setting the measure mode. */
|
||||
|
||||
if (!strcmp(argv[2], "long"))
|
||||
{
|
||||
ioctl(fd, SNIOC_DISTANCELONG);
|
||||
}
|
||||
else if (!strcmp(argv[2], "short"))
|
||||
{
|
||||
ioctl(fd, SNIOC_DISTANCESHORT);
|
||||
}
|
||||
else
|
||||
{
|
||||
error_message(); /* Just show the instructions of how to set-up
|
||||
* this App
|
||||
*/
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Set the calibration value */
|
||||
|
||||
if (argc == 5)
|
||||
{
|
||||
calib_value = atoi(argv[4]);
|
||||
if (calib_value > 10 || calib_value < 4000)
|
||||
{
|
||||
ioctl(fd, SNIOC_CALIBRATE, calib_value);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Error: Calibration not set, value out of range\n");
|
||||
}
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
/* Read the distance every 100 mS. */
|
||||
|
||||
read(fd, &result, sizeof(result));
|
||||
printf("Distance %i mm \n", result);
|
||||
usleep(100000);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user