evil_portal_scene_start.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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 { NO_ARGS = 0, INPUT_ARGS, TOGGLE_ARGS } InputArgs;
  6. typedef enum {
  7. FOCUS_CONSOLE_END = 0,
  8. FOCUS_CONSOLE_START,
  9. FOCUS_CONSOLE_TOGGLE
  10. } FocusConsole;
  11. #define SHOW_STOPSCAN_TIP (true)
  12. #define NO_TIP (false)
  13. #define MAX_OPTIONS (9)
  14. typedef struct {
  15. const char *item_string;
  16. const char *options_menu[MAX_OPTIONS];
  17. int num_options_menu;
  18. const char *actual_commands[MAX_OPTIONS];
  19. InputArgs needs_keyboard;
  20. FocusConsole focus_console;
  21. bool show_stopscan_tip;
  22. } Evil_PortalItem;
  23. // NUM_MENU_ITEMS defined in evil_portal_app_i.h - if you add an entry here,
  24. // increment it!
  25. const Evil_PortalItem items[NUM_MENU_ITEMS] = {
  26. // send command
  27. {"Start portal",
  28. {""},
  29. 1,
  30. {SET_HTML_CMD},
  31. NO_ARGS,
  32. FOCUS_CONSOLE_END,
  33. SHOW_STOPSCAN_TIP},
  34. // stop portal
  35. {"Stop portal", {""}, 1, {RESET_CMD}, NO_ARGS, FOCUS_CONSOLE_START, SHOW_STOPSCAN_TIP},
  36. // console
  37. {"Save logs",
  38. {""},
  39. 1,
  40. {"savelogs"},
  41. NO_ARGS,
  42. FOCUS_CONSOLE_START,
  43. SHOW_STOPSCAN_TIP},
  44. // set AP name
  45. {"Set AP name",
  46. {""},
  47. 1,
  48. {"setapname"},
  49. NO_ARGS,
  50. FOCUS_CONSOLE_START,
  51. SHOW_STOPSCAN_TIP},
  52. // select HTML Portal File
  53. {"Select HTML",
  54. {""},
  55. 1,
  56. {"selecthtml"},
  57. NO_ARGS,
  58. FOCUS_CONSOLE_START,
  59. SHOW_STOPSCAN_TIP},
  60. // help
  61. {"Help",
  62. {""},
  63. 1,
  64. {"help"},
  65. NO_ARGS,
  66. FOCUS_CONSOLE_START,
  67. SHOW_STOPSCAN_TIP},
  68. };
  69. static void evil_portal_scene_start_var_list_enter_callback(void *context,
  70. uint32_t index) {
  71. furi_assert(context);
  72. Evil_PortalApp *app = context;
  73. furi_assert(index < NUM_MENU_ITEMS);
  74. const Evil_PortalItem *item = &items[index];
  75. const int selected_option_index = app->selected_option_index[index];
  76. furi_assert(selected_option_index < item->num_options_menu);
  77. app->selected_tx_string = item->actual_commands[selected_option_index];
  78. app->is_command = true;
  79. app->is_custom_tx_string = false;
  80. app->selected_menu_index = index;
  81. app->focus_console_start = (item->focus_console == FOCUS_CONSOLE_TOGGLE)
  82. ? (selected_option_index == 0)
  83. : item->focus_console;
  84. app->show_stopscan_tip = item->show_stopscan_tip;
  85. view_dispatcher_send_custom_event(app->view_dispatcher,
  86. Evil_PortalEventStartConsole);
  87. }
  88. static void
  89. evil_portal_scene_start_var_list_change_callback(VariableItem *item) {
  90. furi_assert(item);
  91. Evil_PortalApp *app = variable_item_get_context(item);
  92. furi_assert(app);
  93. const Evil_PortalItem *menu_item = &items[app->selected_menu_index];
  94. uint8_t item_index = variable_item_get_current_value_index(item);
  95. furi_assert(item_index < menu_item->num_options_menu);
  96. variable_item_set_current_value_text(item,
  97. menu_item->options_menu[item_index]);
  98. app->selected_option_index[app->selected_menu_index] = item_index;
  99. }
  100. void evil_portal_scene_start_on_enter(void *context) {
  101. Evil_PortalApp *app = context;
  102. VariableItemList *var_item_list = app->var_item_list;
  103. variable_item_list_set_enter_callback(
  104. var_item_list, evil_portal_scene_start_var_list_enter_callback, app);
  105. VariableItem *item;
  106. for (int i = 0; i < NUM_MENU_ITEMS; ++i) {
  107. item = variable_item_list_add(
  108. var_item_list, items[i].item_string, items[i].num_options_menu,
  109. evil_portal_scene_start_var_list_change_callback, app);
  110. variable_item_set_current_value_index(item, app->selected_option_index[i]);
  111. variable_item_set_current_value_text(
  112. item, items[i].options_menu[app->selected_option_index[i]]);
  113. }
  114. variable_item_list_set_selected_item(
  115. var_item_list,
  116. scene_manager_get_scene_state(app->scene_manager, Evil_PortalSceneStart));
  117. view_dispatcher_switch_to_view(app->view_dispatcher,
  118. Evil_PortalAppViewVarItemList);
  119. }
  120. bool evil_portal_scene_start_on_event(void *context, SceneManagerEvent event) {
  121. UNUSED(context);
  122. Evil_PortalApp *app = context;
  123. bool consumed = false;
  124. if (event.type == SceneManagerEventTypeCustom) {
  125. if (event.event == Evil_PortalEventStartPortal) {
  126. scene_manager_set_scene_state(app->scene_manager, Evil_PortalSceneStart,
  127. app->selected_menu_index);
  128. scene_manager_next_scene(app->scene_manager,
  129. Evil_PortalAppViewStartPortal);
  130. } else if (event.event == Evil_PortalEventStartKeyboard) {
  131. scene_manager_set_scene_state(app->scene_manager, Evil_PortalSceneStart,
  132. app->selected_menu_index);
  133. } else if (event.event == Evil_PortalEventStartConsole) {
  134. scene_manager_set_scene_state(app->scene_manager, Evil_PortalSceneStart,
  135. app->selected_menu_index);
  136. scene_manager_next_scene(app->scene_manager,
  137. Evil_PortalAppViewConsoleOutput);
  138. }
  139. consumed = true;
  140. } else if (event.type == SceneManagerEventTypeTick) {
  141. app->selected_menu_index =
  142. variable_item_list_get_selected_item_index(app->var_item_list);
  143. consumed = true;
  144. }
  145. return consumed;
  146. }
  147. void evil_portal_scene_start_on_exit(void *context) {
  148. Evil_PortalApp *app = context;
  149. variable_item_list_reset(app->var_item_list);
  150. }