Add a console with a reboot command
Couldn't just call the component "console" as that conflicted with the ESP-IDF component, so opted for "console-wrapper".
This commit is contained in:
parent
e4fa25a61e
commit
0634787df3
5
components/console_wrapper/CMakeLists.txt
Normal file
5
components/console_wrapper/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
idf_component_register(
|
||||||
|
SRCS "console.c"
|
||||||
|
INCLUDE_DIRS "."
|
||||||
|
REQUIRES console esp_system
|
||||||
|
)
|
63
components/console_wrapper/console.c
Normal file
63
components/console_wrapper/console.c
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
* Copyright (c) Camden Dixie O'Brien
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "console.h"
|
||||||
|
|
||||||
|
#include "esp_console.h"
|
||||||
|
#include "esp_log.h"
|
||||||
|
#include "esp_system.h"
|
||||||
|
|
||||||
|
#define TAG "Console"
|
||||||
|
|
||||||
|
static esp_console_repl_t *repl;
|
||||||
|
|
||||||
|
static int reboot_command_func(int argc, char **argv)
|
||||||
|
{
|
||||||
|
(void)argc;
|
||||||
|
(void)argv;
|
||||||
|
(void)esp_restart();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void console_init(void)
|
||||||
|
{
|
||||||
|
esp_err_t error;
|
||||||
|
|
||||||
|
error = esp_console_register_help_command();
|
||||||
|
if (error != ESP_OK)
|
||||||
|
ESP_LOGE(TAG, "Error registering help command: %04x", error);
|
||||||
|
|
||||||
|
esp_console_repl_config_t repl_config
|
||||||
|
= ESP_CONSOLE_REPL_CONFIG_DEFAULT();
|
||||||
|
repl_config.prompt = ">";
|
||||||
|
esp_console_dev_uart_config_t uart_config
|
||||||
|
= ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT();
|
||||||
|
error = esp_console_new_repl_uart(&uart_config, &repl_config, &repl);
|
||||||
|
if (error != ESP_OK) {
|
||||||
|
ESP_LOGE(TAG, "Error initializing console REPL: %04x", error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
error = esp_console_start_repl(repl);
|
||||||
|
if (error != ESP_OK)
|
||||||
|
ESP_LOGE(TAG, "Error starting console REPL: %04x", error);
|
||||||
|
|
||||||
|
console_register(
|
||||||
|
"reboot", "Reboot the system", "reboot", reboot_command_func);
|
||||||
|
}
|
||||||
|
|
||||||
|
void console_register(
|
||||||
|
const char *name, const char *help, const char *hint, CommandFunc func)
|
||||||
|
{
|
||||||
|
const esp_console_cmd_t command = {
|
||||||
|
.command = name,
|
||||||
|
.help = help,
|
||||||
|
.hint = hint,
|
||||||
|
.func = func,
|
||||||
|
};
|
||||||
|
const esp_err_t error = esp_console_cmd_register(&command);
|
||||||
|
if (error != ESP_OK)
|
||||||
|
ESP_LOGE(TAG, "Error registering command %s: %04x", name, error);
|
||||||
|
}
|
25
components/console_wrapper/console.h
Normal file
25
components/console_wrapper/console.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
* Copyright (c) Camden Dixie O'Brien
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef CONSOLE_H
|
||||||
|
#define CONSOLE_H
|
||||||
|
|
||||||
|
typedef int (*CommandFunc)(int argc, char **argv);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize and start the console.
|
||||||
|
*/
|
||||||
|
void console_init(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a console command.
|
||||||
|
*
|
||||||
|
* The name, help and hint should all be null-terminated strings. Hint
|
||||||
|
* should list possible arguments.
|
||||||
|
*/
|
||||||
|
void console_register(
|
||||||
|
const char *name, const char *help, const char *hint, CommandFunc func);
|
||||||
|
|
||||||
|
#endif
|
@ -1,5 +1,5 @@
|
|||||||
idf_component_register(
|
idf_component_register(
|
||||||
SRCS "main.c"
|
SRCS "main.c"
|
||||||
INCLUDE_DIRS "."
|
INCLUDE_DIRS "."
|
||||||
REQUIRES display settings
|
REQUIRES console_wrapper display settings
|
||||||
)
|
)
|
||||||
|
@ -3,11 +3,13 @@
|
|||||||
* Copyright (c) Camden Dixie O'Brien
|
* Copyright (c) Camden Dixie O'Brien
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "console.h"
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
|
||||||
void app_main(void)
|
void app_main(void)
|
||||||
{
|
{
|
||||||
|
console_init();
|
||||||
settings_init();
|
settings_init();
|
||||||
display_init();
|
display_init();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user