From 914b168727481d4dd87e9517e9735ac7a4a9d52b Mon Sep 17 00:00:00 2001 From: "S.J.R. van Schaik" Date: Tue, 31 Oct 2017 17:14:54 +0100 Subject: [PATCH] shell: led: add command to enable/disable LEDs --- include/shell/led.h | 3 +++ source/shell/Makefile | 1 + source/shell/led.c | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 include/shell/led.h create mode 100644 source/shell/led.c diff --git a/include/shell/led.h b/include/shell/led.h new file mode 100644 index 0000000..1c7c9e1 --- /dev/null +++ b/include/shell/led.h @@ -0,0 +1,3 @@ +#pragma once + +int shell_led(struct console *con, size_t argc, const char **argv); diff --git a/source/shell/Makefile b/source/shell/Makefile index 05a3e8a..259a215 100644 --- a/source/shell/Makefile +++ b/source/shell/Makefile @@ -6,6 +6,7 @@ obj-y += source/shell/cmd.o obj-y += source/shell/echo.o obj-y += source/shell/flash.o obj-y += source/shell/ftl.o +obj-y += source/shell/led.o obj-y += source/shell/mufs.o obj-y += source/shell/progress.o obj-y += source/shell/rtc.o diff --git a/source/shell/led.c b/source/shell/led.c new file mode 100644 index 0000000..529ac76 --- /dev/null +++ b/source/shell/led.c @@ -0,0 +1,36 @@ +#include +#include +#include + +#include + +#include +#include + +extern struct led leds[]; +extern size_t nleds; + +int shell_led(struct console *con, size_t argc, const char **argv) +{ + size_t led_id = 0; + int state = 0; + + if (argc >= 2) + state = (strcmp(argv[1], "on") == 0); + + if (argc >= 1) + led_id = strtoul(argv[0], NULL, 0); + + if (led_id > nleds) { + fprintf(con->fp, "error: unknown LED ID %d\n", led_id); + return -1; + } + + if (state) { + led_enable(leds + led_id); + } else { + led_disable(leds + led_id); + } + + return 0; +}