evil_portal_scene_start.c 5.3 KB

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