hex_viewer.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #include "hex_viewer.h"
  2. bool hex_viewer_custom_event_callback(void* context, uint32_t event) {
  3. furi_assert(context);
  4. Boilerplate* app = context;
  5. return scene_manager_handle_custom_event(app->scene_manager, event);
  6. }
  7. void hex_viewer_tick_event_callback(void* context) {
  8. furi_assert(context);
  9. Boilerplate* app = context;
  10. scene_manager_handle_tick_event(app->scene_manager);
  11. }
  12. //leave app if back button pressed
  13. bool hex_viewer_navigation_event_callback(void* context) {
  14. furi_assert(context);
  15. Boilerplate* app = context;
  16. return scene_manager_handle_back_event(app->scene_manager);
  17. }
  18. Boilerplate* hex_viewer_app_alloc() {
  19. Boilerplate* app = malloc(sizeof(Boilerplate));
  20. app->gui = furi_record_open(RECORD_GUI);
  21. app->notification = furi_record_open(RECORD_NOTIFICATION);
  22. //Turn backlight on, believe me this makes testing your app easier
  23. notification_message(app->notification, &sequence_display_backlight_on);
  24. //Scene additions
  25. app->view_dispatcher = view_dispatcher_alloc();
  26. view_dispatcher_enable_queue(app->view_dispatcher);
  27. app->scene_manager = scene_manager_alloc(&hex_viewer_scene_handlers, app);
  28. view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
  29. view_dispatcher_set_navigation_event_callback(app->view_dispatcher, hex_viewer_navigation_event_callback);
  30. view_dispatcher_set_tick_event_callback(app->view_dispatcher, hex_viewer_tick_event_callback, 100);
  31. view_dispatcher_set_custom_event_callback(app->view_dispatcher, hex_viewer_custom_event_callback);
  32. app->submenu = submenu_alloc();
  33. // Set defaults, in case no config loaded
  34. app->haptic = 1;
  35. app->speaker = 1;
  36. app->led = 1;
  37. app->save_settings = 1;
  38. // Used for File Browser
  39. app->dialogs = furi_record_open(RECORD_DIALOGS);
  40. app->file_path = furi_string_alloc();
  41. // Load configs
  42. hex_viewer_read_settings(app);
  43. view_dispatcher_add_view(app->view_dispatcher, BoilerplateViewIdMenu, submenu_get_view(app->submenu));
  44. app->hex_viewer_startscreen = hex_viewer_startscreen_alloc();
  45. view_dispatcher_add_view(app->view_dispatcher, BoilerplateViewIdStartscreen, hex_viewer_startscreen_get_view(app->hex_viewer_startscreen));
  46. app->hex_viewer_scene_1 = hex_viewer_scene_1_alloc();
  47. view_dispatcher_add_view(app->view_dispatcher, BoilerplateViewIdScene1, hex_viewer_scene_1_get_view(app->hex_viewer_scene_1));
  48. app->hex_viewer_scene_2 = hex_viewer_scene_2_alloc();
  49. view_dispatcher_add_view(app->view_dispatcher, BoilerplateViewIdScene2, hex_viewer_scene_2_get_view(app->hex_viewer_scene_2));
  50. app->button_menu = button_menu_alloc();
  51. view_dispatcher_add_view(app->view_dispatcher, BoilerplateViewIdScene3, button_menu_get_view(app->button_menu));
  52. app->variable_item_list = variable_item_list_alloc();
  53. view_dispatcher_add_view(app->view_dispatcher, BoilerplateViewIdSettings, variable_item_list_get_view(app->variable_item_list));
  54. //End Scene Additions
  55. return app;
  56. }
  57. void hex_viewer_app_free(Boilerplate* app) {
  58. furi_assert(app);
  59. // Scene manager
  60. scene_manager_free(app->scene_manager);
  61. // View Dispatcher
  62. view_dispatcher_remove_view(app->view_dispatcher, BoilerplateViewIdMenu);
  63. view_dispatcher_remove_view(app->view_dispatcher, BoilerplateViewIdScene1);
  64. view_dispatcher_remove_view(app->view_dispatcher, BoilerplateViewIdScene2);
  65. view_dispatcher_remove_view(app->view_dispatcher, BoilerplateViewIdSettings);
  66. submenu_free(app->submenu);
  67. view_dispatcher_free(app->view_dispatcher);
  68. furi_record_close(RECORD_GUI);
  69. app->gui = NULL;
  70. app->notification = NULL;
  71. // Close File Browser
  72. furi_record_close(RECORD_DIALOGS);
  73. furi_string_free(app->file_path);
  74. //Remove whatever is left
  75. free(app);
  76. }
  77. int32_t hex_viewer_app(void* p) {
  78. UNUSED(p);
  79. Boilerplate* app = hex_viewer_app_alloc();
  80. view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
  81. scene_manager_next_scene(app->scene_manager, BoilerplateSceneStartscreen); //Start with start screen
  82. //scene_manager_next_scene(app->scene_manager, BoilerplateSceneMenu); //if you want to directly start with Menu
  83. furi_hal_power_suppress_charge_enter();
  84. view_dispatcher_run(app->view_dispatcher);
  85. hex_viewer_save_settings(app);
  86. furi_hal_power_suppress_charge_exit();
  87. hex_viewer_app_free(app);
  88. return 0;
  89. }