Example application for the hdc1008 driver.
This commit is contained in:
parent
779635afa6
commit
0704bd2e49
11
examples/hdc1008_demo/Kconfig
Normal file
11
examples/hdc1008_demo/Kconfig
Normal file
@ -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_HDC1008
|
||||
tristate "HDC1008 driver example"
|
||||
default n
|
||||
---help---
|
||||
Enable the example application
|
||||
|
23
examples/hdc1008_demo/Make.defs
Normal file
23
examples/hdc1008_demo/Make.defs
Normal file
@ -0,0 +1,23 @@
|
||||
############################################################################
|
||||
# apps/examples/hdc1008_demo/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_HDC1008),)
|
||||
CONFIGURED_APPS += $(APPDIR)/examples/hdc1008_demo
|
||||
endif
|
32
examples/hdc1008_demo/Makefile
Normal file
32
examples/hdc1008_demo/Makefile
Normal file
@ -0,0 +1,32 @@
|
||||
############################################################################
|
||||
# apps/examples/hdc1008_demo/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 $(TOPDIR)/Make.defs
|
||||
|
||||
# hdc1008 example built-in application info
|
||||
|
||||
PROGNAME = hdc1008
|
||||
PRIORITY = SCHED_PRIORITY_DEFAULT
|
||||
STACKSIZE = $(CONFIG_DEFAULT_TASK_STACKSIZE)
|
||||
MODULE = $(CONFIG_EXAMPLES_HDC1008)
|
||||
|
||||
MAINSRC = hdc1008_main.c
|
||||
|
||||
include $(APPDIR)/Application.mk
|
169
examples/hdc1008_demo/hdc1008_main.c
Normal file
169
examples/hdc1008_demo/hdc1008_main.c
Normal file
@ -0,0 +1,169 @@
|
||||
/****************************************************************************
|
||||
* examples/hdc1008_demo/hdc1008_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/hdc1008.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/hdc1008"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* hdc1008_main
|
||||
****************************************************************************/
|
||||
|
||||
int main(int argc, FAR char *argv[])
|
||||
{
|
||||
struct hdc1008_conv_data_s data;
|
||||
int fd;
|
||||
int ret;
|
||||
int i;
|
||||
uint8_t res[3];
|
||||
char buf[16];
|
||||
|
||||
/* Available resolutions: 8/11/14 bits */
|
||||
|
||||
res[0] = 8;
|
||||
res[1] = 11;
|
||||
res[2] = 14;
|
||||
|
||||
fd = open(DEV_PATH, O_RDONLY);
|
||||
if (fd < 0)
|
||||
{
|
||||
printf("Failed to open device driver at '%s'\n", DEV_PATH);
|
||||
}
|
||||
|
||||
/* Read both t and rh */
|
||||
|
||||
ret = read(fd, buf, sizeof(buf));
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("FAILED to read temperature and rh: %d\n", errno);
|
||||
goto out;
|
||||
}
|
||||
|
||||
printf("Temperature and humidity\n"
|
||||
"========================\n");
|
||||
printf("data=%s%d\n\n", buf);
|
||||
|
||||
/* Measure using ioctl */
|
||||
|
||||
ret = ioctl(fd, SNIOC_MEASURE, (unsigned long)&data);
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("Failed to measure using ioctl: %d\n", errno);
|
||||
goto out;
|
||||
}
|
||||
|
||||
printf("Temperature and humidity (ioctl)\n"
|
||||
"================================\n");
|
||||
printf("t=%d.%d, h=%d.%d\n\n",
|
||||
data.temperature / 100, data.temperature % 100,
|
||||
data.humidity / 10, data.humidity % 10);
|
||||
|
||||
/* Enable heater */
|
||||
|
||||
ret = ioctl(fd, SNIOC_SET_HEATER_MODE, 1);
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("Failed to enable heater: %d\n", errno);
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* Read only t */
|
||||
|
||||
ret = ioctl(fd, SNIOC_SET_OPERATIONAL_MODE, HDC1008_MEAS_TEMPERATURE);
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("Failed to set temperature measurement only: %d\n", errno);
|
||||
goto out;
|
||||
}
|
||||
|
||||
for (i = 1; i < 3; ++i)
|
||||
{
|
||||
ret = ioctl(fd, SNIOC_SET_RESOLUTION_T, res[i]);
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("Failed to set temperature resolution: %d\n", errno);
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = read(fd, buf, sizeof(buf));
|
||||
printf("Temperature, %d bit resolution\n"
|
||||
"==============================\n", res[i]);
|
||||
printf("data=%s\n\n", buf);
|
||||
}
|
||||
|
||||
/* Disable heater */
|
||||
|
||||
ret = ioctl(fd, SNIOC_SET_HEATER_MODE, 0);
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("Failed to disable heater: %d\n", errno);
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* Read only rh */
|
||||
|
||||
ret = ioctl(fd, SNIOC_SET_OPERATIONAL_MODE, HDC1008_MEAS_HUMIDITY);
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("Failed to set humidity measurement only: %d\n", errno);
|
||||
goto out;
|
||||
}
|
||||
|
||||
for (i = 0; i < 3; ++i)
|
||||
{
|
||||
ret = ioctl(fd, SNIOC_SET_RESOLUTION_RH, res[i]);
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("Failed to set humidity resolution: %d\n", errno);
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = read(fd, buf, sizeof(buf));
|
||||
printf("Humidity, %d bit resolution\n"
|
||||
"===========\n", res[i]);
|
||||
printf("data=%s\n\n", buf);
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
out:
|
||||
close(fd);
|
||||
return ret;
|
||||
}
|
Loading…
Reference in New Issue
Block a user