1 /*
2  * Copyright (c) 2018 Alexander Wachter
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 
main(void)12 int main(void)
13 {
14 	const struct device *const dev = DEVICE_DT_GET_ONE(ams_ens210);
15 	struct sensor_value temperature, humidity;
16 
17 	if (!device_is_ready(dev)) {
18 		printk("Device %s is not ready\n", dev->name);
19 		return 0;
20 	}
21 
22 	printk("device is %p, name is %s\n", dev, dev->name);
23 
24 	while (1) {
25 		sensor_sample_fetch(dev);
26 		sensor_channel_get(dev, SENSOR_CHAN_HUMIDITY, &humidity);
27 		sensor_channel_get(dev, SENSOR_CHAN_AMBIENT_TEMP, &temperature);
28 		printk("Temperature: %d.%06d C; Humidity: %d.%06d%%\n",
29 			temperature.val1, temperature.val2,
30 			humidity.val1, humidity.val2);
31 
32 		k_sleep(K_MSEC(1000));
33 	}
34 	return 0;
35 }
36