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 the CONFIG_SENSOR_SIM_BASE_TEMPERATURE Kconfig option and a pseudo-random number between -1 and 1.

  • Humidity (SENSOR_CHAN_HUMIDITY) - The value is generated as the sum of the value of the CONFIG_SENSOR_SIM_BASE_HUMIDITY Kconfig option and a pseudo-random number between -1 and 1.

  • Pressure (SENSOR_CHAN_PRESS) - The value is generated as the sum of the value of the CONFIG_SENSOR_SIM_BASE_PRESSURE Kconfig option and a pseudo-random number between -1 and 1.

  • Acceleration in X, Y, and Z axes (SENSOR_CHAN_ACCEL_X, SENSOR_CHAN_ACCEL_Y, SENSOR_CHAN_ACCEL_Z, for each axis respectively, and SENSOR_CHAN_ACCEL_XYZ for all axes at once) - The acceleration is generated depending on the selected Kconfig option:

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:

For both triggers, the handler function is called by a dedicated thread. The thread has the following configuration options:

API documentation

Header file: include/drivers/sensor_sim.h
Source file: 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.