comparison src/ui3/bmi/mmiBtipsA2dp.c @ 420:e8ddbb0837ed

src/ui3: initial import of TCS3/LoCosto BMI & MFW code
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 21 Jan 2018 03:09:00 +0000
parents
children
comparison
equal deleted inserted replaced
419:59143cd42ec7 420:e8ddbb0837ed
1 /* =========================================================
2 * Texas Instruments OMAP(TM) Platform Software
3 * (c) Copyright Texas Instruments, Incorporated. All Rights Reserved.
4 *
5 * Use of this software is controlled by the terms and conditions found
6 * in the license agreement under which this software has been supplied.
7 * ========================================================== */
8 /*
9 $Project name: Basic Bluetooth MMI
10 $Project code:
11 $Module: Bluetooth BMG APPlication
12 $File: MmiBtipsA2dp.c
13 $Revision: 1.0
14 $Author: Texas Instruments
15 $Date: 26/06/07
16
17 ********************************************************************************
18
19 Description:
20
21 This module provides the BTIPS BMG APPlication functionality.
22
23 ********************************************************************************
24 $History: MmiBtipsA2dp.c
25
26 26/06/07 Sasken original version
27
28 $End
29
30 *******************************************************************************/
31
32
33
34
35 /*******************************************************************************
36
37 Include files
38
39 *******************************************************************************/
40
41 #define ENTITY_MFW
42
43 #include <string.h>
44
45 /* BTIPS Includes */
46 #include "me.h"
47
48
49 #if defined (NEW_FRAME)
50
51 #include "typedefs.h"
52 #include "vsi.h"
53 #include "pei.h"
54 #include "custom.h"
55 #include "gsm.h"
56 #include "prim.h"
57
58 #else
59
60 #include "STDDEFS.H"
61 #include "custom.h"
62 #include "gsm.h"
63 #include "vsi.h"
64
65 #endif
66
67 #include "mfw_mfw.h"
68 #include "mfw_win.h"
69 #include "mfw_icn.h" /* included for mfw_mnu.h */
70 #include "mfw_mnu.h"
71 #include "mfw_tim.h"
72 #include "mfw_kbd.h"
73 #include "mfw_sat.h" /* included for MmiDummy.h, included for MmiMenu.h */
74 #include "MmiBlkLangDB.h"
75 #include "mmiColours.h"
76 #include "MmiDialogs.h"
77 #include "MmiDummy.h" /* included for MmiMenu.h */
78 #include "MmiLists.h"
79 #include "MmiMenu.h"
80 #include "MmiSoftKeys.h"
81 #include "AUIEditor.h"
82 #include "MmiMain.h"
83 #include "Mmiicons.h"
84 #include "MmiWindow.h"
85 #include "MmiCall.h"
86 #include "mmiBookShared.h"
87
88 #include "mmiBtips.h"
89 #include "mfw_btips.h"
90 #include "mfw_BtipsA2dp.h"
91 #include "mmiBtipsA2dp.h"
92 #include "mfw_BtipsBmg.h"
93 #include "mmiBtipsBmg.h"
94 #include "btl_a2dp.h"
95
96
97 int a2dp_files_count;
98 extern BtlA2dpStreamId streamId;
99 //Array to load fileNames in content directory
100 char* a2dp_file_names[A2DP_MAX_FILES];
101 char* szSelectedFileExt;
102 char szSelectedFileName[256];
103 #define A2DP_INFO_SCRN_TIMEOUT 1500//Timeout for InfoDialog
104 T_MFW_HND hA2dpDeviceWnd;
105
106 #define A2DP_BMG_DEVICES_EXIT_WIN 5
107
108
109 #ifdef FF_MMI_BTIPS_APP
110
111 static T_MFW_HND mmi_btips_a2dpBuildMenu( MfwHnd parent_window);
112 static int mmi_btips_a2dpWinCb (MfwEvt e, MfwWin *w) ;
113
114 static void mmi_btips_a2dpListMenuCb(T_MFW_HND Parent, ListMenuData * ListData);
115 static void mmi_btips_a2dpListMenuDestroy(MfwHnd window);
116 static MfwHnd mmi_btips_a2dpShowInfoDlg(T_MFW_HND parent, int str1, int str2,
117 T_VOID_FUNC callback);
118
119 int mmi_btips_a2dpHandler(MfwMnu* m, MfwMnuItem* i)
120 {
121 T_MFW_HND win;
122 T_MFW_HND parent_win = mfw_parent(mfw_header());
123 int numFiles=0;
124
125 TRACE_FUNCTION ("mmi_btips_a2dpHandler");
126 //mfw_btips_a2dpInit();
127 a2dp_files_count = A2DP_MAX_FILES;
128 a2dp_files_count=mfw_btips_a2dpPopulateFiles(a2dp_file_names,A2DP_MAX_FILES,
129 BT_DEMO_FOLDER_PATH);
130 TRACE_FUNCTION_P1("mmi_btips_a2dpHandler: a2dp_files_count - %d", a2dp_files_count);
131 numFiles = mfw_btips_a2dpGetNumFiles();
132
133 TRACE_FUNCTION_P1("mmi_btips_a2dpHandler FileCount = %d",numFiles);
134
135 if(numFiles <= 0)
136 {
137 mmi_btips_a2dpShowInfoDlg(0, TxtMidiFileNotLoaded, TxtNull, NULL);
138
139 }
140 else
141 {
142 win = mmi_btips_a2dpBuildMenu(parent_win);
143 if (win NEQ NULL)
144 {
145 SEND_EVENT (win, BTIPS_A2DP_LIST_INIT, 0, 0);
146 }
147
148 }
149 return MFW_EVENT_CONSUMED;
150
151 }
152
153 /*******************************************************************************
154
155 $Function: mmi_btips_a2dpBuildMenu
156
157 $Description: To hold list window
158
159 $Returns: Window handle
160
161 $Arguments:
162 *******************************************************************************/
163
164 static T_MFW_HND mmi_btips_a2dpBuildMenu( MfwHnd parent_window)
165 {
166 T_MMI_Btips_A2dp_Win_data * data = (T_MMI_Btips_A2dp_Win_data *)mfwAlloc(sizeof (T_MMI_Btips_A2dp_Win_data));
167 T_MFW_WIN * win;
168
169 TRACE_FUNCTION ("mmi_btips_a2dpBuildMenu");
170
171 /*
172 * Create window handler
173 */
174
175 data->win = win_create (parent_window, 0, E_WIN_VISIBLE, (T_MFW_CB)mmi_btips_a2dpWinCb);
176 if (data->win EQ NULL)
177 {
178 return NULL;
179 }
180
181 TRACE_EVENT("list holder window created: " );
182 /*
183 * connect the dialog data to the MFW-window
184 */
185
186 data->mmi_control.dialog = (T_DIALOG_FUNC)mmi_btips_a2dpExecCb;
187 data->mmi_control.data = data;
188 win = ((T_MFW_HDR *)data->win)->data;
189 win->user = (void *)data;
190 data->parent = parent_window;
191 winShow(data->win);
192 /*
193 * return window handle
194 */
195
196 return data->win;
197 }
198
199
200 // Description: MIDI Player: Back Key malfunctions in MIDI application.
201 // Solution: A window is created to hold list window. When the user presses Back key, the newly
202 // created window is deleted along with list window, bringing the control back to Midi options
203 // screen.
204 /*******************************************************************************
205
206 $Function: mmi_btips_a2dpWinCb
207
208 $Description: Window event handler
209
210 $Returns: MFW_EVENT_REJECTED:
211 MFW_EVENT_CONSUMED:
212
213 $Arguments:
214
215 *******************************************************************************/
216 static int mmi_btips_a2dpWinCb(MfwEvt e, MfwWin *win)
217 {
218 T_MMI_Btips_A2dp_Win_data *data = (T_MMI_Btips_A2dp_Win_data *)win->user;
219
220 TRACE_FUNCTION ("mmi_btips_a2dpWinCb()");
221 switch (e)
222 {
223 case MfwWinFocussed: /* input focus / selected */
224 TRACE_EVENT("MfwWinFocussed");
225 case MfwWinDelete: /* window will be deleted */
226 TRACE_EVENT("MfwWinDelete");
227 case MfwWinVisible: /* window is visible */
228 TRACE_EVENT("MfwWinVisible");
229 break;
230 case MfwWinSuspend: /* window is suspended */
231 TRACE_EVENT("MfwWinSuspend");
232 break;
233 case MfwWinResume: /* window is resumed */
234 TRACE_EVENT("MfwWinResume");
235 default:
236 return MFW_EVENT_REJECTED;
237 }
238 return MFW_EVENT_CONSUMED;
239 }
240
241 // Description: MIDI Player: Back Key malfunctions in MIDI application.
242 // Solution: A window is created to hold list window. When the user presses Back key, the newly
243 // created window is deleted along with list window, bringing the control back to Midi options
244 // screen.
245 /*******************************************************************************
246
247 $Function: mmi_btips_a2dpExecCb
248
249 $Description: Call back function
250
251 $Returns: none
252
253 $Arguments:
254
255 *******************************************************************************/
256 void mmi_btips_a2dpExecCb (T_MFW_HND win, USHORT event, SHORT value, void * parameter)
257 {
258 T_MFW_WIN * win_data = ((T_MFW_HDR *) win)->data;
259 T_MMI_Btips_A2dp_Win_data * data = (T_MMI_Btips_A2dp_Win_data *)win_data->user;
260 int max_file_number;
261 int i;
262
263 ListWinInfo * mnu_data = (ListWinInfo *)parameter;
264
265 TRACE_FUNCTION ("mmi_btips_a2dpExecCb()");
266 switch (event)
267 {
268 T_MFW A2dpListCreationStatus;
269 case BTIPS_A2DP_LIST_INIT:
270 {
271
272 TRACE_EVENT(" midi_test_files_exec_cb() Event:E_INIT");
273
274 /* initialization of administrative data */
275
276 data->menu_list_data = (ListMenuData *)ALLOC_MEMORY(sizeof(ListMenuData));
277
278 if(data->menu_list_data == 0)
279 {
280 TRACE_EVENT("Failed memory alloc 1 ");
281 return;
282 }
283
284 max_file_number = mfw_btips_a2dpGetNumFiles();
285 //In case no files have been loaded display info message
286 //In case no files have been loaded return info message
287 if(max_file_number == 0)
288 {
289 return;
290 }
291
292
293 data->menu_list_data->List = (T_MFW_MNU_ITEM *)ALLOC_MEMORY( max_file_number * sizeof(T_MFW_MNU_ITEM) );
294
295 if(data->menu_list_data->List == 0)
296 {
297 TRACE_EVENT("Failed memory alloc 2");
298 return;
299 }
300 for (i = 0; i < max_file_number ; i++)
301 {
302 mnuInitDataItem(&data->menu_list_data->List[i]);
303 data->menu_list_data->List[i].flagFunc = item_flag_none;
304 //Display the A2DP file names in the list
305 data->menu_list_data->List[i].str =
306 (char *)mfw_btips_a2dpGetFileName(data->a2dp_file_count++);
307 }
308
309 data->menu_list_data->ListLength =max_file_number;
310 data->menu_list_data->ListPosition = 1;
311 data->menu_list_data->CursorPosition = 1;
312 data->menu_list_data->SnapshotSize = max_file_number;
313 data->menu_list_data->Font = 0;
314 data->menu_list_data->LeftSoftKey = TxtSoftSelect;
315 data->menu_list_data->RightSoftKey = TxtSoftBack;
316 data->menu_list_data->KeyEvents = KEY_ALL;
317 data->menu_list_data->Reason = 0;
318 data->menu_list_data->Strings = TRUE;
319 data->menu_list_data->Attr = (MfwMnuAttr*)&BtipsA2dpList_Attrib;
320 data->menu_list_data->Attr->hdrId = TxtPlayerSelectFile;
321 data->menu_list_data->autoDestroy = FALSE;
322 A2dpListCreationStatus =
323 listDisplayListMenu (win, data->menu_list_data,
324 (ListCbFunc)mmi_btips_a2dpListMenuCb,0);
325 if (LISTS_OK == A2dpListCreationStatus)
326 {
327 #if 0
328 /*If control reached this point then List of files are showed on display*/
329 isMidiListON = TRUE;
330 /*Create one timer and play the file only if that timer expires*/
331 /*Play the first file if user hasn't pressed the up and down for half a second */
332 mfw_player_currently_playing_idx = 0;
333 midiBrowseTimer = timCreate( 0, TIME_HALFSECOND, (MfwCb)midi_test_play_browsing);
334 timStart( midiBrowseTimer );
335 #endif
336 }
337 }
338 break;
339 default:
340 break;
341 }
342
343 }
344 /*******************************************************************************
345
346 $Function: midi_mt_menu_list_listmnu_cb
347
348 $Description: destroy lists and menu in case of back softkey or menu exit
349
350 $Returns:
351
352 $Arguments:
353
354 *******************************************************************************/
355 static void mmi_btips_a2dpListMenuCb(T_MFW_HND Parent, ListMenuData * ListData)
356 {
357 T_MFW_WIN *win_data = ((T_MFW_HDR *)Parent)->data;
358 T_MMI_Btips_A2dp_Win_data *data = (T_MMI_Btips_A2dp_Win_data *)win_data->user;
359
360 TRACE_FUNCTION ("mmi_btips_a2dpListMenuCb()");
361
362 if ((ListData->Reason EQ LISTS_REASON_BACK) ||
363 (ListData->Reason EQ LISTS_REASON_CLEAR) ||
364 (ListData->Reason EQ LISTS_REASON_HANGUP))
365 {
366 mfw_btips_a2dpCloseStream();
367 /*
368 ** Destroy the window --- Not sure if this is required! ... leave it out for now
369 */
370 listsDestroy(ListData->win);
371
372 /*
373 ** Free the memory set aside for ALL the devices to be listed.
374 */
375 if (data->menu_list_data != NULL)
376 {
377 FREE_MEMORY ((void *)data->menu_list_data->List, (U16)(data->a2dp_num_file * sizeof (T_MFW_MNU_ITEM)));
378 FREE_MEMORY ((void *)data->menu_list_data, sizeof (ListMenuData));
379 }
380
381 mmi_btips_a2dpListMenuDestroy(data->win);
382 #if 0
383 // June 19, 2006 REF: DRT OMAPS00076378 x0012849
384 /*At this point the MIDI list is destroyed*/
385 isMidiListON = FALSE;
386 /* At this point the play need to be stopped. If user wants the file need to
387 be played while going across menu then 'play' or 'play all' need to be selected */
388 midi_stop_player (NULL, NULL);
389 if (midiBrowseTimer != NULL)
390 {
391 // Delete the timer. It's not required any more.
392 timDelete (midiBrowseTimer);
393 }
394 #endif
395 }
396 else if(ListData->Reason EQ LISTS_REASON_SELECT)
397 {
398 OS_MemSet(szSelectedFileName, 0, sizeof(szSelectedFileName));
399 OS_StrCpy(szSelectedFileName, BT_DEMO_FOLDER_PATH);
400 OS_StrCat(szSelectedFileName, "/");
401 OS_StrCat(szSelectedFileName, mfw_btips_a2dpGetFileName(ListData->CursorPosition));
402 TRACE_EVENT_P1("szSelectedFileName: %s", szSelectedFileName);
403 //szSelectedFileName = mfw_btips_a2dpGetFileName(ListData->CursorPosition);
404
405 //OS_StrCpy(szSelectedFileName, "/MfwBtDemo/base_fadeout.wav");
406 szSelectedFileExt = mfw_btips_a2dpGetExtension(szSelectedFileName);
407 if(streamId >= 0)
408 {
409 TRACE_EVENT("Closing stream in mmi_btips_a2dpListMenuCb After selecting new file");
410 mfw_btips_a2dpCloseStream();
411 }
412 if(FALSE == data->deviceSearchStarted)
413 {
414
415 data->deviceSearchStarted = TRUE;
416 if ( (strcmp(szSelectedFileExt, "mp3") == 0))
417 {
418
419 mmi_btips_a2dpDeviceSearchWnd();
420 }
421 else if ( (strcmp(szSelectedFileExt, "pcm") == 0))
422 {
423
424 mmi_btips_a2dpDeviceSearchWnd();
425 }
426 else if ( (strcmp(szSelectedFileExt, "wav") == 0))
427 {
428
429 mmi_btips_a2dpDeviceSearchWnd();
430 }
431 else
432 {
433 //It should never come here
434 TRACE_ERROR("invalid file name");
435 }
436 }
437 #if 0
438 TRACE_EVENT_P1("list position is %d",ListData->ListPosition);
439 mt_menu_data.mt_list_idx = ListData->ListPosition;
440 //call mfw to save selected index
441 mfw_player_save_selected_file_idx(mt_menu_data.mt_list_idx);
442 //display a "file selected" text here
443 mmi_midi_test_show_info(0, TxtMidiFileSelected, TxtNull, NULL);
444 #endif
445 }
446
447
448 return;
449 }
450 /*******************************************************************************
451
452 $Function: mmi_btips_a2dpListMenuDestroy
453
454 $Description: destroy menu window
455
456 $Returns:
457
458 $Arguments: window to be destroyed
459
460 *******************************************************************************/
461 static void mmi_btips_a2dpListMenuDestroy(MfwHnd window)
462 {
463 T_MFW_WIN * win_data = ((T_MFW_HDR *)window)->data;
464 T_MMI_Btips_A2dp_Win_data * data = (T_MMI_Btips_A2dp_Win_data *)win_data->user;
465
466 TRACE_FUNCTION ("mmi_btips_a2dpListMenuDestroy");
467
468 if (window == NULL)
469 {
470 return;
471 }
472
473 if (data)
474 {
475 win_delete(data->win);
476
477 /*
478 ** Free Memory
479 */
480 mfwFree((void *)data, sizeof (T_MMI_Btips_A2dp_Win_data));
481 }
482 }
483 /*******************************************************************************
484
485 $Function: mmi_btips_a2dpShowInfoDlg
486
487 $Description: Display the Dialog
488
489 $Returns:
490
491 $Arguments:
492
493 *******************************************************************************/
494 static MfwHnd mmi_btips_a2dpShowInfoDlg(T_MFW_HND parent, int str1, int str2, T_VOID_FUNC callback)
495 {
496 T_DISPLAY_DATA display_info;
497
498 TRACE_FUNCTION ("mmi_btips_a2dpShowInfoDlg()");
499
500 /*
501 ** Create a timed dialog to display the Message "Failed"
502 */
503 dlg_initDisplayData_TextId( &display_info, TxtNull, TxtNull, str1, str2, COLOUR_STATUS);
504 dlg_initDisplayData_events( &display_info, callback, A2DP_INFO_SCRN_TIMEOUT, KEY_LEFT | KEY_CLEAR | KEY_HUP);
505
506 return info_dialog(parent, &display_info);
507 }
508 /*******************************************************************************
509
510 $Function: mmi_btips_a2dpPlayOnSingleDevice
511
512 $Description:
513
514 $Returns:
515
516 $Arguments:
517
518 *******************************************************************************/
519 int mmi_btips_a2dpPlayOnSingleDevice(MfwMnu* m, MfwMnuItem* i)
520 {
521 T_MFW_HND parent_win = mfwParent(mfw_header());
522 TRACE_FUNCTION("mmi_btips_a2dpPlayOnSingleDevice");
523 mfw_btips_bmgSearch(BTIPS_A2DP_DEVICE_SEARCH);
524 return MFW_EVENT_CONSUMED;
525 }
526 /*******************************************************************************
527
528 $Function: mmi_btips_a2dpPlayOnMultipleDevice
529
530 $Description:
531
532 $Returns:
533
534 $Arguments:
535
536 *******************************************************************************/
537 int mmi_btips_a2dpPlayOnMultipleDevice(MfwMnu* m, MfwMnuItem* i)
538 {
539 T_MFW_HND parent_win = mfwParent(mfw_header());
540 //mmi_btips_app_show_info(parent_win,TxtBtipsShowPhone,TxtSelected,ONE_SECS,NULL);
541 //mfw_BtipsBmgSetPhoneVisibility(True);
542 return MFW_EVENT_CONSUMED;
543 }
544
545 int mmi_btips_a2dpDeviceSearchWnd()
546 {
547 T_MFW_HND parent_win = mfwParent(mfw_header());
548 hA2dpDeviceWnd = (T_MFW_HND)mmi_btips_bmg_devices_win_create(parent_win, BTIPS_A2DP_DEVICE_SEARCH, mmi_btips_a2dpDeviceSearchCallback);
549 return MFW_EVENT_CONSUMED;
550 }
551
552 T_MFW_HND mmi_btips_a2dp_ask_cancelStreaming(T_MFW_HND parent, char * str1, char * str2, T_VOID_FUNC callback)
553 {
554 T_DISPLAY_DATA display_info;
555
556 TRACE_FUNCTION("mmi_btips_a2dp_ask_cancelStreaming");
557 dlg_initDisplayData_TextStr( &display_info, TxtNull, TxtStop, str1, str2, COLOUR_STATUS);
558 dlg_initDisplayData_events( &display_info, callback, FOREVER, KEY_LEFT|KEY_RIGHT | KEY_CLEAR | KEY_HUP);
559 return info_dialog(parent,&display_info);
560 }
561
562 void mmi_btips_a2dp_streaming_stop_cb(T_MFW_HND win, UBYTE identifier, UBYTE reason)
563 {
564
565 T_MFW_WIN * win_data = ((T_MFW_HDR *) win)->data;
566 T_dialog_info * data = (T_dialog_info *)win_data->user;
567
568 T_MFW_WIN *parent_win_data = ((T_MFW_HDR *) data->parent_win)->data;
569 /* T_MMI_Btips_Bmg_DevicesWin_data * parent_data = (T_MMI_Btips_Bmg_DevicesWin_data *)parent_win_data->user;
570 T_MFW_HND parent_win = parent_data->win;
571 */
572 TRACE_FUNCTION_P1("mmi_btips_a2dp_streaming_stop_cb %d", reason);
573
574 switch (reason)
575 {
576 case INFO_KCD_LEFT:
577 TRACE_ERROR("No LSK");
578 break;
579 case INFO_KCD_HUP:
580 case INFO_KCD_RIGHT:
581 mfw_btips_a2dpCloseStream();
582 break;
583 case INFO_KCD_CLEAR:
584 break;
585 default:
586 break;
587 }
588 }
589
590
591
592 int mmi_btips_a2dpDeviceSearchCallback(BD_ADDR bdAddr)
593 {
594 T_MFW_HND parent_win = mfwParent(mfw_header());
595
596 BtStatus status;
597 static char szDevName[128];
598 SEND_EVENT ( hA2dpDeviceWnd, BTIPS_BMG_DEVICES_EXIT_WIN, 0, (void *)NULL);
599 vsi_t_sleep(0, 10);
600 mfw_btips_bmgGetDeviceName(&bdAddr, szDevName);
601 TRACE_EVENT_P1("mmi_btips_a2dpDeviceSearchCallback with Dev Name %s", szDevName);
602
603 /*Now update the state machine so that when user comes back to this menu
604 He should be able to STOP playing A2DP OR Select another file to Play*/
605 // mmi_btips_a2dp_ask_cancelStreaming(NULL, "Streaming Audio to", szDevName, mmi_btips_a2dp_streaming_stop_cb);
606 status = mfw_btips_a2dpConnectStream(bdAddr);
607 return status;
608 }
609 #endif
610