app.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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_enable_queue(app->view_dispatcher);
  35. view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
  36. view_dispatcher_set_custom_event_callback(app->view_dispatcher, custom_event_callback);
  37. view_dispatcher_set_navigation_event_callback(app->view_dispatcher, back_event_callback);
  38. view_dispatcher_set_tick_event_callback(app->view_dispatcher, tick_event_callback, 500);
  39. app->notification = furi_record_open(RECORD_NOTIFICATION);
  40. return app;
  41. }
  42. static void app_free(App* app) {
  43. furi_record_close(RECORD_NOTIFICATION);
  44. for(uint32_t i = 0; i < ViewIdMax; ++i) {
  45. view_dispatcher_remove_view(app->view_dispatcher, i);
  46. }
  47. progress_free(app->progress);
  48. submenu_free(app->submenu);
  49. widget_free(app->widget);
  50. scene_manager_free(app->scene_manager);
  51. view_dispatcher_free(app->view_dispatcher);
  52. furi_string_free(app->file_path);
  53. free(app);
  54. }
  55. void submenu_item_common_callback(void* context, uint32_t index) {
  56. furi_assert(context);
  57. App* app = context;
  58. view_dispatcher_send_custom_event(app->view_dispatcher, index);
  59. }
  60. int32_t vgm_tool_app(void* arg) {
  61. UNUSED(arg);
  62. Expansion* expansion = furi_record_open(RECORD_EXPANSION);
  63. expansion_disable(expansion);
  64. const bool is_debug_enabled = furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug);
  65. if(is_debug_enabled) {
  66. furi_hal_debug_disable();
  67. }
  68. App* app = app_alloc();
  69. Gui* gui = furi_record_open(RECORD_GUI);
  70. view_dispatcher_attach_to_gui(app->view_dispatcher, gui, ViewDispatcherTypeFullscreen);
  71. scene_manager_next_scene(app->scene_manager, SceneProbe);
  72. view_dispatcher_run(app->view_dispatcher);
  73. flasher_deinit();
  74. app_free(app);
  75. furi_record_close(RECORD_GUI);
  76. if(is_debug_enabled) {
  77. furi_hal_debug_enable();
  78. }
  79. expansion_enable(expansion);
  80. furi_record_close(RECORD_EXPANSION);
  81. return 0;
  82. }