shell: led: add command to enable/disable LEDs
This commit is contained in:
parent
6394c5f006
commit
914b168727
3 changed files with 40 additions and 0 deletions
3
include/shell/led.h
Normal file
3
include/shell/led.h
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
int shell_led(struct console *con, size_t argc, const char **argv);
|
|
@ -6,6 +6,7 @@ obj-y += source/shell/cmd.o
|
||||||
obj-y += source/shell/echo.o
|
obj-y += source/shell/echo.o
|
||||||
obj-y += source/shell/flash.o
|
obj-y += source/shell/flash.o
|
||||||
obj-y += source/shell/ftl.o
|
obj-y += source/shell/ftl.o
|
||||||
|
obj-y += source/shell/led.o
|
||||||
obj-y += source/shell/mufs.o
|
obj-y += source/shell/mufs.o
|
||||||
obj-y += source/shell/progress.o
|
obj-y += source/shell/progress.o
|
||||||
obj-y += source/shell/rtc.o
|
obj-y += source/shell/rtc.o
|
||||||
|
|
36
source/shell/led.c
Normal file
36
source/shell/led.c
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <libopencm3/stm32/gpio.h>
|
||||||
|
|
||||||
|
#include <console.h>
|
||||||
|
#include <led.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue