From a0fca76508f150c735fc8e008fb43a3c7669e813 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Dul=C4=99ba?= Date: Thu, 28 Sep 2023 14:34:29 +0000 Subject: [PATCH] sensor_shell: Print channels supported by a sensor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use the recently introduced "channels" field of the sensor_info struct and print all supported channels if they're specified. Signed-off-by: Kornel Dulęba --- drivers/sensor/sensor_shell.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/sensor/sensor_shell.c b/drivers/sensor/sensor_shell.c index a85eab23e43ec36..4b63c1e24d6c007 100644 --- a/drivers/sensor/sensor_shell.c +++ b/drivers/sensor/sensor_shell.c @@ -664,6 +664,20 @@ static int cmd_get_sensor_info(const struct shell *sh, size_t argc, char **argv) sensor->dev->name, sensor->vendor ? sensor->vendor : null_str, sensor->model ? sensor->model : null_str, sensor->friendly_name ? sensor->friendly_name : null_str); + if (sensor->num_channels > 0) { + /* Can't use shell_print here as it appends '\n'. */ + shell_fprintf(sh, SHELL_NORMAL, "supported channels:"); + for (int i = 0; i < sensor->num_channels; i++) { + if (sensor->channels[i] < ARRAY_SIZE(sensor_channel_name)) { + shell_fprintf(sh, SHELL_NORMAL, " %s", + sensor_channel_name[sensor->channels[i]]); + } else { + shell_fprintf(sh, SHELL_NORMAL, " unknown(%d)", + sensor->channels[i]); + } + } + shell_fprintf(sh, SHELL_NORMAL, "\n"); + } } return 0; #else