2021-04-18 18:47:28 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021 Nordic Semiconductor ASA
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2022-05-06 09:31:04 +00:00
|
|
|
#include <kernel.h>
|
2021-04-18 18:47:28 +00:00
|
|
|
#include <drivers/sensor.h>
|
|
|
|
|
|
|
|
#include "app_version.h"
|
|
|
|
|
|
|
|
#include <logging/log.h>
|
|
|
|
LOG_MODULE_REGISTER(main, CONFIG_APP_LOG_LEVEL);
|
|
|
|
|
|
|
|
void main(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
const struct device *sensor;
|
|
|
|
|
|
|
|
printk("Zephyr Example Application %s\n", APP_VERSION_STR);
|
|
|
|
|
|
|
|
sensor = DEVICE_DT_GET(DT_NODELABEL(examplesensor0));
|
|
|
|
if (!device_is_ready(sensor)) {
|
|
|
|
LOG_ERR("Sensor not ready");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
struct sensor_value val;
|
|
|
|
|
|
|
|
ret = sensor_sample_fetch(sensor);
|
|
|
|
if (ret < 0) {
|
|
|
|
LOG_ERR("Could not fetch sample (%d)", ret);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = sensor_channel_get(sensor, SENSOR_CHAN_PROX, &val);
|
|
|
|
if (ret < 0) {
|
|
|
|
LOG_ERR("Could not get sample (%d)", ret);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
printk("Sensor value: %d\n", val.val1);
|
|
|
|
|
|
|
|
k_sleep(K_MSEC(1000));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|