mirror of
https://github.com/m5stack/StackChan.git
synced 2026-04-27 19:12:40 +00:00
update firmware v1.2.4 (#16)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
@@ -32,7 +32,7 @@ static int enter_passkey_handler(int argc, char *argv[])
|
||||
return -1;
|
||||
}
|
||||
|
||||
sscanf(argv[1], "%s", pkey);
|
||||
sscanf(argv[1], "%7s", pkey);
|
||||
ESP_LOGI("You entered", "%s %s", argv[0], argv[1]);
|
||||
num = pkey[0];
|
||||
|
||||
@@ -45,7 +45,9 @@ static int enter_passkey_handler(int argc, char *argv[])
|
||||
xQueueSend(cli_handle, &key, 0);
|
||||
}
|
||||
} else {
|
||||
sscanf(pkey, "%d", &key);
|
||||
if (sscanf(pkey, "%d", &key) != 1) {
|
||||
key = 0;
|
||||
}
|
||||
xQueueSend(cli_handle, &key, 0);
|
||||
}
|
||||
|
||||
@@ -84,14 +86,14 @@ static void scli_task(void *arg)
|
||||
QueueHandle_t uart_queue;
|
||||
uart_event_t event;
|
||||
|
||||
uart_driver_install(uart_num, 256, 0, 8, &uart_queue, 0);
|
||||
ESP_ERROR_CHECK(uart_driver_install(uart_num, 256, 0, 8, &uart_queue, 0));
|
||||
/* Initialize the console */
|
||||
esp_console_config_t console_config = {
|
||||
.max_cmdline_args = 8,
|
||||
.max_cmdline_length = 256,
|
||||
};
|
||||
|
||||
esp_console_init(&console_config);
|
||||
ESP_ERROR_CHECK(esp_console_init(&console_config));
|
||||
|
||||
while (!stop) {
|
||||
i = 0;
|
||||
@@ -107,6 +109,9 @@ static void scli_task(void *arg)
|
||||
}
|
||||
if (event.type == UART_DATA) {
|
||||
while (uart_read_bytes(uart_num, (uint8_t *)&linebuf[i], 1, 0)) {
|
||||
if (i >= sizeof(linebuf) - 1) {
|
||||
break;
|
||||
}
|
||||
if (linebuf[i] == '\r') {
|
||||
uart_write_bytes(uart_num, "\r\n", 2);
|
||||
} else {
|
||||
@@ -115,13 +120,17 @@ static void scli_task(void *arg)
|
||||
i++;
|
||||
}
|
||||
}
|
||||
} while ((i < 255) && linebuf[i - 1] != '\r');
|
||||
|
||||
} while ((i < 255) && (i == 0 || linebuf[i - 1] != '\r'));
|
||||
if (stop) {
|
||||
break;
|
||||
}
|
||||
/* Remove the truncating \r\n */
|
||||
linebuf[strlen((char *)linebuf) - 1] = '\0';
|
||||
ret = esp_console_run((char *)linebuf, &cmd_ret);
|
||||
size_t len = strlen((char *)linebuf);
|
||||
if (len > 0) {
|
||||
linebuf[len - 1] = '\0';
|
||||
}
|
||||
ret = esp_console_run((char *)linebuf, &cmd_ret);
|
||||
if (ret < 0) {
|
||||
break;
|
||||
}
|
||||
@@ -144,3 +153,40 @@ int scli_init(void)
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
int scli_deinit(void)
|
||||
{
|
||||
if (cli_task == NULL) {
|
||||
return ESP_OK; // Already deinitialized
|
||||
}
|
||||
|
||||
// Signal task to exit
|
||||
stop = 1;
|
||||
|
||||
// Wait for task to exit (it will clean up UART and console)
|
||||
int timeout_ms = 200;
|
||||
while (timeout_ms > 0 && cli_task != NULL && eTaskGetState(cli_task) != eDeleted) {
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
timeout_ms -= 10;
|
||||
}
|
||||
|
||||
// Force delete if still running (shouldn't happen if task exits properly)
|
||||
if (cli_task != NULL && eTaskGetState(cli_task) != eDeleted) {
|
||||
vTaskDelete(cli_task);
|
||||
// If force-deleted, clean up resources manually
|
||||
uart_driver_delete(0);
|
||||
esp_console_deinit();
|
||||
}
|
||||
cli_task = NULL;
|
||||
|
||||
// Clean up queue
|
||||
if (cli_handle != NULL) {
|
||||
vQueueDelete(cli_handle);
|
||||
cli_handle = NULL;
|
||||
}
|
||||
|
||||
// Reset stop flag
|
||||
stop = 0;
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user