Explorar o código

Show text input when needed.

antirez %!s(int64=3) %!d(string=hai) anos
pai
achega
2f1327eef1
Modificáronse 3 ficheiros con 71 adicións e 2 borrados
  1. 45 1
      app.c
  2. 10 1
      app.h
  3. 16 0
      view_info.c

+ 45 - 1
app.c

@@ -123,6 +123,9 @@ ProtoViewApp* protoview_app_alloc() {
     view_port_input_callback_set(app->view_port, input_callback, app);
     gui_add_view_port(app->gui, app->view_port, GuiLayerFullscreen);
     app->event_queue = furi_message_queue_alloc(8, sizeof(InputEvent));
+    app->view_dispatcher = NULL;
+    app->text_input = NULL;
+    app->show_text_input = false;
     app->current_view = ViewRawPulses;
     for (int j = 0; j < ViewLast; j++) app->current_subview[j] = 0;
     app->direct_sampling_enabled = false;
@@ -301,7 +304,48 @@ int32_t protoview_app_entry(void* p) {
                 if (!(c % 20)) FURI_LOG_E(TAG, "Loop timeout");
             }
         }
-        view_port_update(app->view_port);
+        if (app->show_text_input) {
+            /* Remove our viewport: we need to use a view dispatcher
+             * in order to show the standard Flipper keyboard. */
+            gui_remove_view_port(app->gui, app->view_port);
+
+            /* Allocate a view dispatcher, add a text input view to it,
+             * and activate it. */
+            app->view_dispatcher = view_dispatcher_alloc();
+            view_dispatcher_enable_queue(app->view_dispatcher);
+            app->text_input = text_input_alloc();
+            view_dispatcher_set_event_callback_context(app->view_dispatcher,app);
+            view_dispatcher_add_view(app->view_dispatcher, 0, text_input_get_view(app->text_input));
+            view_dispatcher_switch_to_view(app->view_dispatcher, 0);
+
+            /* Setup the text input view. The different parameters are set
+             * in the app structure by the view that wanted to show the
+             * input text. The callback, buffer and buffer len must be set.  */
+            text_input_set_header_text(app->text_input, "Save signal filename");
+            text_input_set_result_callback(
+                app->text_input,
+                app->text_input_done_callback,
+                app,
+                app->text_input_buffer,
+                app->text_input_buffer_len,
+                false);
+
+            /* Run the dispatcher with the keyboard. */
+            view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
+            view_dispatcher_run(app->view_dispatcher);
+
+            /* Undo all it: remove the view from the dispatcher, free it
+             * so that it removes itself from the current gui, finally
+             * restore our viewport. */
+            view_dispatcher_remove_view(app->view_dispatcher, 0);
+            text_input_free(app->text_input);
+            view_dispatcher_free(app->view_dispatcher);
+            app->view_dispatcher = NULL;
+            gui_add_view_port(app->gui, app->view_port, GuiLayerFullscreen);
+            app->show_text_input = false;
+        } else {
+            view_port_update(app->view_port);
+        }
     }
 
     /* App no longer running. Shut down and free. */

+ 10 - 1
app.h

@@ -14,6 +14,7 @@
 #include <gui/modules/submenu.h>
 #include <gui/modules/variable_item_list.h>
 #include <gui/modules/widget.h>
+#include <gui/modules/text_input.h>
 #include <notification/notification_messages.h>
 #include <lib/subghz/subghz_setting.h>
 #include <lib/subghz/subghz_worker.h>
@@ -25,7 +26,7 @@
 #define TAG "ProtoView"
 #define PROTOVIEW_RAW_VIEW_DEFAULT_SCALE 100 // 100us is 1 pixel by default
 #define BITMAP_SEEK_NOT_FOUND UINT32_MAX // Returned by function as sentinel
-#define PROTOVIEW_VIEW_PRIVDATA_LEN 32 // View specific private data len
+#define PROTOVIEW_VIEW_PRIVDATA_LEN 64 // View specific private data len
 
 #define DEBUG_MSG 1
 
@@ -120,6 +121,14 @@ struct ProtoViewApp {
     ProtoViewCurrentView current_view;      /* Active left-right view ID. */
     int current_subview[ViewLast];  /* Active up-down subview ID. */
     FuriMessageQueue *event_queue;  /* Keypress events go here. */
+    ViewDispatcher *view_dispatcher; /* Used only when we want to show
+                                        the text_input view for a moment.
+                                        Otherwise it is set to null. */
+    TextInput *text_input;
+    bool show_text_input;
+    char *text_input_buffer;
+    uint32_t text_input_buffer_len;
+    void (*text_input_done_callback)(void*);
 
     /* Radio related. */
     ProtoViewTxRx *txrx;     /* Radio state. */

+ 16 - 0
view_info.c

@@ -2,6 +2,7 @@
  * See the LICENSE file for information about the license. */
 
 #include "app.h"
+#include <gui/view_i.h>
 
 enum {
     SubViewInfoMain,
@@ -10,11 +11,13 @@ enum {
 };
 
 /* Our view private data. */
+#define SAVE_FILENAME_LEN 64
 typedef struct {
     /* Our save view displays an oscilloscope-alike resampled signal,
      * so that the user can see what they are saving. With left/right
      * you can move to next rows. Here we store where we are. */
     uint32_t signal_display_start_row;
+    char *filename;
 } InfoViewPrivData;
 
 /* Render the view with the detected message information. */
@@ -90,6 +93,13 @@ void render_view_info(Canvas *const canvas, ProtoViewApp *app) {
     }
 }
 
+void text_input_done_callback(void* context) {
+    ProtoViewApp *app = context;
+    InfoViewPrivData *privdata = app->view_privdata;
+    free(privdata->filename);
+    view_dispatcher_stop(app->view_dispatcher);
+}
+
 /* Handle input for the info view. */
 void process_input_info(ProtoViewApp *app, InputEvent input) {
     if (process_subview_updown(app,input,SubViewInfoLast)) return;
@@ -109,6 +119,12 @@ void process_input_info(ProtoViewApp *app, InputEvent input) {
         } else if (input.type == InputTypePress && input.key == InputKeyLeft) {
             if (privdata->signal_display_start_row != 0)
                 privdata->signal_display_start_row--;
+        } else if (input.type == InputTypePress && input.key == InputKeyOk) {
+            privdata->filename = malloc(SAVE_FILENAME_LEN);
+            app->show_text_input = true;
+            app->text_input_buffer = privdata->filename;
+            app->text_input_buffer_len = SAVE_FILENAME_LEN;
+            app->text_input_done_callback = text_input_done_callback;
         }
     }
 }