dtmf_dolphin.c 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #include "dtmf_dolphin_i.h"
  2. #include <furi.h>
  3. #include <furi_hal.h>
  4. static bool dtmf_dolphin_app_custom_event_callback(void* context, uint32_t event) {
  5. furi_assert(context);
  6. DTMFDolphinApp* app = context;
  7. return scene_manager_handle_custom_event(app->scene_manager, event);
  8. }
  9. static bool dtmf_dolphin_app_back_event_callback(void* context) {
  10. furi_assert(context);
  11. DTMFDolphinApp* app = context;
  12. return scene_manager_handle_back_event(app->scene_manager);
  13. }
  14. static void dtmf_dolphin_app_tick_event_callback(void* context) {
  15. furi_assert(context);
  16. DTMFDolphinApp* app = context;
  17. scene_manager_handle_tick_event(app->scene_manager);
  18. }
  19. static DTMFDolphinApp* app_alloc() {
  20. DTMFDolphinApp* app = malloc(sizeof(DTMFDolphinApp));
  21. app->gui = furi_record_open(RECORD_GUI);
  22. app->view_dispatcher = view_dispatcher_alloc();
  23. app->scene_manager = scene_manager_alloc(&dtmf_dolphin_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(
  27. app->view_dispatcher, dtmf_dolphin_app_custom_event_callback);
  28. view_dispatcher_set_navigation_event_callback(
  29. app->view_dispatcher, dtmf_dolphin_app_back_event_callback);
  30. view_dispatcher_set_tick_event_callback(
  31. app->view_dispatcher, dtmf_dolphin_app_tick_event_callback, 100);
  32. view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
  33. app->main_menu_list = variable_item_list_alloc();
  34. view_dispatcher_add_view(
  35. app->view_dispatcher,
  36. DTMFDolphinViewMainMenu,
  37. variable_item_list_get_view(app->main_menu_list));
  38. app->dtmf_dolphin_dialer = dtmf_dolphin_dialer_alloc();
  39. view_dispatcher_add_view(
  40. app->view_dispatcher,
  41. DTMFDolphinViewDialer,
  42. dtmf_dolphin_dialer_get_view(app->dtmf_dolphin_dialer));
  43. app->notification = furi_record_open(RECORD_NOTIFICATION);
  44. notification_message(app->notification, &sequence_display_backlight_enforce_on);
  45. scene_manager_next_scene(app->scene_manager, DTMFDolphinSceneStart);
  46. return app;
  47. }
  48. static void app_free(DTMFDolphinApp* app) {
  49. furi_assert(app);
  50. view_dispatcher_remove_view(app->view_dispatcher, DTMFDolphinViewMainMenu);
  51. view_dispatcher_remove_view(app->view_dispatcher, DTMFDolphinViewDialer);
  52. variable_item_list_free(app->main_menu_list);
  53. dtmf_dolphin_dialer_free(app->dtmf_dolphin_dialer);
  54. // widget_free(app->dtmf_dolphin_play);
  55. view_dispatcher_free(app->view_dispatcher);
  56. scene_manager_free(app->scene_manager);
  57. // button_panel_free(app->dialer_button_panel);
  58. // button_panel_free(app->bluebox_button_panel);
  59. // button_panel_free(app->redbox_button_panel);
  60. notification_message(app->notification, &sequence_display_backlight_enforce_auto);
  61. furi_record_close(RECORD_GUI);
  62. furi_record_close(RECORD_NOTIFICATION);
  63. free(app);
  64. }
  65. int32_t dtmf_dolphin_app(void *p) {
  66. UNUSED(p);
  67. DTMFDolphinApp* app = app_alloc();
  68. view_dispatcher_run(app->view_dispatcher);
  69. app_free(app);
  70. return 0;
  71. }