-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathkey_handler.cpp
More file actions
270 lines (240 loc) · 6.78 KB
/
Copy pathkey_handler.cpp
File metadata and controls
270 lines (240 loc) · 6.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#include "a2dp_api.h"
#include "app_audio.h"
#include "app_battery.h"
#include "app_ble_include.h"
#include "app_bt.h"
#include "app_bt_func.h"
#include "app_bt_media_manager.h"
#include "app_key.h"
#include "app_overlay.h"
#include "app_pwl.h"
#include "app_status_ind.h"
#include "app_thread.h"
#include "app_tws_ibrt_cmd_handler.h"
#include "app_utils.h"
#include "apps.h"
#include "audio_process.h"
#include "audioflinger.h"
#include "besbt.h"
#include "bt_drv_interface.h"
#include "bt_if.h"
#include "btapp.h"
#include "cmsis_os.h"
#include "crash_dump_section.h"
#include "factory_section.h"
#include "gapm_task.h"
#include "hal_bootmode.h"
#include "hal_i2c.h"
#include "hal_sleep.h"
#include "hal_timer.h"
#include "hal_trace.h"
#include "list.h"
#include "log_section.h"
#include "me_api.h"
#include "norflash_api.h"
#include "nvrecord.h"
#include "nvrecord_dev.h"
#include "nvrecord_env.h"
#include "os_api.h"
#include "pmu.h"
#include "stdio.h"
#include "string.h"
#include "tgt_hardware.h"
#ifdef __INTERCONNECTION__
#include "app_ble_mode_switch.h"
#include "app_interconnection.h"
#include "app_interconnection_ble.h"
#include "app_interconnection_logic_protocol.h"
#endif
#include "app_ibrt_customif_cmd.h"
#include "app_ibrt_customif_ui.h"
#include "app_ibrt_if.h"
#include "app_ibrt_ui_test.h"
#include "app_ibrt_voice_report.h"
#include "app_tws_if.h"
#include "app_anc.h"
extern struct BT_DEVICE_T app_bt_device;
/*
* handling of touch events when the devices are turned on
* Both pods active:
* Right Ear:
* Single tap : Play/Pause
* Double tap : Next track
* Hold : ANC on/off
* Triple tap : Volume Up
*
* Left Ear:
* Single tap : Play/Pause
* Double tap : Previous track
* Hold : ANC on/off
* Triple tap : Volume Down
* Single pod active:
* Single tap : Play/Pause
* Double tap : Next track
* Hold : Previous track
* Triple tap : Volume Up
* Quad tap : Volume Down
* We use app_ibrt_if_start_user_action for handling actions, as this will apply
locally if we are link master
* OR send it over the link to the other bud if we are not
*/
void send_vol_up(void) {
uint8_t action[] = {IBRT_ACTION_LOCAL_VOLUP};
app_ibrt_if_start_user_action(action, sizeof(action));
}
void send_play_pause(void) {
if (app_bt_device.a2dp_play_pause_flag != 0) {
uint8_t action[] = {IBRT_ACTION_PAUSE};
app_ibrt_if_start_user_action(action, sizeof(action));
} else {
uint8_t action[] = {IBRT_ACTION_PLAY};
app_ibrt_if_start_user_action(action, sizeof(action));
}
}
void send_vol_down(void) {
uint8_t action[] = {IBRT_ACTION_LOCAL_VOLDN};
app_ibrt_if_start_user_action(action, sizeof(action));
}
void send_next_track(void) {
uint8_t action[] = {IBRT_ACTION_FORWARD};
app_ibrt_if_start_user_action(action, sizeof(action));
}
void send_prev_track(void) {
uint8_t action[] = {IBRT_ACTION_BACKWARD};
app_ibrt_if_start_user_action(action, sizeof(action));
}
void send_enable_disable_anc(void) {
uint8_t action[] = {IBRT_ACTION_ANC_NOTIRY_MASTER_EXCHANGE_COEF};
app_ibrt_if_start_user_action(action, sizeof(action));
}
void app_key_single_tap(APP_KEY_STATUS *status, void *param) {
TRACE(2, "%s event %d", __func__, status->event);
/*
if (!app_tws_ibrt_tws_link_connected()) {
// No other bud paired
TRACE(0, "Handling %s in single bud mode", __func__);
send_play_pause();
} else {
// Bud's are working as a pair
if (app_tws_is_left_side()) {
TRACE(0, "Handling %s as left bud", __func__);
// Lefty
send_play_pause();
} else {
TRACE(0, "Handling %s as right bud", __func__);
// Righty
send_play_pause();
}
}
*/
send_play_pause();
}
void app_key_double_tap(APP_KEY_STATUS *status, void *param) {
TRACE(2, "%s event %d", __func__, status->event);
if (!app_tws_ibrt_tws_link_connected()) {
// No other bud paired
TRACE(0, "Handling %s in single bud mode", __func__);
send_next_track();
} else {
// Bud's are working as a pair
if (app_tws_is_left_side()) {
TRACE(0, "Handling %s as left bud", __func__);
// Lefty
send_prev_track();
} else {
TRACE(0, "Handling %s as right bud", __func__);
// Righty
send_next_track();
}
}
}
void app_key_triple_tap(APP_KEY_STATUS *status, void *param) {
TRACE(2, "%s event %d", __func__, status->event);
if (!app_tws_ibrt_tws_link_connected()) {
// No other bud paired
TRACE(0, "Handling %s in single bud mode", __func__);
send_vol_up();
} else {
// Bud's are working as a pair
if (app_tws_is_left_side()) {
TRACE(0, "Handling %s as left bud", __func__);
// Lefty
send_vol_down();
} else {
TRACE(0, "Handling %s as right bud", __func__);
// Righty
send_vol_up();
}
}
}
void app_key_quad_tap(APP_KEY_STATUS *status, void *param) {
TRACE(2, "%s event %d", __func__, status->event);
if (!app_tws_ibrt_tws_link_connected()) {
// No other bud paired
TRACE(0, "Handling %s in single bud mode", __func__);
send_vol_down();
}
}
void app_key_long_press_down(APP_KEY_STATUS *status, void *param) {
TRACE(2, "%s event %d", __func__, status->event);
if (!app_tws_ibrt_tws_link_connected()) {
// No other bud paired
TRACE(0, "Handling %s in single bud mode", __func__);
send_prev_track();
} else {
// Bud's are working as a pair
send_enable_disable_anc();
}
}
void app_key_reboot(APP_KEY_STATUS *status, void *param) {
TRACE(1, "%s ", __func__);
hal_cmu_sys_reboot();
}
void app_key_init(void) {
uint8_t i = 0;
TRACE(1, "%s", __func__);
const APP_KEY_HANDLE key_cfg[] = {
{{APP_KEY_CODE_PWR, APP_KEY_EVENT_CLICK}, "", app_key_single_tap, NULL},
{{APP_KEY_CODE_PWR, APP_KEY_EVENT_DOUBLECLICK},
"",
app_key_double_tap,
NULL},
{{APP_KEY_CODE_PWR, APP_KEY_EVENT_TRIPLECLICK},
"",
app_key_triple_tap,
NULL},
{{APP_KEY_CODE_PWR, APP_KEY_EVENT_ULTRACLICK},
"",
app_key_quad_tap,
NULL},
{{APP_KEY_CODE_PWR, APP_KEY_EVENT_LONGPRESS},
"",
app_key_long_press_down,
NULL},
};
app_key_handle_clear();
for (i = 0; i < (sizeof(key_cfg) / sizeof(APP_KEY_HANDLE)); i++) {
app_key_handle_registration(&key_cfg[i]);
}
}
void app_key_init_on_charging(void) {
uint8_t i = 0;
const APP_KEY_HANDLE key_cfg[] = {
{{APP_KEY_CODE_PWR, APP_KEY_EVENT_LONGLONGPRESS},
"long press reboot",
app_key_reboot,
NULL},
// {{APP_KEY_CODE_PWR,APP_KEY_EVENT_CLICK},"bt function
// key",app_dfu_key_handler, NULL},
#ifdef __USB_COMM__
{{APP_KEY_CODE_PWR, APP_KEY_EVENT_LONGPRESS},
"usb cdc key",
app_usb_cdc_comm_key_handler,
NULL},
#endif
};
TRACE(1, "%s", __func__);
for (i = 0; i < (sizeof(key_cfg) / sizeof(APP_KEY_HANDLE)); i++) {
app_key_handle_registration(&key_cfg[i]);
}
}