|
| 1 | +/* |
| 2 | + * Copyright (c) 2018 Bosch Sensortec GmbH |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause |
| 5 | + */ |
| 6 | + |
| 7 | +#include <zephyr/kernel.h> |
| 8 | +#include <zephyr/device.h> |
| 9 | +#include <zephyr/drivers/sensor.h> |
| 10 | +#include <stdio.h> |
| 11 | + |
| 12 | +int main(void) |
| 13 | +{ |
| 14 | + const struct device *const dev = DEVICE_DT_GET_ONE(bosch_bme680); |
| 15 | + struct sensor_value temp, press, humidity, gas_res; |
| 16 | + |
| 17 | + if (!device_is_ready(dev)) { |
| 18 | + printk("sensor: device not ready.\n"); |
| 19 | + return 0; |
| 20 | + } |
| 21 | + |
| 22 | + printf("Device %p name is %s\n", dev, dev->name); |
| 23 | + |
| 24 | +#ifndef CONFIG_COVERAGE |
| 25 | + while (1) { |
| 26 | +#else |
| 27 | + for (int i = 0; i < 5; i++) { |
| 28 | +#endif |
| 29 | + k_sleep(K_MSEC(3000)); |
| 30 | + |
| 31 | + sensor_sample_fetch(dev); |
| 32 | + sensor_channel_get(dev, SENSOR_CHAN_AMBIENT_TEMP, &temp); |
| 33 | + sensor_channel_get(dev, SENSOR_CHAN_PRESS, &press); |
| 34 | + sensor_channel_get(dev, SENSOR_CHAN_HUMIDITY, &humidity); |
| 35 | + sensor_channel_get(dev, SENSOR_CHAN_GAS_RES, &gas_res); |
| 36 | + |
| 37 | + printf("T: %d.%06d; P: %d.%06d; H: %d.%06d; G: %d.%06d\n", |
| 38 | + temp.val1, temp.val2, press.val1, press.val2, |
| 39 | + humidity.val1, humidity.val2, gas_res.val1, |
| 40 | + gas_res.val2); |
| 41 | + } |
| 42 | + return 0; |
| 43 | +} |
0 commit comments