/* * Copyright (c) 2017 STMicroelectronics * * SPDX-License-Identifier: Apache-2.0 */ #include #include #include #include #include int main(void) { const struct device *const dev = DEVICE_DT_GET_ONE(st_vl53l0x); struct sensor_value value; int ret; if (!device_is_ready(dev)) { printk("sensor: device not ready.\n"); return 0; } while (1) { ret = sensor_sample_fetch(dev); if (ret) { printk("sensor_sample_fetch failed ret %d\n", ret); return 0; } ret = sensor_channel_get(dev, SENSOR_CHAN_PROX, &value); printk("prox is %d\n", value.val1); ret = sensor_channel_get(dev, SENSOR_CHAN_DISTANCE, &value); printf("distance is %.3fm\n", sensor_value_to_double(&value)); k_sleep(K_MSEC(1000)); } return 0; }