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