scope.c 3.5 KB

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