From 3a4faf944a7b90c7720a7c2f5631470eb3035f3a Mon Sep 17 00:00:00 2001 From: Alan Carvalho de Assis Date: Sun, 28 Oct 2018 16:04:15 -0600 Subject: [PATCH] apps/examples/mlx90614: Add mlx90614 test example --- examples/mlx90614/.gitignore | 11 +++ examples/mlx90614/Kconfig | 23 ++++++ examples/mlx90614/Make.defs | 39 +++++++++ examples/mlx90614/Makefile | 55 +++++++++++++ examples/mlx90614/mlx90614_main.c | 132 ++++++++++++++++++++++++++++++ 5 files changed, 260 insertions(+) create mode 100644 examples/mlx90614/.gitignore create mode 100644 examples/mlx90614/Kconfig create mode 100644 examples/mlx90614/Make.defs create mode 100644 examples/mlx90614/Makefile create mode 100644 examples/mlx90614/mlx90614_main.c diff --git a/examples/mlx90614/.gitignore b/examples/mlx90614/.gitignore new file mode 100644 index 000000000..fa1ec7579 --- /dev/null +++ b/examples/mlx90614/.gitignore @@ -0,0 +1,11 @@ +/Make.dep +/.depend +/.built +/*.asm +/*.obj +/*.rel +/*.lst +/*.sym +/*.adb +/*.lib +/*.src diff --git a/examples/mlx90614/Kconfig b/examples/mlx90614/Kconfig new file mode 100644 index 000000000..bdd67ccd2 --- /dev/null +++ b/examples/mlx90614/Kconfig @@ -0,0 +1,23 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +config EXAMPLES_MLX90614 + tristate "MLX90614 Test Example" + default n + select LIBC_FLOATINGPOINT + ---help--- + Enable the MLX90614 example + +if EXAMPLES_MLX90614 + +config EXAMPLES_MLX90614_PROGNAME + string "Program name" + default "MLX90614 Test Example" + depends on BUILD_LOADABLE + ---help--- + This is the name of the program that will be use when the NSH ELF + program is installed. + +endif diff --git a/examples/mlx90614/Make.defs b/examples/mlx90614/Make.defs new file mode 100644 index 000000000..d97678d82 --- /dev/null +++ b/examples/mlx90614/Make.defs @@ -0,0 +1,39 @@ +############################################################################ +# apps/examples/mlx90614/Make.defs +# Adds selected applications to apps/ build +# +# Copyright (C) 2018 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# 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_MLX90614),) +CONFIGURED_APPS += examples/mlx90614 +endif diff --git a/examples/mlx90614/Makefile b/examples/mlx90614/Makefile new file mode 100644 index 000000000..7e0dc78f3 --- /dev/null +++ b/examples/mlx90614/Makefile @@ -0,0 +1,55 @@ +############################################################################ +# apps/examples/mlx90614/Makefile +# +# Copyright (C) 2018 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# 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 + +# MLX90614 built-in application info + +APPNAME = mlx90614 +PRIORITY = SCHED_PRIORITY_DEFAULT +STACKSIZE = 2048 + +# MLX90614 Test + +ASRCS = +CSRCS = +MAINSRC = mlx90614_main.c + +CONFIG_EXAMPLES_MLX90614_PROGNAME ?= mlx90614$(EXEEXT) +PROGNAME = $(CONFIG_EXAMPLES_MLX90614_PROGNAME) + +MODULE = CONFIG_EXAMPLES_MLX90614 + +include $(APPDIR)/Application.mk diff --git a/examples/mlx90614/mlx90614_main.c b/examples/mlx90614/mlx90614_main.c new file mode 100644 index 000000000..81a42f874 --- /dev/null +++ b/examples/mlx90614/mlx90614_main.c @@ -0,0 +1,132 @@ +/**************************************************************************** + * examples/mlx90614/mlx90614_main.c + * + * Copyright (C) 2017 Gregory Nutt. All rights reserved. + * Copyright (c) 2015-2017 Pololu Corporation. + * Author: Alan Carvalho de Assis + * + * 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 +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define CONFIG_EXAMPLES_MLX90614_DEVNAME "/dev/therm0" + +/* If MLX90614 has two internal thermopile change it to 1 */ + +#define MLX90614_DUALTHERMOPILE 0 + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +#define MILISEC_DELAY 1000 + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * mlx90614_main + ****************************************************************************/ + +#ifdef BUILD_MODULE +int main(int argc, FAR char *argv[]) +#else +int mlx90614_main(int argc, char *argv[]) +#endif +{ + FAR struct mlx90614_temp_s temp; + float ta; + float tobj1; +#if MLX90614_DUALTHERMOPILE + float tobj2; +#endif + int fd; + int ret; + + fd = open(CONFIG_EXAMPLES_MLX90614_DEVNAME, O_RDWR); + if (fd < 0) + { + fprintf(stderr, "ERROR: Failed to open %s: %d\n", + CONFIG_EXAMPLES_MLX90614_DEVNAME, errno); + return -1; + } + + for (; ; ) + { + /* Read new temperature from sensor */ + + ret = read(fd, &temp, sizeof(struct mlx90614_temp_s)); + if (ret < 0) + { + fprintf(stderr, "Failed to read MLX90614, ERROR: %d\n", errno); + } + + ta = (temp.ta * 0.02) - 273.15; + tobj1 = (temp.tobj1 * 0.02) - 273.15; +#if MLX90614_DUALTHERMOPILE + tobj2 = (temp.tobj2 * 0.02) - 273.15; +#endif + + printf("Ambient Temperature = %.2f ", ta); + printf("| Object 1 Temperature = %.2f ", tobj1); +#if MLX90614_DUALTHERMOPILE + printf("| Object 2 Temperature = %.2f", tobj2); +#endif + printf("\n"); + + usleep(MILISEC_DELAY * 1000); + } + + close(fd); + return 0; +}