From 13fff73bdb8f64c0f61e6bbc0451d3349bbc967c Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Fri, 1 Mar 2019 06:26:03 +0100 Subject: [PATCH] event: use with keypad --- lv_core/lv_indev.c | 100 ++++++++++++++++++++++++++++++--------------- lv_objx/lv_btn.c | 30 +++++++++----- lv_objx/lv_list.c | 1 + 3 files changed, 87 insertions(+), 44 deletions(-) diff --git a/lv_core/lv_indev.c b/lv_core/lv_indev.c index 6cff598c3..dc6564df0 100644 --- a/lv_core/lv_indev.c +++ b/lv_core/lv_indev.c @@ -388,58 +388,92 @@ static void indev_keypad_proc(lv_indev_t * i, lv_indev_data_t * data) if(g == NULL) return; lv_obj_t * focused = lv_group_get_focused(g); + if(focused == NULL) return; /*Key press happened*/ if(data->state == LV_INDEV_STATE_PR && - i->proc.types.keypad.last_state == LV_INDEV_STATE_REL) { + i->proc.types.keypad.last_state == LV_INDEV_STATE_REL) + { i->proc.pr_timestamp = lv_tick_get(); - lv_obj_t * focused = lv_group_get_focused(g); - if(focused && data->key == LV_GROUP_KEY_ENTER) { - focused->signal_cb(focused, LV_SIGNAL_PRESSED, indev_act); + /*Simulate a press on the object if ENTER was pressed*/ + if(data->key == LV_GROUP_KEY_ENTER) { lv_obj_send_event(focused, LV_EVENT_PRESSED); + lv_group_send_data(g, LV_GROUP_KEY_ENTER); + if(i->proc.reset_query) return; /*The object might be deleted*/ + } + /*Move the focus on NEXT*/ + else if(data->key == LV_GROUP_KEY_NEXT) { + lv_group_set_editing(g, false); /*Editing is not used by KEYPAD is be sure it is disabled*/ + lv_group_focus_next(g); + if(i->proc.reset_query) return; /*The object might be deleted*/ + } + /*Move the focus on PREV*/ + else if(data->key == LV_GROUP_KEY_PREV) { + lv_group_set_editing(g, false); /*Editing is not used by KEYPAD is be sure it is disabled*/ + lv_group_focus_prev(g); + if(i->proc.reset_query) return; /*The object might be deleted*/ + } + /*Just send other keys to the object (e.g. 'A' or `LV_GORUP_KEY_RIGHT)*/ + else { + lv_group_send_data(g, data->key); } } /*Pressing*/ - else if(data->state == LV_INDEV_STATE_PR && i->proc.types.keypad.last_state == LV_INDEV_STATE_PR) { - if(data->key == LV_GROUP_KEY_ENTER && - i->proc.long_pr_sent == 0 && - lv_tick_elaps(i->proc.pr_timestamp) > LV_INDEV_LONG_PRESS_TIME) { - /*On enter long press leave edit mode.*/ - lv_obj_t * focused = lv_group_get_focused(g); - if(focused) { - focused->signal_cb(focused, LV_SIGNAL_LONG_PRESS, indev_act); - i->proc.long_pr_sent = 1; + else if(data->state == LV_INDEV_STATE_PR && i->proc.types.keypad.last_state == LV_INDEV_STATE_PR) + { + /*Long press time has elapsed?*/ + if(i->proc.long_pr_sent == 0 && lv_tick_elaps(i->proc.pr_timestamp) > LV_INDEV_LONG_PRESS_TIME) { + i->proc.long_pr_sent = 1; + if(data->key == LV_GROUP_KEY_ENTER) { + i->proc.longpr_rep_timestamp = lv_tick_get(); lv_obj_send_event(focused, LV_EVENT_LONG_PRESSED); + if(i->proc.reset_query) return; /*The object might be deleted*/ + } + } + /*Long press repeated time has elapsed?*/ + else if(i->proc.long_pr_sent != 0 && lv_tick_elaps(i->proc.longpr_rep_timestamp) > LV_INDEV_LONG_PRESS_REP_TIME) { + + i->proc.longpr_rep_timestamp = lv_tick_get(); + + /*Send LONG_PRESS_REP on ENTER*/ + if(data->key == LV_GROUP_KEY_ENTER) { + lv_obj_send_event(focused, LV_EVENT_LONG_PRESSED_REPEAT); + if(i->proc.reset_query) return; /*The object might be deleted*/ + } + /*Move the focus on NEXT again*/ + else if(data->key == LV_GROUP_KEY_NEXT) { + lv_group_set_editing(g, false); /*Editing is not used by KEYPAD is be sure it is disabled*/ + lv_group_focus_next(g); + if(i->proc.reset_query) return; /*The object might be deleted*/ + } + /*Move the focus on PREV again*/ + else if(data->key == LV_GROUP_KEY_PREV) { + lv_group_set_editing(g, false); /*Editing is not used by KEYPAD is be sure it is disabled*/ + lv_group_focus_prev(g); + if(i->proc.reset_query) return; /*The object might be deleted*/ + } + /*Just send other keys again to the object (e.g. 'A' or `LV_GORUP_KEY_RIGHT)*/ + else { + lv_group_send_data(g, data->key); + if(i->proc.reset_query) return; /*The object might be deleted*/ } } } /*Release happened*/ - else if(data->state == LV_INDEV_STATE_REL && i->proc.types.keypad.last_state == LV_INDEV_STATE_PR) { + else if(data->state == LV_INDEV_STATE_REL && i->proc.types.keypad.last_state == LV_INDEV_STATE_PR) + { /*The user might clear the key when it was released. Always release the pressed key*/ data->key = i->proc.types.keypad.last_key; + if(data->key == LV_GROUP_KEY_ENTER) { - /* Edit mode is not used by KEYPAD devices. - * So leave edit mode if we are in it before focusing on the next/prev object*/ - if(data->key == LV_GROUP_KEY_NEXT || data->key == LV_GROUP_KEY_PREV) { - lv_group_set_editing(g, false); - } - - if(data->key == LV_GROUP_KEY_NEXT) { - lv_group_focus_next(g); - } else if(data->key == LV_GROUP_KEY_PREV) { - lv_group_focus_prev(g); - } else if(data->key == LV_GROUP_KEY_ENTER) { - if(!i->proc.long_pr_sent) { - focused->signal_cb(focused, LV_SIGNAL_RELEASED, indev_act); + if(i->proc.long_pr_sent == 0) { lv_obj_send_event(focused, LV_EVENT_CLICKED); + } else { + lv_obj_send_event(focused, LV_EVENT_RELEASED); } - } else { - lv_group_send_data(g, data->key); + if(i->proc.reset_query) return; /*The object might be deleted*/ } - - if(i->proc.reset_query) return; /*The object might be deleted in `focus_cb` or due to any other user event*/ - i->proc.pr_timestamp = 0; i->proc.long_pr_sent = 0; } @@ -754,7 +788,7 @@ static void indev_proc_release(lv_indev_proc_t * proc) if(proc->long_pr_sent == 0 && proc->types.pointer.drag_in_prog == 0) { lv_obj_send_event(proc->types.pointer.act_obj, LV_EVENT_CLICKED); } else { - lv_obj_send_event(proc->types.pointer.act_obj, LV_SIGNAL_RELEASED); + lv_obj_send_event(proc->types.pointer.act_obj, LV_EVENT_RELEASED); } } diff --git a/lv_objx/lv_btn.c b/lv_objx/lv_btn.c index aebee87df..5f0d18735 100644 --- a/lv_objx/lv_btn.c +++ b/lv_objx/lv_btn.c @@ -170,6 +170,11 @@ void lv_btn_set_toggle(lv_obj_t * btn, bool tgl) */ void lv_btn_set_state(lv_obj_t * btn, lv_btn_state_t state) { + + if(state == LV_BTN_STATE_REL) { + printf("asd\n"); + } + lv_btn_ext_t * ext = lv_obj_get_ext_attr(btn); if(ext->state != state) { ext->state = state; @@ -493,6 +498,7 @@ static bool lv_btn_design(lv_obj_t * btn, const lv_area_t * mask, lv_design_mode */ static lv_res_t lv_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * param) { + lv_res_t res; /* Include the ancient signal function */ @@ -562,8 +568,7 @@ static lv_res_t lv_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * param) } else if(sign == LV_SIGNAL_RELEASED) { /*If not dragged and it was not long press action then *change state and run the action*/ - lv_indev_t * indev = lv_indev_get_act(); - if(lv_indev_is_dragging(param) == false && indev->proc.long_pr_sent == 0) { + if(lv_indev_is_dragging(param) == false) { if(ext->state == LV_BTN_STATE_PR && tgl == false) { lv_btn_set_state(btn, LV_BTN_STATE_REL); } else if(ext->state == LV_BTN_STATE_TGL_PR && tgl == false) { @@ -573,6 +578,11 @@ static lv_res_t lv_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * param) } else if(ext->state == LV_BTN_STATE_TGL_PR && tgl == true) { lv_btn_set_state(btn, LV_BTN_STATE_REL); } + + if(tgl) { + lv_obj_send_event(btn, LV_EVENT_VALUE_CHANGED); + } + } else { /*If dragged change back the state*/ if(ext->state == LV_BTN_STATE_PR) { lv_btn_set_state(btn, LV_BTN_STATE_REL); @@ -616,16 +626,14 @@ static lv_res_t lv_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * param) } else if(c == LV_GROUP_KEY_LEFT || c == LV_GROUP_KEY_DOWN) { if(lv_btn_get_toggle(btn)) lv_btn_set_state(btn, LV_BTN_STATE_REL); } else if(c == LV_GROUP_KEY_ENTER) { - lv_indev_t * indev = lv_indev_get_act(); - if(!indev->proc.long_pr_sent) { - if(lv_btn_get_toggle(btn)) { - if(state == LV_BTN_STATE_REL || state == LV_BTN_STATE_PR) lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL); - else if(state == LV_BTN_STATE_TGL_REL || state == LV_BTN_STATE_TGL_PR) lv_btn_set_state(btn, LV_BTN_STATE_REL); - } else { - if(state == LV_BTN_STATE_REL || state == LV_BTN_STATE_PR) lv_btn_set_state(btn, LV_BTN_STATE_REL); - else if(state == LV_BTN_STATE_TGL_REL || state == LV_BTN_STATE_TGL_PR) lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL); - } + if(lv_btn_get_toggle(btn)) { + if(state == LV_BTN_STATE_REL || state == LV_BTN_STATE_PR) lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL); + else if(state == LV_BTN_STATE_TGL_REL || state == LV_BTN_STATE_TGL_PR) lv_btn_set_state(btn, LV_BTN_STATE_REL); + } else { + if(state == LV_BTN_STATE_REL || state == LV_BTN_STATE_PR) lv_btn_set_state(btn, LV_BTN_STATE_REL); + else if(state == LV_BTN_STATE_TGL_REL || state == LV_BTN_STATE_TGL_PR) lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL); } + lv_obj_send_event(btn, LV_EVENT_VALUE_CHANGED); } } else if(sign == LV_SIGNAL_CLEANUP) { #if USE_LV_ANIMATION && LV_BTN_INK_EFFECT diff --git a/lv_objx/lv_list.c b/lv_objx/lv_list.c index 097f2495f..67823f7d3 100644 --- a/lv_objx/lv_list.c +++ b/lv_objx/lv_list.c @@ -846,6 +846,7 @@ static lv_res_t lv_list_signal(lv_obj_t * list, lv_signal_t sign, void * param) if(btn != NULL) { lv_list_ext_t * ext = lv_obj_get_ext_attr(list); ext->last_sel = btn; + lv_obj_send_event(btn, LV_EVENT_CLICKED); } } #endif