evil_portal_scene_start.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. // help
  53. {"Help",
  54. {""},
  55. 1,
  56. {"help"},
  57. NO_ARGS,
  58. FOCUS_CONSOLE_START,
  59. SHOW_STOPSCAN_TIP},
  60. };
  61. static void evil_portal_scene_start_var_list_enter_callback(void *context,
  62. uint32_t index) {
  63. furi_assert(context);
  64. Evil_PortalApp *app = context;
  65. furi_assert(index < NUM_MENU_ITEMS);
  66. const Evil_PortalItem *item = &items[index];
  67. const int selected_option_index = app->selected_option_index[index];
  68. furi_assert(selected_option_index < item->num_options_menu);
  69. app->selected_tx_string = item->actual_commands[selected_option_index];
  70. app->is_command = true;
  71. app->is_custom_tx_string = false;
  72. app->selected_menu_index = index;
  73. app->focus_console_start = (item->focus_console == FOCUS_CONSOLE_TOGGLE)
  74. ? (selected_option_index == 0)
  75. : item->focus_console;
  76. app->show_stopscan_tip = item->show_stopscan_tip;
  77. view_dispatcher_send_custom_event(app->view_dispatcher,
  78. Evil_PortalEventStartConsole);
  79. }
  80. static void
  81. evil_portal_scene_start_var_list_change_callback(VariableItem *item) {
  82. furi_assert(item);
  83. Evil_PortalApp *app = variable_item_get_context(item);
  84. furi_assert(app);
  85. const Evil_PortalItem *menu_item = &items[app->selected_menu_index];
  86. uint8_t item_index = variable_item_get_current_value_index(item);
  87. furi_assert(item_index < menu_item->num_options_menu);
  88. variable_item_set_current_value_text(item,
  89. menu_item->options_menu[item_index]);
  90. app->selected_option_index[app->selected_menu_index] = item_index;
  91. }
  92. void evil_portal_scene_start_on_enter(void *context) {
  93. Evil_PortalApp *app = context;
  94. VariableItemList *var_item_list = app->var_item_list;
  95. variable_item_list_set_enter_callback(
  96. var_item_list, evil_portal_scene_start_var_list_enter_callback, app);
  97. VariableItem *item;
  98. for (int i = 0; i < NUM_MENU_ITEMS; ++i) {
  99. item = variable_item_list_add(
  100. var_item_list, items[i].item_string, items[i].num_options_menu,
  101. evil_portal_scene_start_var_list_change_callback, app);
  102. variable_item_set_current_value_index(item, app->selected_option_index[i]);
  103. variable_item_set_current_value_text(
  104. item, items[i].options_menu[app->selected_option_index[i]]);
  105. }
  106. variable_item_list_set_selected_item(
  107. var_item_list,
  108. scene_manager_get_scene_state(app->scene_manager, Evil_PortalSceneStart));
  109. view_dispatcher_switch_to_view(app->view_dispatcher,
  110. Evil_PortalAppViewVarItemList);
  111. }
  112. bool evil_portal_scene_start_on_event(void *context, SceneManagerEvent event) {
  113. UNUSED(context);
  114. Evil_PortalApp *app = context;
  115. bool consumed = false;
  116. if (event.type == SceneManagerEventTypeCustom) {
  117. if (event.event == Evil_PortalEventStartPortal) {
  118. scene_manager_set_scene_state(app->scene_manager, Evil_PortalSceneStart,
  119. app->selected_menu_index);
  120. scene_manager_next_scene(app->scene_manager,
  121. Evil_PortalAppViewStartPortal);
  122. } else if (event.event == Evil_PortalEventStartKeyboard) {
  123. scene_manager_set_scene_state(app->scene_manager, Evil_PortalSceneStart,
  124. app->selected_menu_index);
  125. } else if (event.event == Evil_PortalEventStartConsole) {
  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_PortalAppViewConsoleOutput);
  130. }
  131. consumed = true;
  132. } else if (event.type == SceneManagerEventTypeTick) {
  133. app->selected_menu_index =
  134. variable_item_list_get_selected_item_index(app->var_item_list);
  135. consumed = true;
  136. }
  137. return consumed;
  138. }
  139. void evil_portal_scene_start_on_exit(void *context) {
  140. Evil_PortalApp *app = context;
  141. variable_item_list_reset(app->var_item_list);
  142. }