Skip to content

Commit

Permalink
Send /n terminator.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamisonderek committed Oct 9, 2024
1 parent 2c8a229 commit cd6c970
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
4 changes: 2 additions & 2 deletions gemini_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
15 changes: 11 additions & 4 deletions helpers/uart_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion scenes/gemini_scene_set_name.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit cd6c970

Please sign in to comment.