evil_portal_scene_start.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #include "../evil_portal_app_i.h"
  2. // For each command, define whether additional arguments are needed
  3. // (enabling text input to fill them out), and whether the console
  4. // text box should focus at the start of the output or the end
  5. typedef enum {
  6. NO_ARGS = 0,
  7. INPUT_ARGS,
  8. TOGGLE_ARGS
  9. } InputArgs;
  10. typedef enum {
  11. FOCUS_CONSOLE_END = 0,
  12. FOCUS_CONSOLE_START,
  13. FOCUS_CONSOLE_TOGGLE
  14. } FocusConsole;
  15. #define SHOW_STOPSCAN_TIP (true)
  16. #define NO_TIP (false)
  17. #define MAX_OPTIONS (9)
  18. typedef struct {
  19. const char* item_string;
  20. const char* options_menu[MAX_OPTIONS];
  21. int num_options_menu;
  22. const char* actual_commands[MAX_OPTIONS];
  23. InputArgs needs_keyboard;
  24. FocusConsole focus_console;
  25. bool show_stopscan_tip;
  26. } Evil_PortalItem;
  27. // NUM_MENU_ITEMS defined in evil_portal_app_i.h - if you add an entry here,
  28. // increment it!
  29. const Evil_PortalItem items[NUM_MENU_ITEMS] = {
  30. // send command
  31. {"Start portal", {""}, 1, {SET_HTML_CMD}, NO_ARGS, FOCUS_CONSOLE_END, SHOW_STOPSCAN_TIP},
  32. // stop portal
  33. {"Stop portal", {""}, 1, {RESET_CMD}, NO_ARGS, FOCUS_CONSOLE_START, SHOW_STOPSCAN_TIP},
  34. // console
  35. {"Save logs", {""}, 1, {"savelogs"}, NO_ARGS, FOCUS_CONSOLE_START, SHOW_STOPSCAN_TIP},
  36. // set AP name
  37. {"Set AP name", {""}, 1, {"setapname"}, NO_ARGS, FOCUS_CONSOLE_START, SHOW_STOPSCAN_TIP},
  38. // select HTML Portal File
  39. {"Select HTML", {""}, 1, {"selecthtml"}, NO_ARGS, FOCUS_CONSOLE_START, SHOW_STOPSCAN_TIP},
  40. // help
  41. {"Help", {""}, 1, {"help"}, NO_ARGS, FOCUS_CONSOLE_START, SHOW_STOPSCAN_TIP},
  42. };
  43. static void evil_portal_scene_start_var_list_enter_callback(void* context, uint32_t index) {
  44. furi_assert(context);
  45. Evil_PortalApp* app = context;
  46. furi_assert(index < NUM_MENU_ITEMS);
  47. const Evil_PortalItem* item = &items[index];
  48. const int selected_option_index = app->selected_option_index[index];
  49. furi_assert(selected_option_index < item->num_options_menu);
  50. app->selected_tx_string = item->actual_commands[selected_option_index];
  51. app->is_command = true;
  52. app->is_custom_tx_string = false;
  53. app->selected_menu_index = index;
  54. app->focus_console_start = (item->focus_console == FOCUS_CONSOLE_TOGGLE) ?
  55. (selected_option_index == 0) :
  56. item->focus_console;
  57. app->show_stopscan_tip = item->show_stopscan_tip;
  58. view_dispatcher_send_custom_event(app->view_dispatcher, Evil_PortalEventStartConsole);
  59. }
  60. static void evil_portal_scene_start_var_list_change_callback(VariableItem* item) {
  61. furi_assert(item);
  62. Evil_PortalApp* app = variable_item_get_context(item);
  63. furi_assert(app);
  64. const Evil_PortalItem* menu_item = &items[app->selected_menu_index];
  65. uint8_t item_index = variable_item_get_current_value_index(item);
  66. furi_assert(item_index < menu_item->num_options_menu);
  67. variable_item_set_current_value_text(item, menu_item->options_menu[item_index]);
  68. app->selected_option_index[app->selected_menu_index] = item_index;
  69. }
  70. void evil_portal_scene_start_on_enter(void* context) {
  71. Evil_PortalApp* app = context;
  72. VariableItemList* var_item_list = app->var_item_list;
  73. variable_item_list_set_enter_callback(
  74. var_item_list, evil_portal_scene_start_var_list_enter_callback, app);
  75. VariableItem* item;
  76. for(int i = 0; i < NUM_MENU_ITEMS; ++i) {
  77. item = variable_item_list_add(
  78. var_item_list,
  79. items[i].item_string,
  80. items[i].num_options_menu,
  81. evil_portal_scene_start_var_list_change_callback,
  82. app);
  83. variable_item_set_current_value_index(item, app->selected_option_index[i]);
  84. variable_item_set_current_value_text(
  85. item, items[i].options_menu[app->selected_option_index[i]]);
  86. }
  87. variable_item_list_set_selected_item(
  88. var_item_list, scene_manager_get_scene_state(app->scene_manager, Evil_PortalSceneStart));
  89. view_dispatcher_switch_to_view(app->view_dispatcher, Evil_PortalAppViewVarItemList);
  90. }
  91. bool evil_portal_scene_start_on_event(void* context, SceneManagerEvent event) {
  92. UNUSED(context);
  93. Evil_PortalApp* app = context;
  94. bool consumed = false;
  95. if(event.type == SceneManagerEventTypeCustom) {
  96. if(event.event == Evil_PortalEventStartPortal) {
  97. scene_manager_set_scene_state(
  98. app->scene_manager, Evil_PortalSceneStart, app->selected_menu_index);
  99. scene_manager_next_scene(app->scene_manager, Evil_PortalAppViewStartPortal);
  100. } else if(event.event == Evil_PortalEventStartKeyboard) {
  101. scene_manager_set_scene_state(
  102. app->scene_manager, Evil_PortalSceneStart, app->selected_menu_index);
  103. } else if(event.event == Evil_PortalEventStartConsole) {
  104. scene_manager_set_scene_state(
  105. app->scene_manager, Evil_PortalSceneStart, app->selected_menu_index);
  106. scene_manager_next_scene(app->scene_manager, Evil_PortalAppViewConsoleOutput);
  107. }
  108. consumed = true;
  109. } else if(event.type == SceneManagerEventTypeTick) {
  110. app->selected_menu_index = variable_item_list_get_selected_item_index(app->var_item_list);
  111. consumed = true;
  112. }
  113. return consumed;
  114. }
  115. void evil_portal_scene_start_on_exit(void* context) {
  116. Evil_PortalApp* app = context;
  117. variable_item_list_reset(app->var_item_list);
  118. }