scope.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #include <furi.h>
  2. #include <furi_hal.h>
  3. #include <furi_hal_resources.h>
  4. #include <gui/gui.h>
  5. #include <gui/modules/submenu.h>
  6. #include <input/input.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include "scope_icons.h"
  10. #include <gui/gui.h>
  11. #include <gui/view_dispatcher.h>
  12. #include <gui/scene_manager.h>
  13. #include <gui/modules/submenu.h>
  14. #include <gui/modules/variable_item_list.h>
  15. #include <gui/modules/widget.h>
  16. #include <notification/notification_messages.h>
  17. #include "scope_app_i.h"
  18. #define TAG "Scope"
  19. static bool scope_app_custom_event_callback(void* context, uint32_t event) {
  20. furi_assert(context);
  21. ScopeApp* app = context;
  22. return scene_manager_handle_custom_event(app->scene_manager, event);
  23. }
  24. static bool scope_app_back_event_callback(void* context) {
  25. furi_assert(context);
  26. ScopeApp* app = context;
  27. return scene_manager_handle_back_event(app->scene_manager);
  28. }
  29. static void scope_app_tick_event_callback(void* context) {
  30. furi_assert(context);
  31. ScopeApp* app = context;
  32. scene_manager_handle_tick_event(app->scene_manager);
  33. }
  34. void assert_failed(uint8_t * file, uint32_t line)
  35. {
  36. UNUSED(file);
  37. UNUSED(line);
  38. while (1) {
  39. }
  40. }
  41. ScopeApp* scope_app_alloc() {
  42. ScopeApp* app = malloc(sizeof(ScopeApp));
  43. // GUI
  44. app->gui = furi_record_open(RECORD_GUI);
  45. // View Dispatcher
  46. app->view_dispatcher = view_dispatcher_alloc();
  47. app->scene_manager = scene_manager_alloc(&scope_scene_handlers, app);
  48. view_dispatcher_enable_queue(app->view_dispatcher);
  49. view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
  50. view_dispatcher_set_custom_event_callback(
  51. app->view_dispatcher, scope_app_custom_event_callback);
  52. view_dispatcher_set_navigation_event_callback(
  53. app->view_dispatcher, scope_app_back_event_callback);
  54. view_dispatcher_set_tick_event_callback(
  55. app->view_dispatcher, scope_app_tick_event_callback, 100);
  56. view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
  57. // Open Notification record
  58. app->notifications = furi_record_open(RECORD_NOTIFICATION);
  59. // Variable Item List
  60. app->variable_item_list = variable_item_list_alloc();
  61. view_dispatcher_add_view(
  62. app->view_dispatcher,
  63. ScopeViewVariableItemList,
  64. variable_item_list_get_view(app->variable_item_list));
  65. // SubMenu
  66. app->submenu = submenu_alloc();
  67. view_dispatcher_add_view(
  68. app->view_dispatcher, ScopeViewSubmenu, submenu_get_view(app->submenu));
  69. // Widget
  70. app->widget = widget_alloc();
  71. view_dispatcher_add_view(
  72. app->view_dispatcher, ScopeViewWidget, widget_get_view(app->widget));
  73. app->time = 0.001;
  74. scene_manager_next_scene(app->scene_manager, ScopeSceneStart);
  75. return app;
  76. }
  77. void scope_app_free(ScopeApp* app) {
  78. furi_assert(app);
  79. // Submenu
  80. view_dispatcher_remove_view(app->view_dispatcher, ScopeViewSubmenu);
  81. submenu_free(app->submenu);
  82. // Variable Item List
  83. view_dispatcher_remove_view(app->view_dispatcher, ScopeViewVariableItemList);
  84. variable_item_list_free(app->variable_item_list);
  85. // Widget
  86. view_dispatcher_remove_view(app->view_dispatcher, ScopeViewWidget);
  87. widget_free(app->widget);
  88. // View dispatcher
  89. view_dispatcher_free(app->view_dispatcher);
  90. scene_manager_free(app->scene_manager);
  91. // Notifications
  92. furi_record_close(RECORD_NOTIFICATION);
  93. app->notifications = NULL;
  94. // Close records
  95. furi_record_close(RECORD_GUI);
  96. free(app);
  97. }
  98. int32_t scope_main(void *p)
  99. {
  100. UNUSED(p);
  101. ScopeApp* scope_app = scope_app_alloc();
  102. view_dispatcher_run(scope_app->view_dispatcher);
  103. scope_app_free(scope_app);
  104. return 0;
  105. }