diff --git a/examples/README.txt b/examples/README.txt index 5aaed9c0e..5e604b4ba 100644 --- a/examples/README.txt +++ b/examples/README.txt @@ -691,6 +691,21 @@ examples/lis2csh_reader A simple reader example for the LIS3DSH acceleration sensor as found on STM32F4Discovery rev. C +examples/hts221_reader +^^^^^^^^^^^^^^^^^^^^^^^ + + A simple reader example for the HTS221 humidity sensor. + +examples/lsm303_reader +^^^^^^^^^^^^^^^^^^^^^^^ + + A simple reader example for the LSM303 acc-mag sensor. + +examples/lsm6dsl_reader +^^^^^^^^^^^^^^^^^^^^^^^ + + A simple reader example for the LSM6DSL acc-gyro sensor. + examples/media ^^^^^^^^^^^^^^ diff --git a/examples/hts221_reader/Kconfig b/examples/hts221_reader/Kconfig new file mode 100755 index 000000000..e1717444a --- /dev/null +++ b/examples/hts221_reader/Kconfig @@ -0,0 +1,11 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +config EXAMPLES_HTS221_READER + bool "HTS221 reader example" + default n + depends on SENSORS_HTS221 + ---help--- + Enable the HTS221 reader example diff --git a/examples/hts221_reader/Make.defs b/examples/hts221_reader/Make.defs new file mode 100755 index 000000000..7073fe5ec --- /dev/null +++ b/examples/hts221_reader/Make.defs @@ -0,0 +1,39 @@ +############################################################################ +# apps/examples/hts221_reader/Make.defs +# Adds selected applications to apps/ build +# +# Copyright (C) 2020 Gregory Nutt. All rights reserved. +# Author: Mateusz Szafoni +# +# 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. +# +############################################################################ + +ifeq ($(CONFIG_EXAMPLES_HTS221_READER),y) +CONFIGURED_APPS += examples/hts221_reader +endif diff --git a/examples/hts221_reader/Makefile b/examples/hts221_reader/Makefile new file mode 100755 index 000000000..a0a9a6bce --- /dev/null +++ b/examples/hts221_reader/Makefile @@ -0,0 +1,49 @@ +############################################################################ +# apps/examples/hts221_reader/Makefile +# +# Copyright (C) 2020 Gregory Nutt. All rights reserved. +# Author: Mateusz Szafoni +# +# 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 + +# hts221_reader example + +MAINSRC = hts221_reader_main.c + +# application info + +PROGNAME = hts221_reader +PRIORITY = SCHED_PRIORITY_DEFAULT +STACKSIZE = 2048 +MODULE = $(CONFIG_EXAMPLES_HTS221_READER) + +include $(APPDIR)/Application.mk diff --git a/examples/hts221_reader/hts221_reader_main.c b/examples/hts221_reader/hts221_reader_main.c new file mode 100644 index 000000000..433b91de3 --- /dev/null +++ b/examples/hts221_reader/hts221_reader_main.c @@ -0,0 +1,97 @@ +/**************************************************************************** + * examples/hts221_reader/hts221_reader_main.c + * + * Copyright (C) 2020 Gregory Nutt. All rights reserved. + * Author: Mateusz Szafoni + * + * 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 + +#include +#include +#include +#include +#include + +#include + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * lsm303_reader_main + ****************************************************************************/ + +int main(int argc, FAR char *argv[]) +{ + FILE *sensor; + hts221_conv_data_t sensor_data; + int ret; + + sensor = fopen("/dev/hts2210", "r"); + if (sensor == NULL) + { + printf("Unable to create file\n"); + return -ENOENT; + } + + ret = ioctl(fileno(sensor), SNIOC_START, 0); + if (ret < 0) + { + printf("IOCTL SNIOC_START failed %d\n", ret); + } + + for (; ; ) + { + ret = ioctl(fileno(sensor), SNIOC_READ_CONVERT_DATA, + (unsigned long)&sensor_data); + if (ret < 0) + { + printf("IOCTL READ failed %d\n", ret); + } + + printf("temp: %d, hum: %d\n", + sensor_data.temperature, + sensor_data.humidity); + + sleep(2); + } + + fclose(sensor); + return EXIT_SUCCESS; +} diff --git a/examples/lsm303_reader/Kconfig b/examples/lsm303_reader/Kconfig new file mode 100755 index 000000000..501f9051f --- /dev/null +++ b/examples/lsm303_reader/Kconfig @@ -0,0 +1,11 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +config EXAMPLES_LSM303_READER + bool "LSM303 reader example" + default n + depends on SENSORS_LSM303AGR + ---help--- + Enable the LSM303 reader example diff --git a/examples/lsm303_reader/Make.defs b/examples/lsm303_reader/Make.defs new file mode 100755 index 000000000..75dfb3410 --- /dev/null +++ b/examples/lsm303_reader/Make.defs @@ -0,0 +1,39 @@ +############################################################################ +# apps/examples/lsm303_reader/Make.defs +# Adds selected applications to apps/ build +# +# Copyright (C) 2020 Gregory Nutt. All rights reserved. +# Author: Mateusz Szafoni +# +# 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. +# +############################################################################ + +ifeq ($(CONFIG_EXAMPLES_LSM303_READER),y) +CONFIGURED_APPS += examples/lsm303_reader +endif diff --git a/examples/lsm303_reader/Makefile b/examples/lsm303_reader/Makefile new file mode 100755 index 000000000..0e11a15c8 --- /dev/null +++ b/examples/lsm303_reader/Makefile @@ -0,0 +1,49 @@ +############################################################################ +# apps/examples/lsm303_reader/Makefile +# +# Copyright (C) 2020 Gregory Nutt. All rights reserved. +# Author: Mateusz Szafoni +# +# 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 + +# lsm303_reader example + +MAINSRC = lsm303_reader_main.c + +# application info + +PROGNAME = lsm303_reader +PRIORITY = SCHED_PRIORITY_DEFAULT +STACKSIZE = 2048 +MODULE = $(CONFIG_EXAMPLES_LSM303_READER) + +include $(APPDIR)/Application.mk diff --git a/examples/lsm303_reader/lsm303_reader_main.c b/examples/lsm303_reader/lsm303_reader_main.c new file mode 100644 index 000000000..a51f4661c --- /dev/null +++ b/examples/lsm303_reader/lsm303_reader_main.c @@ -0,0 +1,103 @@ +/**************************************************************************** + * examples/lsm303_reader/lsm303_reader_main.c + * + * Copyright (C) 2020 Gregory Nutt. All rights reserved. + * Author: Mateusz Szafoni + * + * 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 + +#include +#include +#include +#include +#include + +#include + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * lsm303_reader_main + ****************************************************************************/ + +int main(int argc, FAR char *argv[]) +{ + FILE *sensor; + struct lsm303agr_sensor_data_s sensor_data; + int ret; + + sensor = fopen("/dev/lsm303agr0", "r"); + if (sensor == NULL) + { + printf("Unable to create file\n"); + return -ENOENT; + } + + ret = ioctl(fileno(sensor), SNIOC_START, 0); + if (ret < 0) + { + printf("IOCTL SNIOC_START failed %d\n", ret); + } + + for (; ; ) + { + ret = ioctl(fileno(sensor), SNIOC_LSM303AGRSENSORREAD, + (unsigned long)&sensor_data); + if (ret < 0) + { + printf("IOCTL READ failed %d\n", ret); + } + + printf("time:%d x:%d y:%d z:%d m_x:%d m_y:%d m_z:%d temp:%d\n", + sensor_data.timestamp, + sensor_data.x_data, + sensor_data.y_data, + sensor_data.z_data, + sensor_data.m_x_data, + sensor_data.m_y_data, + sensor_data.m_z_data, + sensor_data.temperature); + + sleep(2); + } + + fclose(sensor); + return EXIT_SUCCESS; +} diff --git a/examples/lsm6dsl_reader/Kconfig b/examples/lsm6dsl_reader/Kconfig new file mode 100755 index 000000000..d27e77008 --- /dev/null +++ b/examples/lsm6dsl_reader/Kconfig @@ -0,0 +1,11 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +config EXAMPLES_LSM6DSL_READER + bool "LSM6DSL reader example" + default n + depends on SENSORS_LSM6DSL + ---help--- + Enable the LSM6DSL reader example diff --git a/examples/lsm6dsl_reader/Make.defs b/examples/lsm6dsl_reader/Make.defs new file mode 100755 index 000000000..9fed1ce5f --- /dev/null +++ b/examples/lsm6dsl_reader/Make.defs @@ -0,0 +1,39 @@ +############################################################################ +# apps/examples/lsm6dsl_reader/Make.defs +# Adds selected applications to apps/ build +# +# Copyright (C) 2017 Florian Olbrich. All rights reserved. +# Author: Florian Olbrich +# +# 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. +# +############################################################################ + +ifeq ($(CONFIG_EXAMPLES_LSM6DSL_READER),y) +CONFIGURED_APPS += examples/lsm6dsl_reader +endif diff --git a/examples/lsm6dsl_reader/Makefile b/examples/lsm6dsl_reader/Makefile new file mode 100755 index 000000000..4d558b088 --- /dev/null +++ b/examples/lsm6dsl_reader/Makefile @@ -0,0 +1,49 @@ +############################################################################ +# apps/examples/lsm6dsl_reader/Makefile +# +# Copyright (C) 2020 Gregory Nutt. All rights reserved. +# Author: Mateusz Szafoni +# +# 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 + +# lsm6dsl_reader example + +MAINSRC = lsm6dsl_reader_main.c + +# application info + +PROGNAME = lsm6dsl_reader +PRIORITY = SCHED_PRIORITY_DEFAULT +STACKSIZE = 2048 +MODULE = $(CONFIG_EXAMPLES_LSM6DSL_READER) + +include $(APPDIR)/Application.mk diff --git a/examples/lsm6dsl_reader/lsm6dsl_reader_main.c b/examples/lsm6dsl_reader/lsm6dsl_reader_main.c new file mode 100644 index 000000000..ca935d858 --- /dev/null +++ b/examples/lsm6dsl_reader/lsm6dsl_reader_main.c @@ -0,0 +1,103 @@ +/**************************************************************************** + * examples/lsm6dsl_reader/lsm6dsl_reader_main.c + * + * Copyright (C) 2020 Gregory Nutt. All rights reserved. + * Author: Mateusz Szafoni + * + * 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 + +#include +#include +#include +#include +#include + +#include + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * lsm6dsl_reader_main + ****************************************************************************/ + +int main(int argc, FAR char *argv[]) +{ + FILE *sensor; + struct lsm6dsl_sensor_data_s sensor_data; + int ret; + + sensor = fopen("/dev/lsm6dsl0", "r"); + if (sensor == NULL) + { + printf("Unable to create file\n"); + return -ENOENT; + } + + ret = ioctl(fileno(sensor), SNIOC_START, 0); + if (ret < 0) + { + printf("IOCTL SNIOC_START failed %d\n", ret); + } + + for (; ; ) + { + ret = ioctl(fileno(sensor), SNIOC_LSM6DSLSENSORREAD, + (unsigned long)&sensor_data); + if (ret < 0) + { + printf("IOCTL READ failed %d\n", ret); + } + + printf("time:%d x:%d y:%d z:%d m_x:%d m_y:%d m_z:%d temp:%d\n", + sensor_data.timestamp, + sensor_data.x_data, + sensor_data.y_data, + sensor_data.z_data, + sensor_data.g_x_data, + sensor_data.g_y_data, + sensor_data.g_z_data, + sensor_data.temperature); + + sleep(2); + } + + fclose(sensor); + return EXIT_SUCCESS; +}