subbrute.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. #include "subbrute_i.h"
  2. #include "subbrute_custom_event.h"
  3. #include "scenes/subbrute_scene.h"
  4. #define TAG "SubBruteApp"
  5. static bool subbrute_custom_event_callback(void* context, uint32_t event) {
  6. furi_assert(context);
  7. SubBruteState* instance = context;
  8. return scene_manager_handle_custom_event(instance->scene_manager, event);
  9. }
  10. static bool subbrute_back_event_callback(void* context) {
  11. furi_assert(context);
  12. SubBruteState* instance = context;
  13. return scene_manager_handle_back_event(instance->scene_manager);
  14. }
  15. static void subbrute_tick_event_callback(void* context) {
  16. furi_assert(context);
  17. SubBruteState* instance = context;
  18. scene_manager_handle_tick_event(instance->scene_manager);
  19. }
  20. SubBruteState* subbrute_alloc() {
  21. SubBruteState* instance = malloc(sizeof(SubBruteState));
  22. memset(instance->text_store, 0, sizeof(instance->text_store));
  23. string_init(instance->file_path);
  24. instance->scene_manager = scene_manager_alloc(&subbrute_scene_handlers, instance);
  25. instance->view_dispatcher = view_dispatcher_alloc();
  26. instance->gui = furi_record_open(RECORD_GUI);
  27. view_dispatcher_enable_queue(instance->view_dispatcher);
  28. view_dispatcher_set_event_callback_context(instance->view_dispatcher, instance);
  29. view_dispatcher_set_custom_event_callback(
  30. instance->view_dispatcher, subbrute_custom_event_callback);
  31. view_dispatcher_set_navigation_event_callback(
  32. instance->view_dispatcher, subbrute_back_event_callback);
  33. view_dispatcher_set_tick_event_callback(
  34. instance->view_dispatcher, subbrute_tick_event_callback, 10);
  35. //Dialog
  36. instance->dialogs = furi_record_open(RECORD_DIALOGS);
  37. // Notifications
  38. instance->notifications = furi_record_open(RECORD_NOTIFICATION);
  39. // Devices
  40. instance->device = subbrute_device_alloc();
  41. // TextInput
  42. instance->text_input = text_input_alloc();
  43. view_dispatcher_add_view(
  44. instance->view_dispatcher,
  45. SubBruteViewTextInput,
  46. text_input_get_view(instance->text_input));
  47. // Custom Widget
  48. instance->widget = widget_alloc();
  49. view_dispatcher_add_view(
  50. instance->view_dispatcher, SubBruteViewWidget, widget_get_view(instance->widget));
  51. // Popup
  52. instance->popup = popup_alloc();
  53. view_dispatcher_add_view(
  54. instance->view_dispatcher, SubBruteViewPopup, popup_get_view(instance->popup));
  55. // ViewStack
  56. instance->view_stack = view_stack_alloc();
  57. view_dispatcher_add_view(
  58. instance->view_dispatcher, SubBruteViewStack, view_stack_get_view(instance->view_stack));
  59. // SubBruteMainView
  60. instance->view_main = subbrute_main_view_alloc();
  61. view_dispatcher_add_view(
  62. instance->view_dispatcher,
  63. SubBruteViewMain,
  64. subbrute_main_view_get_view(instance->view_main));
  65. // SubBruteAttackView
  66. instance->view_attack = subbrute_attack_view_alloc();
  67. view_dispatcher_add_view(
  68. instance->view_dispatcher,
  69. SubBruteViewAttack,
  70. subbrute_attack_view_get_view(instance->view_attack));
  71. // Loading
  72. instance->loading = loading_alloc();
  73. //instance->flipper_format = flipper_format_string_alloc();
  74. //instance->environment = subghz_environment_alloc();
  75. return instance;
  76. }
  77. void subbrute_free(SubBruteState* instance) {
  78. furi_assert(instance);
  79. // SubBruteDevice
  80. #ifdef FURI_DEBUG
  81. FURI_LOG_D(TAG, "free SubBruteDevice");
  82. #endif
  83. subbrute_worker_stop(instance->device);
  84. subbrute_device_free(instance->device);
  85. // Notifications
  86. #ifdef FURI_DEBUG
  87. FURI_LOG_D(TAG, "free Notifications");
  88. #endif
  89. notification_message(instance->notifications, &sequence_blink_stop);
  90. furi_record_close(RECORD_NOTIFICATION);
  91. instance->notifications = NULL;
  92. // Loading
  93. #ifdef FURI_DEBUG
  94. FURI_LOG_D(TAG, "free loading");
  95. #endif
  96. loading_free(instance->loading);
  97. // View Main
  98. #ifdef FURI_DEBUG
  99. FURI_LOG_D(TAG, "free SubBruteViewMain");
  100. #endif
  101. view_dispatcher_remove_view(instance->view_dispatcher, SubBruteViewMain);
  102. subbrute_main_view_free(instance->view_main);
  103. // View Attack
  104. #ifdef FURI_DEBUG
  105. FURI_LOG_D(TAG, "free SubBruteViewAttack");
  106. #endif
  107. view_dispatcher_remove_view(instance->view_dispatcher, SubBruteViewAttack);
  108. subbrute_attack_view_free(instance->view_attack);
  109. // TextInput
  110. #ifdef FURI_DEBUG
  111. FURI_LOG_D(TAG, "free SubBruteViewTextInput");
  112. #endif
  113. view_dispatcher_remove_view(instance->view_dispatcher, SubBruteViewTextInput);
  114. text_input_free(instance->text_input);
  115. // Custom Widget
  116. #ifdef FURI_DEBUG
  117. FURI_LOG_D(TAG, "free SubBruteViewWidget");
  118. #endif
  119. view_dispatcher_remove_view(instance->view_dispatcher, SubBruteViewWidget);
  120. widget_free(instance->widget);
  121. // Popup
  122. #ifdef FURI_DEBUG
  123. FURI_LOG_D(TAG, "free SubBruteViewPopup");
  124. #endif
  125. view_dispatcher_remove_view(instance->view_dispatcher, SubBruteViewPopup);
  126. popup_free(instance->popup);
  127. // ViewStack
  128. #ifdef FURI_DEBUG
  129. FURI_LOG_D(TAG, "free SubBruteViewStack");
  130. #endif
  131. view_dispatcher_remove_view(instance->view_dispatcher, SubBruteViewStack);
  132. view_stack_free(instance->view_stack);
  133. //Dialog
  134. #ifdef FURI_DEBUG
  135. FURI_LOG_D(TAG, "free RECORD_DIALOGS");
  136. #endif
  137. furi_record_close(RECORD_DIALOGS);
  138. instance->dialogs = NULL;
  139. // Scene manager
  140. #ifdef FURI_DEBUG
  141. FURI_LOG_D(TAG, "free scene_manager");
  142. #endif
  143. scene_manager_free(instance->scene_manager);
  144. // View Dispatcher
  145. #ifdef FURI_DEBUG
  146. FURI_LOG_D(TAG, "free view_dispatcher");
  147. #endif
  148. view_dispatcher_free(instance->view_dispatcher);
  149. // GUI
  150. #ifdef FURI_DEBUG
  151. FURI_LOG_D(TAG, "free RECORD_GUI");
  152. #endif
  153. furi_record_close(RECORD_GUI);
  154. instance->gui = NULL;
  155. string_clear(instance->file_path);
  156. string_init(instance->file_path);
  157. // The rest
  158. #ifdef FURI_DEBUG
  159. FURI_LOG_D(TAG, "free instance");
  160. #endif
  161. free(instance);
  162. }
  163. void subbrute_show_loading_popup(void* context, bool show) {
  164. TaskHandle_t timer_task = xTaskGetHandle(configTIMER_SERVICE_TASK_NAME);
  165. SubBruteState* instance = context;
  166. ViewStack* view_stack = instance->view_stack;
  167. Loading* loading = instance->loading;
  168. if(show) {
  169. // Raise timer priority so that animations can play
  170. vTaskPrioritySet(timer_task, configMAX_PRIORITIES - 1);
  171. view_stack_add_view(view_stack, loading_get_view(loading));
  172. } else {
  173. view_stack_remove_view(view_stack, loading_get_view(loading));
  174. // Restore default timer priority
  175. vTaskPrioritySet(timer_task, configTIMER_TASK_PRIORITY);
  176. }
  177. }
  178. void subbrute_text_input_callback(void* context) {
  179. furi_assert(context);
  180. SubBruteState* instance = context;
  181. view_dispatcher_send_custom_event(
  182. instance->view_dispatcher, SubBruteCustomEventTypeTextEditDone);
  183. }
  184. void subbrute_popup_closed_callback(void* context) {
  185. furi_assert(context);
  186. SubBruteState* instance = context;
  187. view_dispatcher_send_custom_event(
  188. instance->view_dispatcher, SubBruteCustomEventTypePopupClosed);
  189. }
  190. // ENTRYPOINT
  191. int32_t subbrute_app(void* p) {
  192. UNUSED(p);
  193. SubBruteState* instance = subbrute_alloc();
  194. view_dispatcher_attach_to_gui(
  195. instance->view_dispatcher, instance->gui, ViewDispatcherTypeFullscreen);
  196. scene_manager_next_scene(instance->scene_manager, SubBruteSceneStart);
  197. furi_hal_power_suppress_charge_enter();
  198. notification_message(instance->notifications, &sequence_display_backlight_on);
  199. view_dispatcher_run(instance->view_dispatcher);
  200. furi_hal_power_suppress_charge_exit();
  201. subbrute_free(instance);
  202. return 0;
  203. }