wifi_deauther_app.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #include "wifi_deauther_app_i.h"
  2. #include <furi_hal_power.h>
  3. #include <furi.h>
  4. #include <furi_hal.h>
  5. static bool wifi_deauther_app_custom_event_callback(void* context, uint32_t event) {
  6. furi_assert(context);
  7. WifideautherApp* app = context;
  8. return scene_manager_handle_custom_event(app->scene_manager, event);
  9. }
  10. static bool wifi_deauther_app_back_event_callback(void* context) {
  11. furi_assert(context);
  12. WifideautherApp* app = context;
  13. return scene_manager_handle_back_event(app->scene_manager);
  14. }
  15. static void wifi_deauther_app_tick_event_callback(void* context) {
  16. furi_assert(context);
  17. WifideautherApp* app = context;
  18. scene_manager_handle_tick_event(app->scene_manager);
  19. }
  20. WifideautherApp* wifi_deauther_app_alloc() {
  21. WifideautherApp* app = malloc(sizeof(WifideautherApp));
  22. app->gui = furi_record_open(RECORD_GUI);
  23. app->view_dispatcher = view_dispatcher_alloc();
  24. app->scene_manager = scene_manager_alloc(&wifi_deauther_scene_handlers, app);
  25. view_dispatcher_enable_queue(app->view_dispatcher);
  26. view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
  27. view_dispatcher_set_custom_event_callback(
  28. app->view_dispatcher, wifi_deauther_app_custom_event_callback);
  29. view_dispatcher_set_navigation_event_callback(
  30. app->view_dispatcher, wifi_deauther_app_back_event_callback);
  31. view_dispatcher_set_tick_event_callback(
  32. app->view_dispatcher, wifi_deauther_app_tick_event_callback, 100);
  33. view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
  34. app->var_item_list = variable_item_list_alloc();
  35. view_dispatcher_add_view(
  36. app->view_dispatcher,
  37. WifideautherAppViewVarItemList,
  38. variable_item_list_get_view(app->var_item_list));
  39. for(int i = 0; i < NUM_MENU_ITEMS; ++i) {
  40. app->selected_option_index[i] = 0;
  41. }
  42. app->text_box = text_box_alloc();
  43. view_dispatcher_add_view(
  44. app->view_dispatcher, WifideautherAppViewConsoleOutput, text_box_get_view(app->text_box));
  45. app->text_box_store = furi_string_alloc();
  46. furi_string_reserve(app->text_box_store, WIFI_deauther_TEXT_BOX_STORE_SIZE);
  47. app->text_input = text_input_alloc();
  48. view_dispatcher_add_view(
  49. app->view_dispatcher, WifideautherAppViewTextInput, text_input_get_view(app->text_input));
  50. scene_manager_next_scene(app->scene_manager, WifideautherSceneStart);
  51. return app;
  52. }
  53. void wifi_deauther_app_free(WifideautherApp* app) {
  54. furi_assert(app);
  55. // Views
  56. view_dispatcher_remove_view(app->view_dispatcher, WifideautherAppViewVarItemList);
  57. view_dispatcher_remove_view(app->view_dispatcher, WifideautherAppViewConsoleOutput);
  58. view_dispatcher_remove_view(app->view_dispatcher, WifideautherAppViewTextInput);
  59. text_box_free(app->text_box);
  60. furi_string_free(app->text_box_store);
  61. text_input_free(app->text_input);
  62. // View dispatcher
  63. view_dispatcher_free(app->view_dispatcher);
  64. scene_manager_free(app->scene_manager);
  65. wifi_deauther_uart_free(app->uart);
  66. // Close records
  67. furi_record_close(RECORD_GUI);
  68. free(app);
  69. }
  70. int32_t wifi_deauther_app(void* p) {
  71. furi_hal_power_enable_otg();
  72. furi_delay_ms(600);
  73. UNUSED(p);
  74. WifideautherApp* wifi_deauther_app = wifi_deauther_app_alloc();
  75. wifi_deauther_app->uart = wifi_deauther_uart_init(wifi_deauther_app);
  76. view_dispatcher_run(wifi_deauther_app->view_dispatcher);
  77. wifi_deauther_app_free(wifi_deauther_app);
  78. furi_hal_power_disable_otg();
  79. return 0;
  80. }