portal_of_flipper.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #include <furi.h>
  2. #include "portal_of_flipper_i.h"
  3. static bool pof_app_custom_event_callback(void* context, uint32_t event) {
  4. furi_assert(context);
  5. PoFApp* app = context;
  6. return scene_manager_handle_custom_event(app->scene_manager, event);
  7. }
  8. static bool pof_app_back_event_callback(void* context) {
  9. furi_assert(context);
  10. PoFApp* app = context;
  11. return scene_manager_handle_back_event(app->scene_manager);
  12. }
  13. static void pof_app_tick_event_callback(void* context) {
  14. furi_assert(context);
  15. PoFApp* app = context;
  16. scene_manager_handle_tick_event(app->scene_manager);
  17. }
  18. void pof_show_loading_popup(void* context, bool show) {
  19. PoFApp* app = context;
  20. if(show) {
  21. // Raise timer priority so that animations can play
  22. furi_timer_set_thread_priority(FuriTimerThreadPriorityElevated);
  23. view_dispatcher_switch_to_view(app->view_dispatcher, PoFViewLoading);
  24. } else {
  25. // Restore default timer priority
  26. furi_timer_set_thread_priority(FuriTimerThreadPriorityNormal);
  27. }
  28. }
  29. PoFApp* pof_app_alloc() {
  30. PoFApp* app = malloc(sizeof(PoFApp));
  31. // GUI
  32. app->gui = furi_record_open(RECORD_GUI);
  33. // View Dispatcher
  34. app->view_dispatcher = view_dispatcher_alloc();
  35. app->scene_manager = scene_manager_alloc(&pof_scene_handlers, app);
  36. view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
  37. view_dispatcher_set_custom_event_callback(app->view_dispatcher, pof_app_custom_event_callback);
  38. view_dispatcher_set_navigation_event_callback(
  39. app->view_dispatcher, pof_app_back_event_callback);
  40. view_dispatcher_set_tick_event_callback(
  41. app->view_dispatcher, pof_app_tick_event_callback, 100);
  42. view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
  43. // Open Notification record
  44. app->notifications = furi_record_open(RECORD_NOTIFICATION);
  45. // SubMenu
  46. app->submenu = submenu_alloc();
  47. view_dispatcher_add_view(app->view_dispatcher, PoFViewSubmenu, submenu_get_view(app->submenu));
  48. // Popup
  49. app->popup = popup_alloc();
  50. view_dispatcher_add_view(app->view_dispatcher, PoFViewPopup, popup_get_view(app->popup));
  51. // Loading
  52. app->loading = loading_alloc();
  53. view_dispatcher_add_view(app->view_dispatcher, PoFViewLoading, loading_get_view(app->loading));
  54. // Widget
  55. app->widget = widget_alloc();
  56. view_dispatcher_add_view(app->view_dispatcher, PoFViewWidget, widget_get_view(app->widget));
  57. app->virtual_portal = virtual_portal_alloc(app->notifications);
  58. scene_manager_next_scene(app->scene_manager, PoFSceneTypeSelect);
  59. return app;
  60. }
  61. void pof_app_free(PoFApp* app) {
  62. furi_assert(app);
  63. // PoF emulation Stop
  64. pof_stop(app);
  65. // Submenu
  66. view_dispatcher_remove_view(app->view_dispatcher, PoFViewSubmenu);
  67. submenu_free(app->submenu);
  68. // Popup
  69. view_dispatcher_remove_view(app->view_dispatcher, PoFViewPopup);
  70. popup_free(app->popup);
  71. // Loading
  72. view_dispatcher_remove_view(app->view_dispatcher, PoFViewLoading);
  73. loading_free(app->loading);
  74. // Widget
  75. view_dispatcher_remove_view(app->view_dispatcher, PoFViewWidget);
  76. widget_free(app->widget);
  77. // View dispatcher
  78. view_dispatcher_free(app->view_dispatcher);
  79. scene_manager_free(app->scene_manager);
  80. // Notifications
  81. furi_record_close(RECORD_NOTIFICATION);
  82. app->notifications = NULL;
  83. // Close records
  84. furi_record_close(RECORD_GUI);
  85. virtual_portal_free(app->virtual_portal);
  86. app->virtual_portal = NULL;
  87. free(app);
  88. }
  89. int32_t portal_of_flipper_app(void* p) {
  90. UNUSED(p);
  91. PoFApp* pof_app = pof_app_alloc();
  92. view_dispatcher_run(pof_app->view_dispatcher);
  93. pof_app_free(pof_app);
  94. return 0;
  95. }