1+ #include "dtmf_dolphin_i.h"
2+
3+ #include <furi.h>
4+ #include <furi_hal.h>
5+
6+ static bool dtmf_dolphin_app_custom_event_callback (void * context , uint32_t event ) {
7+ furi_assert (context );
8+ DTMFDolphinApp * app = context ;
9+ return scene_manager_handle_custom_event (app -> scene_manager , event );
10+ }
11+
12+ static bool dtmf_dolphin_app_back_event_callback (void * context ) {
13+ furi_assert (context );
14+ DTMFDolphinApp * app = context ;
15+ return scene_manager_handle_back_event (app -> scene_manager );
16+ }
17+
18+ static void dtmf_dolphin_app_tick_event_callback (void * context ) {
19+ furi_assert (context );
20+ DTMFDolphinApp * app = context ;
21+
22+ // Needed to handle queueing to ISR and prioritization of audio
23+ if (app -> player .playing ) {
24+ dtmf_dolphin_player_handle_tick ();
25+ } else {
26+ scene_manager_handle_tick_event (app -> scene_manager );
27+ }
28+ }
29+
30+ static DTMFDolphinApp * app_alloc () {
31+ DTMFDolphinApp * app = malloc (sizeof (DTMFDolphinApp ));
32+ app -> player .half_samples = 4 * 1024 ;
33+ app -> player .sample_count = 8 * 1024 ;
34+ app -> player .sample_buffer = malloc (sizeof (uint16_t ) * app -> player .sample_count );
35+ app -> player .buffer_buffer = malloc (sizeof (uint8_t ) * app -> player .sample_count );
36+ app -> player .wf1_period = 0 ;
37+ app -> player .wf2_period = 0 ;
38+ app -> player .wf1_freq = 0 ;
39+ app -> player .wf2_freq = 0 ;
40+ app -> player .wf1_pos = 0 ;
41+ app -> player .wf2_pos = 0 ;
42+ app -> player .queue = furi_message_queue_alloc (10 , sizeof (DTMFDolphinEvent ));
43+ app -> player .volume = 2.0f ;
44+ app -> player .playing = false;
45+
46+ app -> gui = furi_record_open (RECORD_GUI );
47+ app -> view_dispatcher = view_dispatcher_alloc ();
48+ app -> scene_manager = scene_manager_alloc (& dtmf_dolphin_scene_handlers , app );
49+ view_dispatcher_enable_queue (app -> view_dispatcher );
50+ view_dispatcher_set_event_callback_context (app -> view_dispatcher , app );
51+
52+ view_dispatcher_set_custom_event_callback (
53+ app -> view_dispatcher , dtmf_dolphin_app_custom_event_callback );
54+ view_dispatcher_set_navigation_event_callback (
55+ app -> view_dispatcher , dtmf_dolphin_app_back_event_callback );
56+ view_dispatcher_set_tick_event_callback (
57+ app -> view_dispatcher , dtmf_dolphin_app_tick_event_callback , 100 );
58+
59+ view_dispatcher_attach_to_gui (app -> view_dispatcher , app -> gui , ViewDispatcherTypeFullscreen );
60+
61+ app -> main_menu_list = variable_item_list_alloc ();
62+ view_dispatcher_add_view (
63+ app -> view_dispatcher ,
64+ DTMFDolphinViewMainMenu ,
65+ variable_item_list_get_view (app -> main_menu_list ));
66+
67+ app -> dtmf_dolphin_dialer = dtmf_dolphin_dialer_alloc ();
68+ view_dispatcher_add_view (
69+ app -> view_dispatcher ,
70+ DTMFDolphinViewDialer ,
71+ dtmf_dolphin_dialer_get_view (app -> dtmf_dolphin_dialer ));
72+
73+ app -> dtmf_dolphin_bluebox = dtmf_dolphin_bluebox_alloc ();
74+ view_dispatcher_add_view (
75+ app -> view_dispatcher ,
76+ DTMFDolphinViewBluebox ,
77+ dtmf_dolphin_bluebox_get_view (app -> dtmf_dolphin_bluebox ));
78+
79+ app -> dtmf_dolphin_play = widget_alloc ();
80+ view_dispatcher_add_view (
81+ app -> view_dispatcher ,
82+ DTMFDolphinViewPlay ,
83+ widget_get_view (app -> dtmf_dolphin_play ));
84+
85+ // app->dialer_button_panel = button_panel_alloc();
86+ // app->bluebox_button_panel = button_panel_alloc();
87+ // app->redbox_button_panel = button_panel_alloc();
88+
89+ app -> notification = furi_record_open (RECORD_NOTIFICATION );
90+ notification_message (app -> notification , & sequence_display_backlight_enforce_on );
91+
92+ scene_manager_next_scene (app -> scene_manager , DTMFDolphinSceneStart );
93+
94+ return app ;
95+ }
96+
97+ static void app_free (DTMFDolphinApp * app ) {
98+ furi_assert (app );
99+ view_dispatcher_remove_view (app -> view_dispatcher , DTMFDolphinViewMainMenu );
100+ view_dispatcher_remove_view (app -> view_dispatcher , DTMFDolphinViewBluebox );
101+ view_dispatcher_remove_view (app -> view_dispatcher , DTMFDolphinViewDialer );
102+ view_dispatcher_remove_view (app -> view_dispatcher , DTMFDolphinViewPlay );
103+ variable_item_list_free (app -> main_menu_list );
104+
105+ dtmf_dolphin_bluebox_free (app -> dtmf_dolphin_bluebox );
106+ dtmf_dolphin_dialer_free (app -> dtmf_dolphin_dialer );
107+ widget_free (app -> dtmf_dolphin_play );
108+
109+ view_dispatcher_free (app -> view_dispatcher );
110+ scene_manager_free (app -> scene_manager );
111+
112+ furi_message_queue_free (app -> player .queue );
113+ free (app -> player .sample_buffer );
114+
115+ // button_panel_free(app->dialer_button_panel);
116+ // button_panel_free(app->bluebox_button_panel);
117+ // button_panel_free(app->redbox_button_panel);
118+
119+ notification_message (app -> notification , & sequence_display_backlight_enforce_auto );
120+
121+ furi_record_close (RECORD_GUI );
122+ furi_record_close (RECORD_NOTIFICATION );
123+ free (app );
124+ }
125+
126+ int32_t dtmf_dolphin_app (void * p ) {
127+ UNUSED (p );
128+ DTMFDolphinApp * app = app_alloc ();
129+
130+ dtmf_dolphin_player_init (& (app -> player ));
131+
132+ view_dispatcher_run (app -> view_dispatcher );
133+
134+ app_free (app );
135+ return 0 ;
136+ }
0 commit comments