This is an automated email from the ASF dual-hosted git repository. archer pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push: new 0e8e08e Add example app for isl29023 driver 0e8e08e is described below commit 0e8e08e2a0029fbccc56292afe6f3cbae1001836 Author: Diego Herranz <diegoherr...@diegoherranz.com> AuthorDate: Mon Dec 20 22:44:01 2021 +0100 Add example app for isl29023 driver Created from the hdc1008_demo example. --- examples/isl29023/Kconfig | 11 ++++ examples/isl29023/Make.defs | 23 ++++++++ examples/isl29023/Makefile | 32 +++++++++++ examples/isl29023/isl29023_main.c | 114 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 180 insertions(+) diff --git a/examples/isl29023/Kconfig b/examples/isl29023/Kconfig new file mode 100644 index 0000000..3999d8f --- /dev/null +++ b/examples/isl29023/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_ISL29023 + tristate "ISL29023 driver example" + default n + ---help--- + Enable the example application + diff --git a/examples/isl29023/Make.defs b/examples/isl29023/Make.defs new file mode 100644 index 0000000..f6497bb --- /dev/null +++ b/examples/isl29023/Make.defs @@ -0,0 +1,23 @@ +############################################################################ +# apps/examples/isl29023/Make.defs +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################/ + +ifneq ($(CONFIG_EXAMPLES_ISL29023),) +CONFIGURED_APPS += $(APPDIR)/examples/isl29023 +endif diff --git a/examples/isl29023/Makefile b/examples/isl29023/Makefile new file mode 100644 index 0000000..7e3a080 --- /dev/null +++ b/examples/isl29023/Makefile @@ -0,0 +1,32 @@ +############################################################################ +# apps/examples/isl29023/Makefile +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################/ + +include $(APPDIR)/Make.defs + +# isl29023 example built-in application info + +PROGNAME = isl29023 +PRIORITY = SCHED_PRIORITY_DEFAULT +STACKSIZE = $(CONFIG_DEFAULT_TASK_STACKSIZE) +MODULE = $(CONFIG_EXAMPLES_ISL29023) + +MAINSRC = isl29023_main.c + +include $(APPDIR)/Application.mk diff --git a/examples/isl29023/isl29023_main.c b/examples/isl29023/isl29023_main.c new file mode 100644 index 0000000..a354225 --- /dev/null +++ b/examples/isl29023/isl29023_main.c @@ -0,0 +1,114 @@ +/**************************************************************************** + * apps/examples/isl29023/isl29023_main.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> +#include <nuttx/sensors/isl29023.h> + +#include <sys/ioctl.h> +#include <sys/stat.h> +#include <sys/types.h> + +#include <fcntl.h> +#include <stdio.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define DEV_PATH "/dev/als0" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * isl29023_main + ****************************************************************************/ + +int main(int argc, FAR char *argv[]) +{ + struct isl29023_data_s data; + int fd; + int ret; + + fd = open(DEV_PATH, O_RDONLY); + if (fd < 0) + { + printf("Failed to open device driver at '%s'\n", DEV_PATH); + } + + /* Set continuous ALS mode */ + + ret = ioctl(fd, SNIOC_SET_OPERATIONAL_MODE, + ISL29023_OP_MODE_ALS_CONTINUES); + if (ret < 0) + { + printf("Failed to set isl29023 mode: %d\n", errno); + goto out; + } + + /* Set max resolution (16 bits) */ + + ret = ioctl(fd, SNIOC_SET_RESOLUTION, ISL29023_RESOLUTION_16BITS); + if (ret < 0) + { + printf("Failed to set isl29023 resolution: %d\n", errno); + goto out; + } + + /* Set max range (64000) */ + + ret = ioctl(fd, SNIOC_SET_RANGE, ISL29023_ALS_RANGE_64000); + if (ret < 0) + { + printf("Failed to set isl29023 range: %d\n", errno); + goto out; + } + + /* Wait for the initial conversion to complete. + * 90 ms (typ) for 16-bit conversion on isl29023, + * 105 ms for 16-bit conversion on isl29035 (compatible), + * so going for 110 ms. + */ + + usleep(110000); + + /* Read both lux and raw values */ + + ret = read(fd, &data, sizeof(data)); + if (ret < 0) + { + printf("FAILED to read lux and raw values from isl29023: %d\n", errno); + goto out; + } + + printf("lux: %d\n" + "raw: %d\n", data.lux, data.raw); + + ret = 0; + +out: + close(fd); + return ret; +}