1 /*
2 * Copyright (c) 2019 Centaur Analytics
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/kernel.h>
8 #include <zephyr/device.h>
9 #include <zephyr/drivers/sensor.h>
10 #include <zephyr/sys/printk.h>
11 #include <zephyr/sys/__assert.h>
12 #include <zephyr/logging/log.h>
13 #include <zephyr/drivers/gpio.h>
14
main(void)15 int main(void)
16 {
17 printk("Running on %s!\n", CONFIG_ARCH);
18 const struct device *const dev = DEVICE_DT_GET_ONE(ti_hdc);
19
20 if (!device_is_ready(dev)) {
21 printk("sensor: device not ready.\n");
22 return 0;
23 }
24
25 printk("Dev %p name %s is ready!\n", dev, dev->name);
26
27 struct sensor_value temp, humidity;
28
29 while (1) {
30 /* take a sample */
31 printk("Fetching...\n");
32 sensor_sample_fetch(dev);
33 sensor_channel_get(dev, SENSOR_CHAN_AMBIENT_TEMP, &temp);
34 sensor_channel_get(dev, SENSOR_CHAN_HUMIDITY, &humidity);
35
36 /* print the result */
37 printk("Temp = %d.%06d C, RH = %d.%06d %%\n",
38 temp.val1, temp.val2, humidity.val1, humidity.val2);
39
40 /* wait for the next sample */
41 k_sleep(K_SECONDS(10));
42 }
43 return 0;
44 }
45