app.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #include <furi.h>
  2. #include <furi_hal_rtc.h>
  3. #include <furi_hal_debug.h>
  4. #include <gui/gui.h>
  5. #include <expansion/expansion.h>
  6. #include "app_i.h"
  7. static bool custom_event_callback(void* context, uint32_t event) {
  8. furi_assert(context);
  9. App* app = context;
  10. return scene_manager_handle_custom_event(app->scene_manager, event);
  11. }
  12. static bool back_event_callback(void* context) {
  13. furi_assert(context);
  14. App* app = context;
  15. return scene_manager_handle_back_event(app->scene_manager);
  16. }
  17. static void tick_event_callback(void* context) {
  18. furi_assert(context);
  19. App* app = context;
  20. scene_manager_handle_tick_event(app->scene_manager);
  21. }
  22. static App* app_alloc() {
  23. App* app = malloc(sizeof(App));
  24. app->file_path = furi_string_alloc();
  25. app->view_dispatcher = view_dispatcher_alloc();
  26. app->scene_manager = scene_manager_alloc(&scene_handlers, app);
  27. app->widget = widget_alloc();
  28. app->submenu = submenu_alloc();
  29. app->progress = progress_alloc();
  30. view_dispatcher_add_view(app->view_dispatcher, ViewIdWidget, widget_get_view(app->widget));
  31. view_dispatcher_add_view(app->view_dispatcher, ViewIdSubmenu, submenu_get_view(app->submenu));
  32. view_dispatcher_add_view(
  33. app->view_dispatcher, ViewIdProgress, progress_get_view(app->progress));
  34. view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
  35. view_dispatcher_set_custom_event_callback(app->view_dispatcher, custom_event_callback);
  36. view_dispatcher_set_navigation_event_callback(app->view_dispatcher, back_event_callback);
  37. view_dispatcher_set_tick_event_callback(app->view_dispatcher, tick_event_callback, 500);
  38. app->notification = furi_record_open(RECORD_NOTIFICATION);
  39. return app;
  40. }
  41. static void app_free(App* app) {
  42. furi_record_close(RECORD_NOTIFICATION);
  43. for(uint32_t i = 0; i < ViewIdMax; ++i) {
  44. view_dispatcher_remove_view(app->view_dispatcher, i);
  45. }
  46. progress_free(app->progress);
  47. submenu_free(app->submenu);
  48. widget_free(app->widget);
  49. scene_manager_free(app->scene_manager);
  50. view_dispatcher_free(app->view_dispatcher);
  51. furi_string_free(app->file_path);
  52. free(app);
  53. }
  54. void submenu_item_common_callback(void* context, uint32_t index) {
  55. furi_assert(context);
  56. App* app = context;
  57. view_dispatcher_send_custom_event(app->view_dispatcher, index);
  58. }
  59. int32_t vgm_tool_app(void* arg) {
  60. UNUSED(arg);
  61. Expansion* expansion = furi_record_open(RECORD_EXPANSION);
  62. expansion_disable(expansion);
  63. const bool is_debug_enabled = furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug);
  64. if(is_debug_enabled) {
  65. furi_hal_debug_disable();
  66. }
  67. App* app = app_alloc();
  68. Gui* gui = furi_record_open(RECORD_GUI);
  69. view_dispatcher_attach_to_gui(app->view_dispatcher, gui, ViewDispatcherTypeFullscreen);
  70. scene_manager_next_scene(app->scene_manager, SceneProbe);
  71. view_dispatcher_run(app->view_dispatcher);
  72. flasher_deinit();
  73. app_free(app);
  74. furi_record_close(RECORD_GUI);
  75. if(is_debug_enabled) {
  76. furi_hal_debug_enable();
  77. }
  78. expansion_enable(expansion);
  79. furi_record_close(RECORD_EXPANSION);
  80. return 0;
  81. }