1 /* 2 * Copyright (c) 2020 Sven Herrmann 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 <stdio.h> 11 main(void)12int main(void) 13 { 14 const struct device *const dev = DEVICE_DT_GET_ONE(honeywell_mpr); 15 int rc; 16 17 if (!device_is_ready(dev)) { 18 printf("Device %s is not ready\n", dev->name); 19 return 0; 20 } 21 22 while (1) { 23 struct sensor_value pressure; 24 25 rc = sensor_sample_fetch(dev); 26 if (rc != 0) { 27 printf("sensor_sample_fetch error: %d\n", rc); 28 break; 29 } 30 31 rc = sensor_channel_get(dev, SENSOR_CHAN_PRESS, &pressure); 32 if (rc != 0) { 33 printf("sensor_channel_get error: %d\n", rc); 34 break; 35 } 36 37 printf("pressure: %u.%u kPa\n", pressure.val1, pressure.val2); 38 39 k_sleep(K_SECONDS(1)); 40 } 41 return 0; 42 } 43