/
main.c
41 lines (32 loc) · 940 Bytes
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
* Copyright (c) 2023 Ian Morris
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/drivers/sensor.h>
#include <zephyr/sys/printk.h>
#include <zephyr/sys/__assert.h>
#define HS300X_NODE DT_COMPAT_GET_ANY_STATUS_OKAY(renesas_hs300x)
int main(void)
{
const struct device *const dev = DEVICE_DT_GET(HS300X_NODE);
struct sensor_value temp, hum;
int ret;
__ASSERT(device_is_ready(dev), "HS300x device not ready");
printk("Device %s - %p is ready\n", dev->name, dev);
while (1) {
ret = sensor_sample_fetch(dev);
if (ret) {
printk("Failed to fetch measurements (%d)\n", ret);
return 0;
}
sensor_channel_get(dev, SENSOR_CHAN_AMBIENT_TEMP, &temp);
sensor_channel_get(dev, SENSOR_CHAN_HUMIDITY, &hum);
printk("temp is %d.%d oC\n", temp.val1, temp.val2);
printk("hum is %d.%d %%RH\n", hum.val1, hum.val2);
k_sleep(K_MSEC(1000));
}
return 0;
}