| /* |
| * Copyright (c) 2022 Valerio Setti <valerio.setti@gmail.com> |
| * |
| * SPDX-License-Identifier: Apache-2.0 |
| */ |
| |
| #include <zephyr/kernel.h> |
| #include <zephyr/device.h> |
| #include <zephyr/drivers/sensor.h> |
| #include <zephyr/sys/printk.h> |
| |
| void main(void) |
| { |
| struct sensor_value val; |
| int rc; |
| const struct device *const dev = DEVICE_DT_GET(DT_ALIAS(qdec0)); |
| |
| if (!device_is_ready(dev)) { |
| printk("Qdec device is not ready\n"); |
| return; |
| } |
| |
| printk("Quadrature decoder sensor test\n"); |
| |
| while (true) { |
| rc = sensor_sample_fetch(dev); |
| if (rc != 0) { |
| printk("Failed to fetch sample (%d)\n", rc); |
| return; |
| } |
| |
| rc = sensor_channel_get(dev, SENSOR_CHAN_ROTATION, &val); |
| if (rc != 0) { |
| printk("Failed to get data (%d)\n", rc); |
| return; |
| } |
| |
| printk("Position = %d degrees", val.val1); |
| |
| k_msleep(1000); |
| } |
| } |