1 /* 2 * Copyright (c) 2017 STMicroelectronics 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 #include <zephyr/sys/printk.h> 12 main(void)13int main(void) 14 { 15 const struct device *const dev = DEVICE_DT_GET_ONE(st_vl53l0x); 16 struct sensor_value value; 17 int ret; 18 19 if (!device_is_ready(dev)) { 20 printk("sensor: device not ready.\n"); 21 return 0; 22 } 23 24 while (1) { 25 ret = sensor_sample_fetch(dev); 26 if (ret) { 27 printk("sensor_sample_fetch failed ret %d\n", ret); 28 return 0; 29 } 30 31 ret = sensor_channel_get(dev, SENSOR_CHAN_PROX, &value); 32 printk("prox is %d\n", value.val1); 33 34 ret = sensor_channel_get(dev, 35 SENSOR_CHAN_DISTANCE, 36 &value); 37 printf("distance is %.3fm\n", sensor_value_to_double(&value)); 38 39 k_sleep(K_MSEC(1000)); 40 } 41 return 0; 42 } 43