dap_gui.c 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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_set_event_callback_context(app->view_dispatcher, app);
  25. view_dispatcher_set_custom_event_callback(app->view_dispatcher, dap_gui_custom_event_callback);
  26. view_dispatcher_set_navigation_event_callback(
  27. app->view_dispatcher, dap_gui_back_event_callback);
  28. view_dispatcher_set_tick_event_callback(
  29. app->view_dispatcher, dap_gui_tick_event_callback, DAP_GUI_TICK);
  30. view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
  31. app->notifications = furi_record_open(RECORD_NOTIFICATION);
  32. app->var_item_list = variable_item_list_alloc();
  33. view_dispatcher_add_view(
  34. app->view_dispatcher,
  35. DapGuiAppViewVarItemList,
  36. variable_item_list_get_view(app->var_item_list));
  37. app->main_view = dap_main_view_alloc();
  38. view_dispatcher_add_view(
  39. app->view_dispatcher, DapGuiAppViewMainView, dap_main_view_get_view(app->main_view));
  40. app->widget = widget_alloc();
  41. view_dispatcher_add_view(
  42. app->view_dispatcher, DapGuiAppViewWidget, widget_get_view(app->widget));
  43. scene_manager_next_scene(app->scene_manager, DapSceneMain);
  44. return app;
  45. }
  46. void dap_gui_free(DapGuiApp* app) {
  47. view_dispatcher_remove_view(app->view_dispatcher, DapGuiAppViewVarItemList);
  48. variable_item_list_free(app->var_item_list);
  49. view_dispatcher_remove_view(app->view_dispatcher, DapGuiAppViewMainView);
  50. dap_main_view_free(app->main_view);
  51. view_dispatcher_remove_view(app->view_dispatcher, DapGuiAppViewWidget);
  52. widget_free(app->widget);
  53. // View dispatcher
  54. view_dispatcher_free(app->view_dispatcher);
  55. scene_manager_free(app->scene_manager);
  56. // Close records
  57. furi_record_close(RECORD_GUI);
  58. furi_record_close(RECORD_NOTIFICATION);
  59. free(app);
  60. }
  61. int32_t dap_gui_thread(void* arg) {
  62. DapGuiApp* app = dap_gui_alloc();
  63. app->dap_app = arg;
  64. notification_message_block(app->notifications, &sequence_display_backlight_enforce_on);
  65. view_dispatcher_run(app->view_dispatcher);
  66. notification_message_block(app->notifications, &sequence_display_backlight_enforce_auto);
  67. dap_gui_free(app);
  68. return 0;
  69. }