From cd6c970410402ef3d885656d1df50dad0ed0503f Mon Sep 17 00:00:00 2001 From: Derek Jamison Date: Tue, 8 Oct 2024 19:56:41 -0600 Subject: [PATCH] Send /n terminator. --- gemini_app.c | 4 ++-- helpers/uart_helper.c | 15 +++++++++++---- scenes/gemini_scene_set_name.c | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/gemini_app.c b/gemini_app.c index 29b8437a462..f2116841d0d 100644 --- a/gemini_app.c +++ b/gemini_app.c @@ -31,11 +31,11 @@ bool gemini_app_send_api_key(GeminiApp* app) { memset(key, 0, COUNT_OF(key)); size_t bytes_read = storage_file_read(file, key, COUNT_OF(key)); if (bytes_read > 0) { - size_t bytes_send = bytes_read + 1; // Add one for the null character. + size_t bytes_send = bytes_read; for (size_t i = 0; i < bytes_read; i++) { if ((key[i] == '\r') || (key[i] == '\n') || (key[i] == ' ')) { key[i] = '\0'; - bytes_send = i; + bytes_send = 0; break; } } diff --git a/helpers/uart_helper.c b/helpers/uart_helper.c index 19eefba3b48..8b52f36f42a 100644 --- a/helpers/uart_helper.c +++ b/helpers/uart_helper.c @@ -233,11 +233,18 @@ bool uart_helper_read(UartHelper* helper, FuriString* text) { void uart_helper_send(UartHelper* helper, const char* data, size_t length) { if (length == 0) { - length = strlen(data) + 1; + length = strlen(data); // Exclude the null character. + char* buf = malloc(length + 2); // Null and delimiter. + memcpy(buf, data, length); + buf[length++] = '\n'; // Add a newline character. + buf[length] = 0; // Null terminate the string. + data = buf; + furi_hal_serial_tx(helper->serial_handle, (uint8_t*)data, length); + free(buf); + } else { + // Transmit data via UART TX. + furi_hal_serial_tx(helper->serial_handle, (uint8_t*)data, length); } - - // Transmit data via UART TX. - furi_hal_serial_tx(helper->serial_handle, (uint8_t*)data, length); } void uart_helper_send_string(UartHelper* helper, FuriString* string) { diff --git a/scenes/gemini_scene_set_name.c b/scenes/gemini_scene_set_name.c index 4d7b192c2d7..30aad153e73 100644 --- a/scenes/gemini_scene_set_name.c +++ b/scenes/gemini_scene_set_name.c @@ -27,7 +27,7 @@ bool gemini_scene_set_name_on_event(void* context, SceneManagerEvent event) { if (event.type == SceneManagerEventTypeCustom) { switch(event.event) { case GeminiSceneSetNameEventOk: - uart_helper_send(app->uart_helper, text_buffer, TEXT_BUFFER_SIZE); + uart_helper_send(app->uart_helper, text_buffer, 0); // We want BACK to go back to the main menu, not our current scene. gemini_scene_receive_serial_set_next(app, GeminiSceneSendKnownAps); scene_manager_search_and_switch_to_another_scene(app->scene_manager, GeminiSceneReceiveSerial);