quac.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #include <furi.h>
  2. #include <gui/gui.h>
  3. #include <gui/view_dispatcher.h>
  4. #include <gui/scene_manager.h>
  5. #include <gui/modules/dialog_ex.h>
  6. #include <gui/modules/variable_item_list.h>
  7. #include <storage/storage.h>
  8. #include <notification/notification_messages.h>
  9. #include "item.h"
  10. #include "scenes/scenes.h"
  11. #include "scenes/scene_items.h"
  12. #include "quac.h"
  13. #include "quac_settings.h"
  14. /* generated by fbt from .png files in images folder */
  15. #include <quac_icons.h>
  16. App* app_alloc() {
  17. App* app = malloc(sizeof(App));
  18. app->scene_manager = scene_manager_alloc(&app_scene_handlers, app);
  19. app->view_dispatcher = view_dispatcher_alloc();
  20. view_dispatcher_enable_queue(app->view_dispatcher);
  21. view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
  22. view_dispatcher_set_custom_event_callback(app->view_dispatcher, app_scene_custom_callback);
  23. view_dispatcher_set_navigation_event_callback(app->view_dispatcher, app_back_event_callback);
  24. // Create our UI elements
  25. // Main interface
  26. app->action_menu = action_menu_alloc();
  27. view_dispatcher_add_view(
  28. app->view_dispatcher, Q_ActionMenu, action_menu_get_view(app->action_menu));
  29. // App settings
  30. app->vil_settings = variable_item_list_alloc();
  31. view_dispatcher_add_view(
  32. app->view_dispatcher, Q_Settings, variable_item_list_get_view(app->vil_settings));
  33. app->dialog = dialog_ex_alloc();
  34. view_dispatcher_add_view(app->view_dispatcher, Q_Dialog, dialog_ex_get_view(app->dialog));
  35. // Storage
  36. app->storage = furi_record_open(RECORD_STORAGE);
  37. // Notifications - for LED light access
  38. app->notifications = furi_record_open(RECORD_NOTIFICATION);
  39. // data member initialize
  40. app->depth = 0;
  41. app->selected_item = -1;
  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, Q_ActionMenu);
  48. view_dispatcher_remove_view(app->view_dispatcher, Q_Settings);
  49. view_dispatcher_remove_view(app->view_dispatcher, Q_Dialog);
  50. action_menu_free(app->action_menu);
  51. variable_item_list_free(app->vil_settings);
  52. dialog_ex_free(app->dialog);
  53. scene_manager_free(app->scene_manager);
  54. view_dispatcher_free(app->view_dispatcher);
  55. furi_record_close(RECORD_STORAGE);
  56. furi_record_close(RECORD_NOTIFICATION);
  57. free(app);
  58. }
  59. // FAP Entry Point
  60. int32_t quac_app(void* p) {
  61. UNUSED(p);
  62. FURI_LOG_I(TAG, "QUAC! QUAC!");
  63. size_t free_start = memmgr_get_free_heap();
  64. App* app = app_alloc();
  65. quac_load_settings(app);
  66. // Read items at our root
  67. app->items_view = item_get_items_view_from_path(app, NULL);
  68. Gui* gui = furi_record_open(RECORD_GUI);
  69. view_dispatcher_attach_to_gui(app->view_dispatcher, gui, ViewDispatcherTypeFullscreen);
  70. scene_manager_next_scene(app->scene_manager, Q_Scene_Items);
  71. view_dispatcher_run(app->view_dispatcher);
  72. furi_record_close(RECORD_GUI);
  73. app_free(app);
  74. size_t free_end = memmgr_get_free_heap();
  75. FURI_LOG_W(TAG, "Heap: Start = %d, End = %d", free_start, free_end);
  76. return 0;
  77. }