zephyr/samples/sensor/sensor_shell
Alberto Escolar Piedras cb53e40ff9 drivers uart_native_posix: rename to native_pty and support N instances
Rename the driver from uart_native_posix to uart_native_pty.
Including renaming the DTS compatible, and kconfig options, deprecating
the old ones.

And refactor the driver, generalizing it, so we can have any number of
instances.
Note that, unfortunately generalizing to N instances cannot be done
without a degree of backwards compatibility breakage: This driver was
born with all its configuration and selection of the instances based on
kconfig.
When the driver was made to use DT, it was done in a way that required
both DT and kconfig needing to manually coherently enable the 2nd UART.
This has now been fixed, which it means only DT is used to decide how
many instances are avaliable, and UART_NATIVE_POSIX_PORT_1_ENABLE is
just ignored.

Including:
* Deprecate UART_NATIVE_WAIT_PTS_READY_ENABLE: the options is always on
  now as it has no practical drawbacks.
* Deprecate UART_NATIVE_POSIX_PORT_1_ENABLE: DTS intanciation defines it
  being available now.
* Rename a few functions and in general shorten pseudo-tty/pseudo-
  terminal to PTY instead of PTTY.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-03-11 18:54:02 +01:00
..
boards samples: sensor: sensor_shell: add vmu_rt1170. 2025-01-29 15:17:44 +01:00
dts/bindings samples: sensor: rename fake sensor binding 2025-02-24 10:49:52 +01:00
include
pytest drivers: sensors: Add SENSOR_CHAN_FREQUENCY channel 2025-01-14 17:58:41 +01:00
src drivers: sensor: Place API into iterable section 2024-12-02 22:04:55 +00:00
CMakeLists.txt samples: sensor: sensor_shell: add fake sensor driver 2024-05-20 22:56:11 +03:00
fake_sensor.overlay samples: sensor: Use dedicated overlay for fake sensor in sensor_shell 2025-02-24 10:49:52 +01:00
Kconfig samples: sensor: Use dedicated overlay for fake sensor in sensor_shell 2025-02-24 10:49:52 +01:00
prj.conf
README.rst samples: sensor: Use dedicated overlay for fake sensor in sensor_shell 2025-02-24 10:49:52 +01:00
sample.yaml drivers uart_native_posix: rename to native_pty and support N instances 2025-03-11 18:54:02 +01:00

.. zephyr:code-sample:: sensor_shell
   :name: Sensor shell
   :relevant-api: sensor_interface

   Interact with sensors using the shell module.

Overview
********
This is a simple shell module to get data from sensors presented in the system.

Building and Running
********************

Build the sample app by choosing the target board that has sensors drivers
enabled, for example:

.. zephyr-app-commands::
   :zephyr-app: samples/sensor/sensor_shell
   :board: reel_board
   :goals: build flash

For boards that do not have a sensor, a simple fake sensor driver is provided and can enabled by
adding the following overlay:

.. zephyr-app-commands::
   :zephyr-app: samples/sensor/sensor_shell
   :board: qemu_riscv64
   :goals: run
   :gen-args: -DEXTRA_DTC_OVERLAY_FILE=fake_sensor.overlay

Shell Module Command Help
=========================

.. code-block:: console

   sensor - Sensor commands
   Subcommands:
     get   :Get sensor data. Channel names are optional. All channels are read when
            no channels are provided. Syntax:
            <device_name> <channel name 0> .. <channel name N>
     info  :Get sensor info, such as vendor and model name, for all sensors.


**get**: prints all the sensor channels data for a given sensor device name.
Optionally, a single channel name or index can be passed to be printed out. The
device name and channel name are autocompleted.

Output example (reel_board):

.. code-block:: console

   uart:~$ sensor get mma8652fc@1d
   channel idx=0 accel_x =   0.000000
   channel idx=1 accel_y =   0.268150
   channel idx=2 accel_z =   9.959878
   channel idx=3 accel_xyz x =   0.000000 y =   0.268150 z =   9.959878

   uart:~$ sensor get mma8652fc@1d accel_z
   channel idx=2 accel_z =   9.959878

   uart:~$ sensor get mma8652fc@1d 2
   channel idx=2 accel_z =   9.959878

.. note::
   A valid sensor device name should be passed otherwise you will get an
   undefined behavior like hardware exception. This happens because the shell
   subsystem runs in supervisor mode where API callbacks are not checked before
   being called.

**info**: prints vendor, model, and friendly name information for all sensors.
This command depends on enabling :kconfig:option:`CONFIG_SENSOR_INFO`.

.. code-block:: console

   uart:~$ sensor info
   device name: apds9960@39, vendor: Avago Technologies, model: apds9960, friendly name: (null)
   device name: mma8652fc@1d, vendor: NXP Semiconductors, model: fxos8700, friendly name: (null)
   device name: ti_hdc@43, vendor: Texas Instruments, model: hdc, friendly name: (null)
   device name: temp@4000c000, vendor: Nordic Semiconductor, model: nrf-temp, friendly name: (null)