0xchocolate 3 лет назад
Родитель
Сommit
727772716b

+ 11 - 6
applications/wifi_marauder_companion/scenes/wifi_marauder_scene_console_output.c

@@ -4,13 +4,16 @@ void wifi_marauder_console_output_handle_rx_data_cb(uint8_t *buf, size_t len, vo
     furi_assert(context);
     WifiMarauderApp* app = context;
 
-    // Copy buf to string
-    char str_buf[RX_BUF_SIZE+1];
-    memcpy(str_buf, buf, len);
-    str_buf[len] = '\0';
+    // If text box store gets too big, then truncate it
+    app->text_box_store_strlen += len;
+    if (app->text_box_store_strlen >= WIFI_MARAUDER_TEXT_BOX_STORE_SIZE - 1) {
+        string_right(app->text_box_store, app->text_box_store_strlen / 2);
+        app->text_box_store_strlen = string_size(app->text_box_store);
+    }
 
-    // Append string to text box store
-    string_cat_printf(app->text_box_store, "%s", str_buf);
+    // Null-terminate buf and append to text box store
+    buf[len] = '\0';
+    string_cat_printf(app->text_box_store, "%s", buf);
 
     view_dispatcher_send_custom_event(app->view_dispatcher, WifiMarauderEventRefreshConsoleOutput);
 }
@@ -26,6 +29,7 @@ void wifi_marauder_scene_console_output_on_enter(void* context) {
         text_box_set_focus(text_box, TextBoxFocusEnd);
     }
     string_reset(app->text_box_store);
+    app->text_box_store_strlen = 0;
 
     scene_manager_set_scene_state(app->scene_manager, WifiMarauderSceneConsoleOutput, 0);
     view_dispatcher_switch_to_view(app->view_dispatcher, WifiMarauderAppViewConsoleOutput);
@@ -66,4 +70,5 @@ void wifi_marauder_scene_console_output_on_exit(void* context) {
 
     text_box_reset(app->text_box);
     string_reset(app->text_box_store);
+    app->text_box_store_strlen = 0;
 }

+ 1 - 0
applications/wifi_marauder_companion/wifi_marauder_app_i.h

@@ -22,6 +22,7 @@ struct WifiMarauderApp {
 
     char text_input_store[WIFI_MARAUDER_TEXT_INPUT_STORE_SIZE + 1];
     string_t text_box_store;
+    size_t text_box_store_strlen;
     TextBox* text_box;
     TextInput* text_input;
     //Widget* widget;

+ 1 - 1
applications/wifi_marauder_companion/wifi_marauder_uart.c

@@ -10,7 +10,7 @@ struct WifiMarauderUart {
     WifiMarauderApp* app;
     FuriThread* rx_thread;
     StreamBufferHandle_t rx_stream;
-    uint8_t rx_buf[RX_BUF_SIZE];
+    uint8_t rx_buf[RX_BUF_SIZE+1];
     void (*handle_rx_data_cb)(uint8_t *buf, size_t len, void* context);
 };