diff --git a/apps/main/apps.cpp b/apps/main/apps.cpp index d65443f..10276dc 100644 --- a/apps/main/apps.cpp +++ b/apps/main/apps.cpp @@ -1369,37 +1369,195 @@ void app_latency_switch_key_handler(void) } } -void app_bt_function_key(APP_KEY_STATUS *status, void *param) -{ + +/* + * handling of touch events when the devices are turned on + + * Both pods active: + + * Right Ear: + * Single tap : Play/Pause + * Double tap : Next track + * Hold : Fast-Forward + * Triple tap : Volume Up + * + * Left Ear: + * Single tap : Play/Pause + * Double tap : Previous track + * Hold : Rewind + * 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_AVRCP_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_AVRCP_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 app_key_single_tap(APP_KEY_STATUS *status, void *param){ TRACE(2,"%s event %d", __func__, status->event); - bt_key_send(status); + + 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(); + } + } + +} +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_hold_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(); + } + } + +} +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(); + }else { + //Bud's are working as a pair + if (app_tws_is_left_side()){ + TRACE(0,"Handling %s as left bud",__func__); + //Lefty + }else { + TRACE(0,"Handling %s as right bud",__func__); + //Righty + } + } +} + +void app_key_reboot(APP_KEY_STATUS *status, void *param) +{ + TRACE(1,"%s ",__func__); + hal_cmu_sys_reboot(); } void app_key_init(void) { -#if defined(IBRT_TESTMODE) - app_ibrt_ui_test_key_init(); -#else uint8_t i = 0; TRACE(1,"%s",__func__); const APP_KEY_HANDLE key_cfg[] = { - {{APP_KEY_CODE_PWR,APP_KEY_EVENT_CLICK},"bt function key",app_bt_function_key, NULL}, - {{APP_KEY_CODE_PWR,APP_KEY_EVENT_DOUBLECLICK},"bt function key",app_bt_function_key, NULL}, - {{APP_KEY_CODE_PWR,APP_KEY_EVENT_LONGPRESS},"bt function key",app_bt_function_key, NULL}, - {{APP_KEY_CODE_PWR,APP_KEY_EVENT_TRIPLECLICK},"bt anc key",app_anc_key, NULL}, + + {{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_CONTINUED_DOWN},"",app_key_hold_tap, NULL}, + // {{APP_KEY_CODE_PWR,APP_KEY_EVENT_LONGPRESS},"",app_key_hold_tap, NULL}, + // {{APP_KEY_CODE_PWR,APP_KEY_EVENT_TRIPLECLICK},"bt anc key",app_anc_key, NULL}, + {{APP_KEY_CODE_PWR,APP_KEY_EVENT_LONGLONGPRESS},"long click reboot",app_key_reboot, NULL}, }; app_key_handle_clear(); for (i=0; i<(sizeof(key_cfg)/sizeof(APP_KEY_HANDLE)); i++){ app_key_handle_registration(&key_cfg[i]); } -#endif -} -void app_key_reboot(APP_KEY_STATUS *status, void *param) -{ - TRACE(1,"%s ",__func__); - hal_cmu_sys_reboot(); } void app_key_init_on_charging(void)