add led command

This commit is contained in:
2024-07-16 21:06:31 +02:00
parent 2887173681
commit d185891740
3 changed files with 37 additions and 4 deletions

View File

@@ -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()

View File

@@ -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"