drivers: led: shell: print color as string

Human readable.

Signed-off-by: Nick Ward <nix.ward@gmail.com>
This commit is contained in:
Nick Ward 2024-06-09 14:00:23 +10:00 committed by Anas Nashif
parent 4b8aa82801
commit 2576458dce

View file

@ -6,6 +6,7 @@
#include <zephyr/shell/shell.h> #include <zephyr/shell/shell.h>
#include <zephyr/drivers/led.h> #include <zephyr/drivers/led.h>
#include <zephyr/dt-bindings/led/led.h>
#include <stdlib.h> #include <stdlib.h>
#define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL #define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL
@ -84,6 +85,28 @@ static int cmd_on(const struct shell *sh, size_t argc, char **argv)
return err; return err;
} }
static const char *led_color_to_str(uint8_t color)
{
switch (color) {
case LED_COLOR_ID_WHITE:
return "white";
case LED_COLOR_ID_RED:
return "red";
case LED_COLOR_ID_GREEN:
return "green";
case LED_COLOR_ID_BLUE:
return "blue";
case LED_COLOR_ID_VIOLET:
return "violet";
case LED_COLOR_ID_YELLOW:
return "yellow";
case LED_COLOR_ID_IR:
return "IR";
default:
return "unknown";
}
}
static int cmd_get_info(const struct shell *sh, size_t argc, char **argv) static int cmd_get_info(const struct shell *sh, size_t argc, char **argv)
{ {
const struct device *dev; const struct device *dev;
@ -109,11 +132,11 @@ static int cmd_get_info(const struct shell *sh, size_t argc, char **argv)
shell_print(sh, "Index : %d", info->index); shell_print(sh, "Index : %d", info->index);
shell_print(sh, "Num colors : %d", info->num_colors); shell_print(sh, "Num colors : %d", info->num_colors);
if (info->color_mapping) { if (info->color_mapping) {
shell_fprintf(sh, SHELL_NORMAL, "Colors : %d", shell_fprintf(sh, SHELL_NORMAL, "Colors : %s",
info->color_mapping[0]); led_color_to_str(info->color_mapping[0]));
for (i = 1; i < info->num_colors; i++) { for (i = 1; i < info->num_colors; i++) {
shell_fprintf(sh, SHELL_NORMAL, ":%d", shell_fprintf(sh, SHELL_NORMAL, ":%s",
info->color_mapping[i]); led_color_to_str(info->color_mapping[i]));
} }
shell_fprintf(sh, SHELL_NORMAL, "\n"); shell_fprintf(sh, SHELL_NORMAL, "\n");
} }