blob: 3405d5344b9a73b824861b66d803314598a94bef [file] [log] [blame]
/*
* Copyright (c) 2017 STMicroelectronics
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr.h>
#include <device.h>
#include <sensor.h>
#include <stdio.h>
#include <misc/printk.h>
void main(void)
{
struct device *dev = device_get_binding(DT_ST_VL53L0X_0_LABEL);
struct sensor_value value;
int ret;
if (dev == NULL) {
printk("Could not get VL53L0X device\n");
return;
}
while (1) {
ret = sensor_sample_fetch(dev);
if (ret) {
printk("sensor_sample_fetch failed ret %d\n", ret);
return;
}
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(1000);
}
}