• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Chipsea Technologies (Shenzhen) Corp., Ltd. All rights reserved.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 /*chipsea_ohos proguard begin*/
16 #include "cs_proguard.h"
17 /*chipsea_ohos proguard end*/
18 #include "cs_target_config.h"
19 #if APP_SUPPORT_AVRCP == 1
20 #include "al_rtos.h"
21 #include "app_bt.h"
22 #include "cs_adp_api.h"
23 
24 
app_set_avrcp_volume(BT_ADDR * bdaddr,S8 volume)25 void app_set_avrcp_volume(BT_ADDR *bdaddr,S8 volume)
26 {
27     APP_DEVLIST *tmp = NULL;
28     tmp = app_bt_get_mgr_devinfo(*bdaddr);
29 
30     btdev_info* dev_info = cs_adp_get_devinfo_by_addr(bdaddr);
31     if(tmp && dev_info){
32         dev_info->peer_a2dp_vol = (((int)volume&0x7f)<<4)/128;
33         if (dev_info->peer_a2dp_vol > AUD_VOLUME_LEVEL_15 - AUD_VOLUME_LEVEL_0){
34             dev_info->peer_a2dp_vol = AUD_VOLUME_LEVEL_15 - AUD_VOLUME_LEVEL_0;
35         }else if (dev_info->peer_a2dp_vol < AUD_VOLUME_LEVEL_0 - AUD_VOLUME_LEVEL_0){
36             dev_info->peer_a2dp_vol = AUD_VOLUME_LEVEL_0 - AUD_VOLUME_LEVEL_0;
37         }
38         tmp->peer_volume_a2dp = dev_info->peer_a2dp_vol;
39         TRACE("APP:app_set_avrcp_volume %d\n",(dev_info->peer_a2dp_vol));
40     }
41 }
42 
app_get_avrcp_volume(BT_ADDR * bdaddr)43 U8 app_get_avrcp_volume(BT_ADDR *bdaddr)
44 {
45     U8 volume = 0x7f;
46     btdev_info* dev_info = cs_adp_get_devinfo_by_addr(bdaddr);
47     if(dev_info){
48         if(dev_info->peer_a2dp_vol == 0){
49             volume = 0x3f;
50         }else{
51             if(dev_info->peer_a2dp_vol > (AUD_VOLUME_LEVEL_0 - AUD_VOLUME_LEVEL_0)&& dev_info->peer_a2dp_vol <= (AUD_VOLUME_LEVEL_15 - AUD_VOLUME_LEVEL_0)){
52                 volume = 8*(dev_info->peer_a2dp_vol+1) - 1;
53             }else{
54                 dev_info->peer_a2dp_vol = AUD_VOLUME_LEVEL_15 - AUD_VOLUME_LEVEL_0;
55                 volume = 8*(dev_info->peer_a2dp_vol+1) - 1;
56             }
57         }
58     }
59     TRACE("APP:app_get_avrcp_volume %d,0x%x\n",(dev_info->peer_a2dp_vol),volume);
60     return volume;
61 }
62 
app_avrcp_report_volume_to_phone(BT_ADDR bdaddr,U8 volume)63 void app_avrcp_report_volume_to_phone(BT_ADDR bdaddr,          U8 volume)
64 {
65     TRACE("APP:report local volume 0x%x\n",volume);
66     cs_adp_avrcp_send_volume_report(bdaddr,volume);
67 }
68 
app_avrcp_key_handle(uint32_t key)69 BOOL app_avrcp_key_handle(uint32_t key)
70 {
71     BOOL ret = FALSE;
72     APP_DEVLIST * a2dp_devinfo = NULL;
73 
74     a2dp_devinfo = cs_adp_get_a2dp_current_devinfo();
75     if(a2dp_devinfo == NULL){
76         TRACE("APP:a2dp_devinfo error!\n");
77         return ret;
78     }
79 
80     switch(key){
81         case APP_KEY_PLAY|APP_KEY_PRESS:
82             TRACE("APP:a2dp_state %d\n",a2dp_devinfo->a2dp_state);
83             if(a2dp_devinfo->a2dp_state == A2DP_ADP_STATE_PAUSE || a2dp_devinfo->a2dp_state == A2DP_ADP_STATE_OPEN){
84                 cs_adp_avrcp_send_key_play(a2dp_devinfo->bdaddr);
85                 ret = TRUE;
86             }else if(a2dp_devinfo->a2dp_state == A2DP_ADP_STATE_PLAY){
87                 cs_adp_avrcp_send_key_pause(a2dp_devinfo->bdaddr);
88                 ret = TRUE;
89             }else{
90                 TRACE("APP:a2dp status error!");
91             }
92             break;
93 #if 1
94         case APP_KEY_VOLADD|APP_KEY_PRESS:
95         case APP_KEY_VOLADD|APP_KEY_HOLD:
96         case APP_KEY_VOLSUB|APP_KEY_PRESS:
97         case APP_KEY_VOLSUB|APP_KEY_HOLD:
98             app_avrcp_report_volume_to_phone(a2dp_devinfo->bdaddr,app_get_avrcp_volume(&a2dp_devinfo->bdaddr));
99             ret = TRUE;
100             break;
101 #else
102         case (APP_KEY_VOLADD|APP_KEY_PRESS):
103         case (APP_KEY_VOLADD|APP_KEY_HOLD):
104             cs_adp_avrcp_send_key_volume_up(a2dp_devinfo->bdaddr);
105             ret = TRUE;
106             break;
107         case APP_KEY_VOLSUB|APP_KEY_PRESS:
108         case APP_KEY_VOLSUB|APP_KEY_HOLD:
109             cs_adp_avrcp_send_key_volume_down(a2dp_devinfo->bdaddr);
110             ret = TRUE;
111             break;
112 #endif
113         case APP_KEY_NEXT|APP_KEY_PRESS:
114             cs_adp_avrcp_send_key_forward(a2dp_devinfo->bdaddr);
115             ret = TRUE;
116             break;
117         case APP_KEY_PREV|APP_KEY_PRESS:
118             cs_adp_avrcp_send_key_backward(a2dp_devinfo->bdaddr);
119             ret = TRUE;
120             break;
121         case APP_KEY_NEXT|APP_KEY_HOLD:
122             //reserved
123             break;
124         case APP_KEY_PREV|APP_KEY_HOLD:
125             //reserved
126             break;
127         case APP_KEY_NEXT|APP_KEY_UP:
128             //reserved
129             break;
130         case APP_KEY_PREV|APP_KEY_UP:
131             //reserved
132             break;
133         default:
134             break;
135     }
136     return ret;
137 }
138 
app_avrcp_msg_handle(CS_EVENT * event)139 void app_avrcp_msg_handle(CS_EVENT *event)
140 {
141     CS_ADP_AVRCP_EVENT *cs_avrcp_msg = (CS_ADP_AVRCP_EVENT *)event->Param;
142     switch(event->EventId)
143     {
144         case CS_ADP_AVRCP_CONNECT:
145             {
146                 BOOL support = false;
147                 TRACE("APP:app_avrcp_connect!\n");
148 #if APP_SUPPORT_IPHONE_VOLUME_SYNC == 1
149                 support = true;
150 #endif
151                 cs_adp_avrcp_support_volume_sync(support);
152             }
153             break;
154         case CS_ADP_AVRCP_DISCONNECT:
155             TRACE("APP:app_avrcp_disconnect\n");
156             break;
157 
158         case CS_ADP_AVRCP_PANEL_PRESS:
159             {
160                 bt_avrcpPanelOp op = (bt_avrcpPanelOp)cs_avrcp_msg->avrcpparam;
161                 TRACE("APP:TG panel press op = %x\n", op);
162 
163                 switch(op)
164                 {
165                     case APP_AVRCP_PANEL_VOLUME_UP:
166                         TRACE("APP:avrcp_key_volume_up\n");
167                         break;
168                     case APP_AVRCP_PANEL_VOLUME_DOWN:
169                         TRACE("APP: avrcp_key_volume_down\n");
170                         break;
171                     case APP_AVRCP_PANEL_PLAY:
172                         TRACE("APP:avrcp start stream \n");
173                         //cs_adp_a2dp_source_start();
174                         break;
175                     case APP_AVRCP_PANEL_PAUSE:
176                         TRACE("APP:acrcp stop stream \n");
177                         //cs_adp_a2dp_source_suspend();
178                         break;
179                     default :
180                         break;
181                 }
182             }
183             break;
184 
185         case CS_ADP_AVRCP_ADV_VOLUME_CHANGE:
186             TRACE("APP:avrcp_volume_change vol =%d \n",cs_avrcp_msg->avrcpparam);
187             app_set_avrcp_volume(&cs_avrcp_msg->bdaddr,(U8)cs_avrcp_msg->avrcpparam);
188 #if APP_SUPPORT_TWS == 0
189             app_bt_local_volume_handle(0,app_get_avrcp_volume(&cs_avrcp_msg->bdaddr));
190 #endif
191             break;
192         case CS_ADP_AVRCP_ADV_PLAYSTAUTS_CHANGE:
193             TRACE("APP:avrcp_play_status states=%x \n",(uint8_t)cs_avrcp_msg->avrcpparam);
194             break;
195         default:
196             break;
197     }
198 }
199 #endif
200