Add Serial Terminal App & WebUi Theme
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include "os_gfx.h"
|
||||
#include "os_oled.h"
|
||||
#include "os_status.h"
|
||||
#include "sys_uart.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
@@ -15,6 +16,45 @@
|
||||
|
||||
static const char *TAG = "SYS_CLI";
|
||||
|
||||
static int cmd_uart(int argc, char **argv)
|
||||
{
|
||||
if (argc < 2) {
|
||||
printf("Usage: uart <send <msg> | baud <rate> | stats | clear>\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (strcmp(argv[1], "send") == 0 && argc >= 3) {
|
||||
sys_uart_write_str(argv[2]);
|
||||
sys_uart_write_str("\r\n");
|
||||
printf("Sent over UART TX: %s\n", argv[2]);
|
||||
return 0;
|
||||
} else if (strcmp(argv[1], "baud") == 0 && argc >= 3) {
|
||||
uint32_t baud = (uint32_t)strtoul(argv[2], NULL, 10);
|
||||
if (baud > 0 && sys_uart_set_baud_rate(baud) == ESP_OK) {
|
||||
printf("UART baud rate changed to %lu\n", (unsigned long)baud);
|
||||
return 0;
|
||||
} else {
|
||||
printf("Failed to set baud rate\n");
|
||||
return 1;
|
||||
}
|
||||
} else if (strcmp(argv[1], "stats") == 0) {
|
||||
uint32_t rx = 0, tx = 0;
|
||||
sys_uart_get_stats(&rx, &tx);
|
||||
printf("\n=== UART Status (TX: GPIO 21, RX: GPIO 20) ===\n");
|
||||
printf("Active Baud Rate: %lu\n", (unsigned long)sys_uart_get_baud_rate());
|
||||
printf("Total RX Bytes: %lu\n", (unsigned long)rx);
|
||||
printf("Total TX Bytes: %lu\n", (unsigned long)tx);
|
||||
return 0;
|
||||
} else if (strcmp(argv[1], "clear") == 0) {
|
||||
sys_uart_clear_rx_buffer();
|
||||
printf("UART RX buffer cleared\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("Unknown uart sub-command\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int cmd_ps(int argc, char **argv)
|
||||
{
|
||||
printf("\n=== Running FreeRTOS Tasks ===\n");
|
||||
@@ -178,6 +218,14 @@ esp_err_t sys_cli_init(void)
|
||||
};
|
||||
esp_console_cmd_register(&reboot_cmd);
|
||||
|
||||
const esp_console_cmd_t uart_cmd = {
|
||||
.command = "uart",
|
||||
.help = "Hardware UART control (send, baud, stats, clear)",
|
||||
.hint = "<send|baud|stats|clear>",
|
||||
.func = &cmd_uart,
|
||||
};
|
||||
esp_console_cmd_register(&uart_cmd);
|
||||
|
||||
err = esp_console_start_repl(repl);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to start USB Serial/JTAG REPL: %s", esp_err_to_name(err));
|
||||
|
||||
Reference in New Issue
Block a user