samples: sensors: add veaa_x_3 sample
Add sample for VEAA-X-3 sensor. Signed-off-by: Jeppe Odgaard <jeppe.odgaard@prevas.dk>
This commit is contained in:
parent
0b94ab7704
commit
69065fa317
7 changed files with 187 additions and 0 deletions
8
samples/sensor/veaa_x_3/CMakeLists.txt
Normal file
8
samples/sensor/veaa_x_3/CMakeLists.txt
Normal file
|
@ -0,0 +1,8 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
cmake_minimum_required(VERSION 3.20.0)
|
||||
|
||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
project(app)
|
||||
|
||||
target_sources(app PRIVATE src/main.c)
|
23
samples/sensor/veaa_x_3/Kconfig
Normal file
23
samples/sensor/veaa_x_3/Kconfig
Normal file
|
@ -0,0 +1,23 @@
|
|||
#
|
||||
# Copyright (c) 2024 Vitrolife A/S
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
mainmenu "VEAA sample application"
|
||||
|
||||
config SAMPLE_USE_SHELL
|
||||
bool "Use sensor shell and disable loop"
|
||||
default n
|
||||
select SHELL
|
||||
select SENSOR_SHELL
|
||||
|
||||
config SAMPLE_LOOP_INTERVAL
|
||||
int "Sample loop delay in milliseconds"
|
||||
default 200
|
||||
|
||||
config SAMPLE_LOOP_INCREMENT
|
||||
int "Sample kPa increment per loop"
|
||||
default 1
|
||||
|
||||
source "Kconfig.zephyr"
|
38
samples/sensor/veaa_x_3/README.rst
Normal file
38
samples/sensor/veaa_x_3/README.rst
Normal file
|
@ -0,0 +1,38 @@
|
|||
.. veaa_x_3:
|
||||
|
||||
VEAA-X-3 sample
|
||||
##########################
|
||||
|
||||
Overview
|
||||
********
|
||||
|
||||
A sensor sample that demonstrates how to use a VEAA-X-3 device.
|
||||
|
||||
Building and Running
|
||||
********************
|
||||
|
||||
This sample sets the valve setpoint then reads the actual pressure.
|
||||
This is done continuously. When the maximum supported pressure is reached the setpoint is reset to
|
||||
the valve's minimum supported pressure value.
|
||||
|
||||
.. zephyr-app-commands::
|
||||
:zephyr-app: samples/sensor/veaa_x_3
|
||||
:board: <board to use>
|
||||
:goals: build flash
|
||||
:compact:
|
||||
|
||||
Sample Output
|
||||
=============
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
Testing test_veaa_x_3
|
||||
Valve range: 1 to 200 kPa
|
||||
Setpoint: 1 kPa, actual: 1 kPa
|
||||
Setpoint: 2 kPa, actual: 2 kPa
|
||||
Setpoint: 3 kPa, actual: 3 kPa
|
||||
...
|
||||
Setpoint: 199 kPa, actual: 199 kPa
|
||||
Setpoint: 200 kPa, actual: 200 kPa
|
||||
Setpoint: 1 kPa, actual: 1 kPa
|
||||
<repeats endlessly>
|
35
samples/sensor/veaa_x_3/boards/nucleo_h563zi.overlay
Normal file
35
samples/sensor/veaa_x_3/boards/nucleo_h563zi.overlay
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Copyright (c) 2024, Vitrolife A/S
|
||||
*/
|
||||
|
||||
/* spi1 sck conflicts with dac1 channel 3 */
|
||||
/delete-node/ &spi1;
|
||||
|
||||
/ {
|
||||
test_veaa_x_3: test_veaa_x_3 {
|
||||
status = "okay";
|
||||
compatible = "festo,veaa-x-3";
|
||||
io-channels = <&adc1 3>;
|
||||
dac = <&dac1>;
|
||||
dac-channel-id = <2>;
|
||||
dac-resolution = <12>;
|
||||
pressure-range-type = "D2";
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
&adc1 {
|
||||
#address-cells = <1>;
|
||||
#size-cells = <0>;
|
||||
|
||||
channel@3 {
|
||||
reg = <3>;
|
||||
zephyr,gain = "ADC_GAIN_1";
|
||||
zephyr,reference = "ADC_REF_INTERNAL";
|
||||
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
|
||||
zephyr,resolution = <12>;
|
||||
};
|
||||
|
||||
};
|
4
samples/sensor/veaa_x_3/prj.conf
Normal file
4
samples/sensor/veaa_x_3/prj.conf
Normal file
|
@ -0,0 +1,4 @@
|
|||
CONFIG_ADC=y
|
||||
CONFIG_DAC=y
|
||||
CONFIG_SENSOR=y
|
||||
CONFIG_LOG=y
|
8
samples/sensor/veaa_x_3/sample.yaml
Normal file
8
samples/sensor/veaa_x_3/sample.yaml
Normal file
|
@ -0,0 +1,8 @@
|
|||
sample:
|
||||
name: VEAA-X-3 sensor sample
|
||||
tests:
|
||||
sample.sensor.veaa_x_3:
|
||||
harness: sensor
|
||||
tags: sensors
|
||||
filter: dt_compat_enabled("festo,veaa-x-3")
|
||||
depends_on: adc dac
|
71
samples/sensor/veaa_x_3/src/main.c
Normal file
71
samples/sensor/veaa_x_3/src/main.c
Normal file
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Copyright (c) 2024 Vitrolife A/S
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/sys/printk.h>
|
||||
#include <zephyr/drivers/sensor.h>
|
||||
#include <zephyr/drivers/sensor/veaa_x_3.h>
|
||||
|
||||
static const struct device *const dev = DEVICE_DT_GET_ONE(festo_veaa_x_3);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int rc;
|
||||
struct sensor_value range, setpoint, pressure;
|
||||
|
||||
printk("Testing %s\n", dev->name);
|
||||
|
||||
if (!device_is_ready(dev)) {
|
||||
printk("%s not ready\n", dev->name);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
rc = sensor_attr_get(dev, SENSOR_CHAN_PRESS,
|
||||
(enum sensor_attribute)SENSOR_ATTR_VEAA_X_3_RANGE, &range);
|
||||
if (rc != 0) {
|
||||
printk("get range failed: %d\n", rc);
|
||||
return rc;
|
||||
}
|
||||
printk("Valve range: %u to %u kPa\n", range.val1, range.val2);
|
||||
|
||||
if (IS_ENABLED(CONFIG_SAMPLE_USE_SHELL)) {
|
||||
printk("Loop is disabled. Use the `sensor` command to test %s", dev->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
setpoint.val1 = range.val1;
|
||||
while (1) {
|
||||
rc = sensor_attr_set(dev, SENSOR_CHAN_PRESS,
|
||||
(enum sensor_attribute)SENSOR_ATTR_VEAA_X_3_SETPOINT,
|
||||
&setpoint);
|
||||
if (rc != 0) {
|
||||
printk("Set setpoint to %u failed: %d\n", setpoint.val1, rc);
|
||||
}
|
||||
|
||||
/* Sleep before get to allow DAC and ADC to stabilize */
|
||||
k_msleep(CONFIG_SAMPLE_LOOP_INTERVAL);
|
||||
|
||||
rc = sensor_sample_fetch(dev);
|
||||
if (rc != 0) {
|
||||
printk("Fetch sample failed: %d", rc);
|
||||
}
|
||||
|
||||
rc = sensor_channel_get(dev, SENSOR_CHAN_PRESS, &pressure);
|
||||
if (rc != 0) {
|
||||
printk("Get sample failed: %d", rc);
|
||||
}
|
||||
|
||||
printk("Setpoint: %4u kPa, actual: %4u kPa\n", setpoint.val1, pressure.val1);
|
||||
|
||||
setpoint.val1 += CONFIG_SAMPLE_LOOP_INCREMENT;
|
||||
if (setpoint.val1 > range.val2) {
|
||||
setpoint.val1 = range.val1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue