scope.c 3.8 KB

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