Skip to content

Commit 69065fa

Browse files
Jeppe Odgaardjhedberg
authored andcommitted
samples: sensors: add veaa_x_3 sample
Add sample for VEAA-X-3 sensor. Signed-off-by: Jeppe Odgaard <jeppe.odgaard@prevas.dk>
1 parent 0b94ab7 commit 69065fa

File tree

7 files changed

+187
-0
lines changed

7 files changed

+187
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
5+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
6+
project(app)
7+
8+
target_sources(app PRIVATE src/main.c)

samples/sensor/veaa_x_3/Kconfig

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#
2+
# Copyright (c) 2024 Vitrolife A/S
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
7+
mainmenu "VEAA sample application"
8+
9+
config SAMPLE_USE_SHELL
10+
bool "Use sensor shell and disable loop"
11+
default n
12+
select SHELL
13+
select SENSOR_SHELL
14+
15+
config SAMPLE_LOOP_INTERVAL
16+
int "Sample loop delay in milliseconds"
17+
default 200
18+
19+
config SAMPLE_LOOP_INCREMENT
20+
int "Sample kPa increment per loop"
21+
default 1
22+
23+
source "Kconfig.zephyr"

samples/sensor/veaa_x_3/README.rst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
.. veaa_x_3:
2+
3+
VEAA-X-3 sample
4+
##########################
5+
6+
Overview
7+
********
8+
9+
A sensor sample that demonstrates how to use a VEAA-X-3 device.
10+
11+
Building and Running
12+
********************
13+
14+
This sample sets the valve setpoint then reads the actual pressure.
15+
This is done continuously. When the maximum supported pressure is reached the setpoint is reset to
16+
the valve's minimum supported pressure value.
17+
18+
.. zephyr-app-commands::
19+
:zephyr-app: samples/sensor/veaa_x_3
20+
:board: <board to use>
21+
:goals: build flash
22+
:compact:
23+
24+
Sample Output
25+
=============
26+
27+
.. code-block:: console
28+
29+
Testing test_veaa_x_3
30+
Valve range: 1 to 200 kPa
31+
Setpoint: 1 kPa, actual: 1 kPa
32+
Setpoint: 2 kPa, actual: 2 kPa
33+
Setpoint: 3 kPa, actual: 3 kPa
34+
...
35+
Setpoint: 199 kPa, actual: 199 kPa
36+
Setpoint: 200 kPa, actual: 200 kPa
37+
Setpoint: 1 kPa, actual: 1 kPa
38+
<repeats endlessly>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* Copyright (c) 2024, Vitrolife A/S
5+
*/
6+
7+
/* spi1 sck conflicts with dac1 channel 3 */
8+
/delete-node/ &spi1;
9+
10+
/ {
11+
test_veaa_x_3: test_veaa_x_3 {
12+
status = "okay";
13+
compatible = "festo,veaa-x-3";
14+
io-channels = <&adc1 3>;
15+
dac = <&dac1>;
16+
dac-channel-id = <2>;
17+
dac-resolution = <12>;
18+
pressure-range-type = "D2";
19+
};
20+
21+
};
22+
23+
&adc1 {
24+
#address-cells = <1>;
25+
#size-cells = <0>;
26+
27+
channel@3 {
28+
reg = <3>;
29+
zephyr,gain = "ADC_GAIN_1";
30+
zephyr,reference = "ADC_REF_INTERNAL";
31+
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
32+
zephyr,resolution = <12>;
33+
};
34+
35+
};

samples/sensor/veaa_x_3/prj.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CONFIG_ADC=y
2+
CONFIG_DAC=y
3+
CONFIG_SENSOR=y
4+
CONFIG_LOG=y

samples/sensor/veaa_x_3/sample.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
sample:
2+
name: VEAA-X-3 sensor sample
3+
tests:
4+
sample.sensor.veaa_x_3:
5+
harness: sensor
6+
tags: sensors
7+
filter: dt_compat_enabled("festo,veaa-x-3")
8+
depends_on: adc dac

samples/sensor/veaa_x_3/src/main.c

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright (c) 2024 Vitrolife A/S
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/device.h>
8+
#include <zephyr/kernel.h>
9+
#include <zephyr/sys/printk.h>
10+
#include <zephyr/drivers/sensor.h>
11+
#include <zephyr/drivers/sensor/veaa_x_3.h>
12+
13+
static const struct device *const dev = DEVICE_DT_GET_ONE(festo_veaa_x_3);
14+
15+
int main(void)
16+
{
17+
int rc;
18+
struct sensor_value range, setpoint, pressure;
19+
20+
printk("Testing %s\n", dev->name);
21+
22+
if (!device_is_ready(dev)) {
23+
printk("%s not ready\n", dev->name);
24+
return -ENODEV;
25+
}
26+
27+
rc = sensor_attr_get(dev, SENSOR_CHAN_PRESS,
28+
(enum sensor_attribute)SENSOR_ATTR_VEAA_X_3_RANGE, &range);
29+
if (rc != 0) {
30+
printk("get range failed: %d\n", rc);
31+
return rc;
32+
}
33+
printk("Valve range: %u to %u kPa\n", range.val1, range.val2);
34+
35+
if (IS_ENABLED(CONFIG_SAMPLE_USE_SHELL)) {
36+
printk("Loop is disabled. Use the `sensor` command to test %s", dev->name);
37+
return 0;
38+
}
39+
40+
setpoint.val1 = range.val1;
41+
while (1) {
42+
rc = sensor_attr_set(dev, SENSOR_CHAN_PRESS,
43+
(enum sensor_attribute)SENSOR_ATTR_VEAA_X_3_SETPOINT,
44+
&setpoint);
45+
if (rc != 0) {
46+
printk("Set setpoint to %u failed: %d\n", setpoint.val1, rc);
47+
}
48+
49+
/* Sleep before get to allow DAC and ADC to stabilize */
50+
k_msleep(CONFIG_SAMPLE_LOOP_INTERVAL);
51+
52+
rc = sensor_sample_fetch(dev);
53+
if (rc != 0) {
54+
printk("Fetch sample failed: %d", rc);
55+
}
56+
57+
rc = sensor_channel_get(dev, SENSOR_CHAN_PRESS, &pressure);
58+
if (rc != 0) {
59+
printk("Get sample failed: %d", rc);
60+
}
61+
62+
printk("Setpoint: %4u kPa, actual: %4u kPa\n", setpoint.val1, pressure.val1);
63+
64+
setpoint.val1 += CONFIG_SAMPLE_LOOP_INCREMENT;
65+
if (setpoint.val1 > range.val2) {
66+
setpoint.val1 = range.val1;
67+
}
68+
}
69+
70+
return 0;
71+
}

0 commit comments

Comments
 (0)