Skip to content

Commit

Permalink
sensor_shell: Print channels supported by a sensor
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
kornelduleba committed Oct 10, 2023
1 parent 39fa42a commit a0fca76
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions drivers/sensor/sensor_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a0fca76

Please sign in to comment.