From d185891740266027a94660382964df81821e3ec4 Mon Sep 17 00:00:00 2001 From: FReenen Date: Tue, 16 Jul 2024 21:06:31 +0200 Subject: [PATCH] add led command --- rx_esp32/lib/cli | 2 +- rx_esp32/src/commands.c | 35 ++++++++++++++++++++++++++++++++++- rx_esp32/src/main.c | 4 ++-- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/rx_esp32/lib/cli b/rx_esp32/lib/cli index 8261e60..f08c8e5 160000 --- a/rx_esp32/lib/cli +++ b/rx_esp32/lib/cli @@ -1 +1 @@ -Subproject commit 8261e605bccf98e6f028d0ca221ffb81ebc4c0c2 +Subproject commit f08c8e5788cb24b7321697560987ecca9322e050 diff --git a/rx_esp32/src/commands.c b/rx_esp32/src/commands.c index 1bbd5a8..7b09665 100644 --- a/rx_esp32/src/commands.c +++ b/rx_esp32/src/commands.c @@ -9,6 +9,7 @@ #include "commands.h" #include "utils.h" +#include "led.h" typedef enum { BOAT_AVAILABLE, @@ -74,10 +75,42 @@ int cmd_status(char* line, CLI_t* cli) return ret; } +char* readInt(char* str, int* out) +{ + *out = 0; + while ((*str >= '0') && (*str <= '9')) + { + *out *= 10; + *out += *str - '0'; + str++; + } + return str; +} + +int setLed(char* line, CLI_t* cli) +{ + int r, g, b; + + char* arg = getNextArg(line, ':'); + readInt(arg, &r); + arg = getNextArg(arg, ','); + readInt(arg, &g); + arg = getNextArg(arg, ','); + readInt(arg, &b); + + led_setRGB(r, g, b); + + char msg[20]; + snprintf(&msg[0], 20, "led: r%d g%d n%d\n", r, g, b); + CLI_stringOut(cli, &msg[0]); + return 0; +} + const CMD_t Commands[] = { { "d", &cmd_contrl }, { "shutdown", &cmd_shutdown }, - { "status", &cmd_status } + { "status", &cmd_status }, + { "led", &setLed } }; CMDList_t* getCMDList() diff --git a/rx_esp32/src/main.c b/rx_esp32/src/main.c index 0952aa3..7381560 100644 --- a/rx_esp32/src/main.c +++ b/rx_esp32/src/main.c @@ -7,8 +7,8 @@ #include "esp_event.h" #include "esp_task_wdt.h" -#include "../lib/cli/CLI/CLI.h" -#include "../lib/cli/CMDList/CMDList.h" +#include "CLI/CLI.h" +#include "CMDList/CMDList.h" #include "config.h" #include "utils.h"