quac.c 3.5 KB

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