1 /*
2 * Copyright (c) 2018 Jan Van Winkel <jan.van_winkel@dxplore.eu>
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/device.h>
8 #include <zephyr/drivers/sensor.h>
9 #include <stdio.h>
10 #include <zephyr/kernel.h>
11
12 #include <zephyr/logging/log.h>
13 LOG_MODULE_REGISTER(main);
14
main(void)15 int main(void)
16 {
17 struct sensor_value oversampling_rate = { 8192, 0 };
18 const struct device *const dev = DEVICE_DT_GET_ANY(meas_ms5837);
19
20 if (dev == NULL) {
21 LOG_ERR("Could not find MS5837 device, aborting test.");
22 return 0;
23 }
24 if (!device_is_ready(dev)) {
25 LOG_ERR("MS5837 device %s is not ready, aborting test.",
26 dev->name);
27 return 0;
28 }
29
30 if (sensor_attr_set(dev, SENSOR_CHAN_ALL, SENSOR_ATTR_OVERSAMPLING,
31 &oversampling_rate) != 0) {
32 LOG_ERR("Could not set oversampling rate of %d "
33 "on MS5837 device, aborting test.",
34 oversampling_rate.val1);
35 return 0;
36 }
37
38 while (1) {
39 struct sensor_value temp;
40 struct sensor_value press;
41
42 sensor_sample_fetch(dev);
43 sensor_channel_get(dev, SENSOR_CHAN_AMBIENT_TEMP, &temp);
44 sensor_channel_get(dev, SENSOR_CHAN_PRESS, &press);
45
46 printf("Temperature: %d.%06d, Pressure: %d.%06d\n", temp.val1,
47 temp.val2, press.val1, press.val2);
48
49 k_sleep(K_MSEC(10000));
50 }
51 return 0;
52 }
53