David Lee 2 лет назад
Родитель
Сommit
4affc9f620

+ 9 - 1
evil_portal_app.c

@@ -32,10 +32,12 @@ Evil_PortalApp *evil_portal_app_alloc() {
   app->has_command_queue = false;  
   app->has_command_queue = false;  
   app->command_index = 0;
   app->command_index = 0;
   app->portal_logs = furi_string_alloc();
   app->portal_logs = furi_string_alloc();
+  
 
 
   app->gui = furi_record_open(RECORD_GUI);
   app->gui = furi_record_open(RECORD_GUI);
 
 
   app->view_dispatcher = view_dispatcher_alloc();
   app->view_dispatcher = view_dispatcher_alloc();
+  
   app->scene_manager = scene_manager_alloc(&evil_portal_scene_handlers, app);
   app->scene_manager = scene_manager_alloc(&evil_portal_scene_handlers, app);
   view_dispatcher_enable_queue(app->view_dispatcher);
   view_dispatcher_enable_queue(app->view_dispatcher);
   view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
   view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
@@ -54,6 +56,10 @@ Evil_PortalApp *evil_portal_app_alloc() {
   view_dispatcher_add_view(app->view_dispatcher, Evil_PortalAppViewVarItemList,
   view_dispatcher_add_view(app->view_dispatcher, Evil_PortalAppViewVarItemList,
                            variable_item_list_get_view(app->var_item_list));
                            variable_item_list_get_view(app->var_item_list));
 
 
+  app->text_input = text_input_alloc();
+  view_dispatcher_add_view(app->view_dispatcher, Evil_PortalAppViewTextInput, text_input_get_view(app->text_input));
+                    
+
   for (int i = 0; i < NUM_MENU_ITEMS; ++i) {
   for (int i = 0; i < NUM_MENU_ITEMS; ++i) {
     app->selected_option_index[i] = 0;
     app->selected_option_index[i] = 0;
   }
   }
@@ -65,6 +71,7 @@ Evil_PortalApp *evil_portal_app_alloc() {
   app->text_box_store = furi_string_alloc();
   app->text_box_store = furi_string_alloc();
   furi_string_reserve(app->text_box_store, EVIL_PORTAL_TEXT_BOX_STORE_SIZE);
   furi_string_reserve(app->text_box_store, EVIL_PORTAL_TEXT_BOX_STORE_SIZE);
 
 
+//scene_manager_next_scene(app->scene_manager, Evil_PortalSceneRename);
   scene_manager_next_scene(app->scene_manager, Evil_PortalSceneStart);
   scene_manager_next_scene(app->scene_manager, Evil_PortalSceneStart);
 
 
   return app;
   return app;
@@ -92,7 +99,8 @@ void evil_portal_app_free(Evil_PortalApp *app) {
 
 
   text_box_free(app->text_box);
   text_box_free(app->text_box);
   furi_string_free(app->text_box_store);
   furi_string_free(app->text_box_store);
-
+  text_input_free(app->text_input);
+  
   // View dispatcher
   // View dispatcher
   view_dispatcher_free(app->view_dispatcher);
   view_dispatcher_free(app->view_dispatcher);
   scene_manager_free(app->scene_manager);
   scene_manager_free(app->scene_manager);

+ 1 - 1
evil_portal_app.h

@@ -8,4 +8,4 @@ typedef struct Evil_PortalApp Evil_PortalApp;
 
 
 #ifdef __cplusplus
 #ifdef __cplusplus
 }
 }
-#endif
+#endif

+ 10 - 1
evil_portal_app_i.h

@@ -7,11 +7,17 @@
 
 
 #include <gui/gui.h>
 #include <gui/gui.h>
 #include <gui/modules/text_box.h>
 #include <gui/modules/text_box.h>
+
+#include <gui/modules/dialog_ex.h>
+#include <gui/modules/text_input.h>
+#include <gui/modules/button_menu.h>
+#include <gui/modules/button_panel.h>
+
 #include <gui/modules/variable_item_list.h>
 #include <gui/modules/variable_item_list.h>
 #include <gui/scene_manager.h>
 #include <gui/scene_manager.h>
 #include <gui/view_dispatcher.h>
 #include <gui/view_dispatcher.h>
 
 
-#define NUM_MENU_ITEMS (4)
+#define NUM_MENU_ITEMS (5)
 
 
 #define EVIL_PORTAL_TEXT_BOX_STORE_SIZE (4096)
 #define EVIL_PORTAL_TEXT_BOX_STORE_SIZE (4096)
 #define UART_CH (FuriHalUartIdUSART1)
 #define UART_CH (FuriHalUartIdUSART1)
@@ -36,6 +42,7 @@ struct Evil_PortalApp {
 
 
   VariableItemList *var_item_list;
   VariableItemList *var_item_list;
   Evil_PortalUart *uart;
   Evil_PortalUart *uart;
+  TextInput* text_input;
 
 
   int selected_menu_index;
   int selected_menu_index;
   int selected_option_index[NUM_MENU_ITEMS];
   int selected_option_index[NUM_MENU_ITEMS];
@@ -48,6 +55,7 @@ struct Evil_PortalApp {
   bool sent_html;
   bool sent_html;
   bool sent_reset;
   bool sent_reset;
   int BAUDRATE;
   int BAUDRATE;
+  char text_store[2][128 + 1];
 
 
   uint8_t *index_html;
   uint8_t *index_html;
   uint8_t *ap_name;
   uint8_t *ap_name;
@@ -57,4 +65,5 @@ typedef enum {
   Evil_PortalAppViewVarItemList,
   Evil_PortalAppViewVarItemList,
   Evil_PortalAppViewConsoleOutput,
   Evil_PortalAppViewConsoleOutput,
   Evil_PortalAppViewStartPortal,
   Evil_PortalAppViewStartPortal,
+  Evil_PortalAppViewTextInput,
 } Evil_PortalAppView;
 } Evil_PortalAppView;

+ 1 - 0
evil_portal_custom_event.h

@@ -5,4 +5,5 @@ typedef enum {
   Evil_PortalEventStartConsole,
   Evil_PortalEventStartConsole,
   Evil_PortalEventStartKeyboard,
   Evil_PortalEventStartKeyboard,
   Evil_PortalEventStartPortal,
   Evil_PortalEventStartPortal,
+  Evil_PortalEventTextInput,
 } Evil_PortalCustomEvent;
 } Evil_PortalCustomEvent;

+ 5 - 0
helpers/evil_portal_storage.c

@@ -77,6 +77,11 @@ void evil_portal_read_ap_name(void *context) {
   evil_portal_close_storage();
   evil_portal_close_storage();
 }
 }
 
 
+void evil_portal_write_ap_name(void *context) {
+  Evil_PortalApp *app = context;
+  UNUSED(app);
+}
+
 char *sequential_file_resolve_path(Storage *storage, const char *dir,
 char *sequential_file_resolve_path(Storage *storage, const char *dir,
                                    const char *prefix, const char *extension) {
                                    const char *prefix, const char *extension) {
   if (storage == NULL || dir == NULL || prefix == NULL || extension == NULL) {
   if (storage == NULL || dir == NULL || prefix == NULL || extension == NULL) {

+ 1 - 0
helpers/evil_portal_storage.h

@@ -12,6 +12,7 @@
 
 
 void evil_portal_read_index_html(void *context);
 void evil_portal_read_index_html(void *context);
 void evil_portal_read_ap_name(void *context);
 void evil_portal_read_ap_name(void *context);
+void evil_portal_write_ap_name(void *context);
 void write_logs(FuriString* portal_logs);
 void write_logs(FuriString* portal_logs);
 char *sequential_file_resolve_path(Storage *storage, const char *dir,
 char *sequential_file_resolve_path(Storage *storage, const char *dir,
                                    const char *prefix, const char *extension);
                                    const char *prefix, const char *extension);

+ 1 - 0
scenes/evil_portal_scene_config.h

@@ -1,2 +1,3 @@
 ADD_SCENE(evil_portal, start, Start)
 ADD_SCENE(evil_portal, start, Start)
 ADD_SCENE(evil_portal, console_output, ConsoleOutput)
 ADD_SCENE(evil_portal, console_output, ConsoleOutput)
+ADD_SCENE(evil_portal, rename, Rename)

+ 6 - 0
scenes/evil_portal_scene_console_output.c

@@ -65,6 +65,12 @@ void evil_portal_scene_console_output_on_enter(void *context) {
       }
       }
     }
     }
 
 
+    if (0 == strncmp("setapname", app->selected_tx_string, strlen("setapname"))) {
+      scene_manager_next_scene(app->scene_manager,
+                               Evil_PortalSceneRename);
+      return;
+    }
+
     if (0 ==
     if (0 ==
         strncmp(SET_HTML_CMD, app->selected_tx_string, strlen(SET_HTML_CMD))) {
         strncmp(SET_HTML_CMD, app->selected_tx_string, strlen(SET_HTML_CMD))) {
       app->command_queue[0] = SET_AP_CMD;
       app->command_queue[0] = SET_AP_CMD;

+ 44 - 0
scenes/evil_portal_scene_rename.c

@@ -0,0 +1,44 @@
+#include "../evil_portal_app_i.h"
+#include "../helpers/evil_portal_storage.h"
+
+void evil_portal_text_input_callback(void* context) {
+    furi_assert(context);
+    Evil_PortalApp* app = context;
+    view_dispatcher_send_custom_event(app->view_dispatcher, Evil_PortalEventTextInput);
+}
+
+void evil_portal_scene_rename_on_enter(void *context) {
+  Evil_PortalApp *app = context;
+  TextInput* text_input = app->text_input;
+  size_t enter_name_length = 25;
+  evil_portal_read_ap_name(app);
+  text_input_set_header_text(text_input, "AP Name/SSID");
+  strncpy(app->text_store[0], (char *)app->ap_name, enter_name_length);
+  text_input_set_result_callback(
+    text_input,
+    evil_portal_text_input_callback,
+    context,
+    app->text_store[0],
+    //(char *)app->ap_name,
+    enter_name_length,
+    false);
+    view_dispatcher_switch_to_view(app->view_dispatcher, Evil_PortalAppViewTextInput);
+}
+
+bool evil_portal_scene_rename_on_event(void *context, SceneManagerEvent event) {
+  Evil_PortalApp *app = context;
+  SceneManager* scene_manager = app->scene_manager;
+  bool consumed = false;
+  if(event.type == SceneManagerEventTypeCustom) {
+    evil_portal_write_ap_name(app);
+    scene_manager_search_and_switch_to_previous_scene(
+                    scene_manager, Evil_PortalSceneStart);
+    consumed = true;
+  }
+  return consumed;
+}
+
+void evil_portal_scene_rename_on_exit(void *context) {
+  Evil_PortalApp *app = context;
+  variable_item_list_reset(app->var_item_list);
+}

+ 9 - 0
scenes/evil_portal_scene_start.c

@@ -49,6 +49,15 @@ const Evil_PortalItem items[NUM_MENU_ITEMS] = {
      FOCUS_CONSOLE_START,
      FOCUS_CONSOLE_START,
      SHOW_STOPSCAN_TIP},
      SHOW_STOPSCAN_TIP},
 
 
+    // set AP name
+    {"Set AP name",
+     {""},
+     1,
+     {"setapname"},
+     NO_ARGS,
+     FOCUS_CONSOLE_START,
+     SHOW_STOPSCAN_TIP},
+
     // help
     // help
     {"Help",
     {"Help",
      {""},
      {""},