Skip to content

Commit ac579a8

Browse files
nandojvekartben
authored andcommitted
drivers: sensors: Add SENSOR_CHAN_FREQUENCY channel
Add new SENSOR_CHAN_FREQUENCY constant to allow implement sensors that output frequency values in Hertz. Signed-off-by: Gerson Fernando Budke <[email protected]>
1 parent 549def6 commit ac579a8

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

drivers/sensor/sensor_shell.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ static const char *sensor_channel_name[SENSOR_CHAN_COMMON_COUNT] = {
8888
[SENSOR_CHAN_POS_DZ] = "pos_dz",
8989
[SENSOR_CHAN_POS_DXYZ] = "pos_dxyz",
9090
[SENSOR_CHAN_RPM] = "rpm",
91+
[SENSOR_CHAN_FREQUENCY] = "frequency",
9192
[SENSOR_CHAN_GAUGE_VOLTAGE] = "gauge_voltage",
9293
[SENSOR_CHAN_GAUGE_AVG_CURRENT] = "gauge_avg_current",
9394
[SENSOR_CHAN_GAUGE_STDBY_CURRENT] = "gauge_stdby_current",

include/zephyr/drivers/sensor.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ enum sensor_channel {
156156
/** Revolutions per minute, in RPM. */
157157
SENSOR_CHAN_RPM,
158158

159+
/** Frequency, in Hz. */
160+
SENSOR_CHAN_FREQUENCY,
161+
159162
/** Voltage, in volts **/
160163
SENSOR_CHAN_GAUGE_VOLTAGE,
161164
/** Average current, in amps **/

samples/sensor/sensor_shell/pytest/test_sensor_shell.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def test_sensor_shell_attr_get(shell: Shell):
3737
lines = shell.exec_command('sensor attr_get sensor@0 co2 sampling_frequency')
3838
assert any(['sensor@0(channel=co2, attr=sampling_frequency)' in line for line in lines]), 'expected response not found'
3939

40-
lines = shell.exec_command('sensor attr_get sensor@1 53 3')
40+
lines = shell.exec_command('sensor attr_get sensor@1 54 3')
4141
assert any(['sensor@1(channel=gauge_state_of_health, attr=slope_th)' in line for line in lines]), 'expected response not found'
4242

4343
logger.info('response is valid')
@@ -50,7 +50,7 @@ def test_sensor_shell_attr_set(shell: Shell):
5050
expected_line = 'sensor@0 channel=co2, attr=sampling_frequency set to value=1'
5151
assert any([expected_line in line for line in lines]), 'expected response not found'
5252

53-
lines = shell.exec_command('sensor attr_set sensor@1 53 3 1')
53+
lines = shell.exec_command('sensor attr_set sensor@1 54 3 1')
5454
expected_line = 'sensor@1 channel=gauge_state_of_health, attr=slope_th set to value=1'
5555
assert any([expected_line in line for line in lines]), 'expected response not found'
5656

0 commit comments

Comments
 (0)