dtmf_dolphin.c 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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_set_event_callback_context(app->view_dispatcher, app);
  25. view_dispatcher_set_custom_event_callback(
  26. app->view_dispatcher, dtmf_dolphin_app_custom_event_callback);
  27. view_dispatcher_set_navigation_event_callback(
  28. app->view_dispatcher, dtmf_dolphin_app_back_event_callback);
  29. view_dispatcher_set_tick_event_callback(
  30. app->view_dispatcher, dtmf_dolphin_app_tick_event_callback, 100);
  31. view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
  32. app->main_menu_list = variable_item_list_alloc();
  33. view_dispatcher_add_view(
  34. app->view_dispatcher,
  35. DTMFDolphinViewMainMenu,
  36. variable_item_list_get_view(app->main_menu_list));
  37. app->dtmf_dolphin_dialer = dtmf_dolphin_dialer_alloc();
  38. view_dispatcher_add_view(
  39. app->view_dispatcher,
  40. DTMFDolphinViewDialer,
  41. dtmf_dolphin_dialer_get_view(app->dtmf_dolphin_dialer));
  42. app->notification = furi_record_open(RECORD_NOTIFICATION);
  43. notification_message(app->notification, &sequence_display_backlight_enforce_on);
  44. scene_manager_next_scene(app->scene_manager, DTMFDolphinSceneStart);
  45. return app;
  46. }
  47. static void app_free(DTMFDolphinApp* app) {
  48. furi_assert(app);
  49. view_dispatcher_remove_view(app->view_dispatcher, DTMFDolphinViewMainMenu);
  50. view_dispatcher_remove_view(app->view_dispatcher, DTMFDolphinViewDialer);
  51. variable_item_list_free(app->main_menu_list);
  52. dtmf_dolphin_dialer_free(app->dtmf_dolphin_dialer);
  53. view_dispatcher_free(app->view_dispatcher);
  54. scene_manager_free(app->scene_manager);
  55. notification_message(app->notification, &sequence_display_backlight_enforce_auto);
  56. furi_record_close(RECORD_GUI);
  57. furi_record_close(RECORD_NOTIFICATION);
  58. free(app);
  59. }
  60. int32_t dtmf_dolphin_app(void* p) {
  61. UNUSED(p);
  62. DTMFDolphinApp* app = app_alloc();
  63. view_dispatcher_run(app->view_dispatcher);
  64. app_free(app);
  65. return 0;
  66. }