dap_gui.c 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #include "dap_gui.h"
  2. #include "dap_gui_i.h"
  3. #define DAP_GUI_TICK 250
  4. static bool dap_gui_custom_event_callback(void* context, uint32_t event) {
  5. furi_assert(context);
  6. DapGuiApp* app = context;
  7. return scene_manager_handle_custom_event(app->scene_manager, event);
  8. }
  9. static bool dap_gui_back_event_callback(void* context) {
  10. furi_assert(context);
  11. DapGuiApp* app = context;
  12. return scene_manager_handle_back_event(app->scene_manager);
  13. }
  14. static void dap_gui_tick_event_callback(void* context) {
  15. furi_assert(context);
  16. DapGuiApp* app = context;
  17. scene_manager_handle_tick_event(app->scene_manager);
  18. }
  19. DapGuiApp* dap_gui_alloc() {
  20. DapGuiApp* app = malloc(sizeof(DapGuiApp));
  21. app->gui = furi_record_open(RECORD_GUI);
  22. app->view_dispatcher = view_dispatcher_alloc();
  23. app->scene_manager = scene_manager_alloc(&dap_scene_handlers, app);
  24. view_dispatcher_enable_queue(app->view_dispatcher);
  25. view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
  26. view_dispatcher_set_custom_event_callback(app->view_dispatcher, dap_gui_custom_event_callback);
  27. view_dispatcher_set_navigation_event_callback(
  28. app->view_dispatcher, dap_gui_back_event_callback);
  29. view_dispatcher_set_tick_event_callback(
  30. app->view_dispatcher, dap_gui_tick_event_callback, DAP_GUI_TICK);
  31. view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
  32. app->notifications = furi_record_open(RECORD_NOTIFICATION);
  33. app->var_item_list = variable_item_list_alloc();
  34. view_dispatcher_add_view(
  35. app->view_dispatcher,
  36. DapGuiAppViewVarItemList,
  37. variable_item_list_get_view(app->var_item_list));
  38. app->main_view = dap_main_view_alloc();
  39. view_dispatcher_add_view(
  40. app->view_dispatcher, DapGuiAppViewMainView, dap_main_view_get_view(app->main_view));
  41. app->widget = widget_alloc();
  42. view_dispatcher_add_view(
  43. app->view_dispatcher, DapGuiAppViewWidget, widget_get_view(app->widget));
  44. scene_manager_next_scene(app->scene_manager, DapSceneMain);
  45. return app;
  46. }
  47. void dap_gui_free(DapGuiApp* app) {
  48. view_dispatcher_remove_view(app->view_dispatcher, DapGuiAppViewVarItemList);
  49. variable_item_list_free(app->var_item_list);
  50. view_dispatcher_remove_view(app->view_dispatcher, DapGuiAppViewMainView);
  51. dap_main_view_free(app->main_view);
  52. view_dispatcher_remove_view(app->view_dispatcher, DapGuiAppViewWidget);
  53. widget_free(app->widget);
  54. // View dispatcher
  55. view_dispatcher_free(app->view_dispatcher);
  56. scene_manager_free(app->scene_manager);
  57. // Close records
  58. furi_record_close(RECORD_GUI);
  59. furi_record_close(RECORD_NOTIFICATION);
  60. free(app);
  61. }
  62. int32_t dap_gui_thread(void* arg) {
  63. DapGuiApp* app = dap_gui_alloc();
  64. app->dap_app = arg;
  65. notification_message_block(app->notifications, &sequence_display_backlight_enforce_on);
  66. view_dispatcher_run(app->view_dispatcher);
  67. notification_message_block(app->notifications, &sequence_display_backlight_enforce_auto);
  68. dap_gui_free(app);
  69. return 0;
  70. }