Simulated sensor driver
The simulated sensor driver implements a simulated sensor that is compatible with Zephyr’s Sensors. The sensor provides readouts for predefined set of sensor channels and supports sensor triggers.
Configuration
You can enable the driver using the CONFIG_SENSOR_SIM
Kconfig option.
To configure the device name used by the simulated sensor device, use the CONFIG_SENSOR_SIM_DEV_NAME
Kconfig option.
The default device name is SENSOR_SIM
.
Configuration of generated readouts
The algorithms used to generate simulated sensor readouts are configurable. The following sensor channels and configuration options are available:
Ambient temperature (
SENSOR_CHAN_AMBIENT_TEMP
) - The value is generated as the sum of the value of theCONFIG_SENSOR_SIM_BASE_TEMPERATURE
Kconfig option and a pseudo-random number between-1
and1
.Humidity (
SENSOR_CHAN_HUMIDITY
) - The value is generated as the sum of the value of theCONFIG_SENSOR_SIM_BASE_HUMIDITY
Kconfig option and a pseudo-random number between-1
and1
.Pressure (
SENSOR_CHAN_PRESS
) - The value is generated as the sum of the value of theCONFIG_SENSOR_SIM_BASE_PRESSURE
Kconfig option and a pseudo-random number between-1
and1
.Acceleration in X, Y, and Z axes (
SENSOR_CHAN_ACCEL_X
,SENSOR_CHAN_ACCEL_Y
,SENSOR_CHAN_ACCEL_Z
, for each axis respectively, andSENSOR_CHAN_ACCEL_XYZ
for all axes at once) - The acceleration is generated depending on the selected Kconfig option:CONFIG_SENSOR_SIM_ACCEL_TOGGLE
- With this option, the acceleration is toggled on fetch between statically defined values.CONFIG_SENSOR_SIM_ACCEL_WAVE
- With this option, the acceleration is generated as value of a periodic wave signal. The wave signal value is generated using the Wave generator library. You can use thesensor_sim_set_wave_param()
function to configure generated waves. By default, the function generates a sine wave.
Configuration of sensor triggers
Use CONFIG_SENSOR_SIM_TRIGGER
to enable the sensor trigger.
The simulated sensor supports the SENSOR_TRIG_DATA_READY
trigger.
You can configure the event that generates the trigger using one of the following Kconfig options:
CONFIG_SENSOR_SIM_TRIGGER_USE_TIMEOUT
- The trigger is generated periodically on timeout of the period defined in theCONFIG_SENSOR_SIM_TRIGGER_TIMEOUT_MSEC
Kconfig option. By default, the trigger is generated every 1 second.CONFIG_SENSOR_SIM_TRIGGER_USE_BUTTON
- The trigger is generated when the Button 1 is pressed on the compatible development kit. The simulated sensor driver uses GPIO to access the GPIO pin.
For both triggers, the handler function is called by a dedicated thread. The thread has the following configuration options:
CONFIG_SENSOR_SIM_THREAD_PRIORITY
- This Kconfig option defines the priority.CONFIG_SENSOR_SIM_THREAD_STACK_SIZE
- This Kconfig option defines the stack size.
API documentation
include/drivers/sensor_sim.h
drivers/sensor/sensor_sim/sensor_sim.c
- group sensor_sim
Simulated sensor device driver.
Functions
-
int sensor_sim_set_wave_param(enum sensor_channel chan, const struct wave_gen_param *set_params)
Set simulated acceleration parameters.
Note
This function can be used only if acceleration is generated as wave signal. Moreover, although it is thread-safe, it cannot be used in interrupts.
- Parameters
chan – [in] Selected sensor channel.
set_params – [in] Parameters of wave signal.
- Return values
0 – If the operation was successful. Otherwise, a (negative) error code is returned.
-
int sensor_sim_set_wave_param(enum sensor_channel chan, const struct wave_gen_param *set_params)