From e924879ef777675cd362c513000bd4d950972ecd Mon Sep 17 00:00:00 2001 From: Diego Sueiro Date: Thu, 22 Nov 2018 06:13:38 +0000 Subject: [PATCH] samples/subsys/shell: Introduce Sensor Shell module Adds the Sensor Shell module sample app. Signed-off-by: Diego Sueiro Signed-off-by: Anas Nashif --- samples/sensor/sensor_shell/CMakeLists.txt | 16 ++++ samples/sensor/sensor_shell/README.rst | 94 +++++++++++++++++++ .../sensor_shell/boards/reel_board.conf | 3 + samples/sensor/sensor_shell/prj.conf | 4 + samples/sensor/sensor_shell/sample.yaml | 9 ++ samples/sensor/sensor_shell/src/main.c | 9 ++ 6 files changed, 135 insertions(+) create mode 100644 samples/sensor/sensor_shell/CMakeLists.txt create mode 100644 samples/sensor/sensor_shell/README.rst create mode 100644 samples/sensor/sensor_shell/boards/reel_board.conf create mode 100644 samples/sensor/sensor_shell/prj.conf create mode 100644 samples/sensor/sensor_shell/sample.yaml create mode 100644 samples/sensor/sensor_shell/src/main.c diff --git a/samples/sensor/sensor_shell/CMakeLists.txt b/samples/sensor/sensor_shell/CMakeLists.txt new file mode 100644 index 00000000000..d69a6623c82 --- /dev/null +++ b/samples/sensor/sensor_shell/CMakeLists.txt @@ -0,0 +1,16 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.8.2) +macro(set_conf_file) + if(EXISTS ${APPLICATION_SOURCE_DIR}/boards/${BOARD}.conf) + set(CONF_FILE "prj.conf ${APPLICATION_SOURCE_DIR}/boards/${BOARD}.conf") + else() + set(CONF_FILE "prj.conf") + endif() +endmacro() + +include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE) +project(sensor_shell) + +FILE(GLOB app_sources src/*.c) +target_sources(app PRIVATE ${app_sources}) diff --git a/samples/sensor/sensor_shell/README.rst b/samples/sensor/sensor_shell/README.rst new file mode 100644 index 00000000000..07e4c136b68 --- /dev/null +++ b/samples/sensor/sensor_shell/README.rst @@ -0,0 +1,94 @@ +.. _sensor_shell_sample: + +Sensor Shell Module Sample +########################## + +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: + +.. code-block:: console + + cmake -DBOARD=reel_board + + +.. zephyr-app-commands:: + :zephyr-app: samples/subsys/shell/sensor_module + :goals: run + + +Shell Module Command Help +========================= + +.. code-block:: console + + sensor - Sensor commands + Options: + -h, --help :Show command help. + Subcommands: + get : [chanel_idx] + list :List configured sensors + list_channels : + +**list**: lists all the initialized devices on the system. + +Output example (reel_board): + +.. code-block:: console + + uart:~$ sensor list + devices: + - clk_k32src + - clk_m16src + - UART_0 + - ENTROPY_0 + - GPIO_0 + - GPIO_1 + - I2C_0 + - APDS9960 + - MMA8652FC + - HDC1008 + +**list_channels**: lists the supported channels (index and name) for a given +sensor device name. + +Output example (reel_board): + +.. code-block:: console + + uart:~$ sensor list_channels MMA8652FC + idx=0 name=accel_x + idx=1 name=accel_y + idx=2 name=accel_z + idx=3 name=accel_xyz + +.. 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. + +**get**: prints all the sensor channels data for a given sensor device name. +Optionally, a single channel index can be passed to be printed out. + +Output example (reel_board): + +.. code-block:: console + + uart:~$ sensor get MMA8652FC + channel idx=0 accel_x = -1.379061 + channel idx=1 accel_y = 1.991975 + channel idx=2 accel_z = -9.576807 + channel idx=3 accel_xyz = -1.379061 + channel idx=3 accel_xyz = 1.991975 + channel idx=3 accel_xyz = -9.576807 + +.. 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. diff --git a/samples/sensor/sensor_shell/boards/reel_board.conf b/samples/sensor/sensor_shell/boards/reel_board.conf new file mode 100644 index 00000000000..cfbedf0f092 --- /dev/null +++ b/samples/sensor/sensor_shell/boards/reel_board.conf @@ -0,0 +1,3 @@ +CONFIG_APDS9960=y +CONFIG_FXOS8700=y +CONFIG_TI_HDC=y diff --git a/samples/sensor/sensor_shell/prj.conf b/samples/sensor/sensor_shell/prj.conf new file mode 100644 index 00000000000..4fee87ae9c4 --- /dev/null +++ b/samples/sensor/sensor_shell/prj.conf @@ -0,0 +1,4 @@ +CONFIG_SHELL=y +CONFIG_BOOT_BANNER=n +CONFIG_SENSOR=y +CONFIG_SENSOR_SHELL=y diff --git a/samples/sensor/sensor_shell/sample.yaml b/samples/sensor/sensor_shell/sample.yaml new file mode 100644 index 00000000000..e100ac533af --- /dev/null +++ b/samples/sensor/sensor_shell/sample.yaml @@ -0,0 +1,9 @@ +sample: + name: Shell Sensor Module Sample +tests: + test: + filter: ( CONFIG_UART_CONSOLE and CONFIG_SERIAL_SUPPORT_INTERRUPT ) + tags: shell + harness: keyboard + min_ram: 20 + min_flash: 33 diff --git a/samples/sensor/sensor_shell/src/main.c b/samples/sensor/sensor_shell/src/main.c new file mode 100644 index 00000000000..69d82ed9b4f --- /dev/null +++ b/samples/sensor/sensor_shell/src/main.c @@ -0,0 +1,9 @@ +/* + * Copyright (c) 2018 Diego Sueiro + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +LOG_MODULE_REGISTER(app);