quac.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #include <furi.h>
  2. #include "quac.h"
  3. #include "quac_settings.h"
  4. #include "item.h"
  5. #include "scenes/scenes.h"
  6. /* generated by fbt from .png files in images folder */
  7. #include <quac_icons.h>
  8. App* app_alloc() {
  9. App* app = malloc(sizeof(App));
  10. app->scene_manager = scene_manager_alloc(&app_scene_handlers, app);
  11. app->view_dispatcher = view_dispatcher_alloc();
  12. view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
  13. view_dispatcher_set_custom_event_callback(app->view_dispatcher, app_scene_custom_callback);
  14. view_dispatcher_set_navigation_event_callback(app->view_dispatcher, app_back_event_callback);
  15. // Create our UI elements
  16. // Main interface
  17. app->action_menu = action_menu_alloc();
  18. view_dispatcher_add_view(
  19. app->view_dispatcher, QView_ActionMenu, action_menu_get_view(app->action_menu));
  20. // App settings
  21. app->vil_settings = variable_item_list_alloc();
  22. view_dispatcher_add_view(
  23. app->view_dispatcher, QView_Settings, variable_item_list_get_view(app->vil_settings));
  24. // Misc interfaces
  25. app->sub_menu = submenu_alloc();
  26. view_dispatcher_add_view(app->view_dispatcher, QView_SubMenu, submenu_get_view(app->sub_menu));
  27. app->text_input = text_input_alloc();
  28. view_dispatcher_add_view(
  29. app->view_dispatcher, QView_TextInput, text_input_get_view(app->text_input));
  30. app->popup = popup_alloc();
  31. view_dispatcher_add_view(app->view_dispatcher, QView_Popup, popup_get_view(app->popup));
  32. // Storage
  33. app->storage = furi_record_open(RECORD_STORAGE);
  34. // Notifications - for LED light access
  35. app->notifications = furi_record_open(RECORD_NOTIFICATION);
  36. app->dialog = furi_record_open(RECORD_DIALOGS);
  37. // data member initialize
  38. app->depth = 0;
  39. app->selected_item = -1;
  40. app->temp_str = furi_string_alloc();
  41. return app;
  42. }
  43. void app_free(App* app) {
  44. furi_assert(app);
  45. item_items_view_free(app->items_view);
  46. view_dispatcher_remove_view(app->view_dispatcher, QView_ActionMenu);
  47. view_dispatcher_remove_view(app->view_dispatcher, QView_Settings);
  48. view_dispatcher_remove_view(app->view_dispatcher, QView_SubMenu);
  49. view_dispatcher_remove_view(app->view_dispatcher, QView_TextInput);
  50. view_dispatcher_remove_view(app->view_dispatcher, QView_Popup);
  51. action_menu_free(app->action_menu);
  52. variable_item_list_free(app->vil_settings);
  53. submenu_free(app->sub_menu);
  54. text_input_free(app->text_input);
  55. scene_manager_free(app->scene_manager);
  56. view_dispatcher_free(app->view_dispatcher);
  57. furi_string_free(app->temp_str);
  58. furi_record_close(RECORD_STORAGE);
  59. furi_record_close(RECORD_NOTIFICATION);
  60. furi_record_close(RECORD_DIALOGS);
  61. free(app);
  62. }
  63. // FAP Entry Point
  64. int32_t quac_app(void* p) {
  65. UNUSED(p);
  66. FURI_LOG_I(TAG, "QUAC! QUAC!");
  67. size_t free_start = memmgr_get_free_heap();
  68. App* app = app_alloc();
  69. quac_load_settings(app);
  70. // Read items at our root
  71. app->items_view = item_get_items_view_from_path(app, NULL);
  72. Gui* gui = furi_record_open(RECORD_GUI);
  73. view_dispatcher_attach_to_gui(app->view_dispatcher, gui, ViewDispatcherTypeFullscreen);
  74. scene_manager_next_scene(app->scene_manager, QScene_Items);
  75. view_dispatcher_run(app->view_dispatcher);
  76. furi_record_close(RECORD_GUI);
  77. app_free(app);
  78. size_t free_end = memmgr_get_free_heap();
  79. FURI_LOG_W(TAG, "Heap: Start = %d, End = %d", free_start, free_end);
  80. return 0;
  81. }