Description
I tried to design a custom btnm, it’s similar to our daily keyboard like “CapsLK” function and so on, but when I changed the map of btnm, some of expected sequence caused my hardware reset,.See the code below, “Up” “Down” btn is OK to change, but “Num” and “FU” btn caused my hardware reset.
What MCU/Processor/Board and compiler are you using?
RDA borad.
What do you want to achieve?
Design a keyboard as we use daily on mobile phone.
What have you tried so far?
I tried to replace the btnm map with the previously one and that two btn works, so I guess this matter with the content of btnm map, but I don’t know why.
Code to reproduce
/*You code here*/
void temp_btnm_test()
{
static lv_style_t cont_style;
lv_style_copy(&cont_style, &lv_style_pretty_color);
cont_style.body.padding.left = 0;
cont_style.body.padding.right = 0;
cont_style.body.padding.top = 0;
cont_style.body.padding.bottom = 0;
cont_style.body.padding.inner = 0;
cont_style.body.radius = 0;
cont_style.body.border.width = 0;
cont_style.body.border.color = LV_COLOR_RED;
cont_style.body.main_color = LV_COLOR_RED;
//cont_style.body.opa = LV_OPA_TRANSP;
lv_obj_t*content_cont = lv_cont_create(lv_scr_act(NULL), NULL);
lv_obj_set_pos(content_cont, 0, 50);//40
lv_cont_set_fit(content_cont, LV_FIT_NONE);
lv_cont_set_layout(content_cont, LV_LAYOUT_OFF);
lv_cont_set_style(content_cont, LV_CONT_STYLE_MAIN, &cont_style);
lv_obj_set_size(content_cont, 480, 200);
//account and password
static lv_style_t click_btn_style;
lv_style_copy(&click_btn_style, &lv_style_btn_rel);
click_btn_style.body.opa = LV_OPA_TRANSP;
lv_obj_t *label_1, *label_2, *btn_account, *btn_password;
label_1 = lv_label_create(content_cont, NULL);
lv_obj_align(label_1, NULL, LV_ALIGN_IN_TOP_LEFT, 100, 20);
lv_label_set_text(label_1, "Account:");
label_2 = lv_label_create(content_cont, NULL);
lv_obj_align(label_2, label_1, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 70);
lv_label_set_text(label_2, "Password:");
//account
lv_obj_t * obj_ta = lv_ta_create(content_cont, NULL);
lv_obj_align(obj_ta, label_1, LV_ALIGN_OUT_RIGHT_TOP, 10, -5);
lv_obj_set_size(obj_ta, 150, 50);
account_ta[0] = obj_ta;
lv_ta_set_one_line(obj_ta, true);
lv_ta_set_text(obj_ta, "");
lv_ta_set_placeholder_text(obj_ta, "please insert");
btn_account = lv_btn_create(content_cont, NULL);
lv_obj_align(btn_account, label_1, LV_ALIGN_OUT_RIGHT_TOP, 10, -5);
lv_btn_set_layout(btn_account, LV_LAYOUT_OFF);
lv_obj_set_size(btn_account, 240, 50);
lv_btn_set_style(btn_account, LV_BTN_STYLE_REL, &click_btn_style);
lv_obj_set_event_cb(btn_account, Account_insert);
//password
obj_ta = lv_ta_create(content_cont, NULL);
lv_obj_align(obj_ta, label_2, LV_ALIGN_OUT_RIGHT_TOP, 10, -5);
lv_obj_set_size(obj_ta, 150, 50);
account_ta[1] = obj_ta;
lv_ta_set_text(obj_ta, "");
lv_ta_set_placeholder_text(obj_ta, "please insert");
btn_password = lv_btn_create(content_cont, NULL);
lv_obj_align(btn_password, label_2, LV_ALIGN_OUT_RIGHT_TOP, 10, -5);
lv_btn_set_layout(btn_password, LV_LAYOUT_OFF);
lv_obj_set_size(btn_password, 240, 50);
lv_btn_set_style(btn_password, LV_BTN_STYLE_REL, &click_btn_style);
static void Account_insert(lv_obj_t *btn, lv_event_t event)
{
if (event == LV_EVENT_CLICKED) {
lv_obj_t *got_parent, *got_child;
got_parent = lv_obj_get_parent(btn);
got_child = lv_obj_get_child(got_parent, btn); //supposed to be text area match to btn
Account_keyboard_create(got_child);
lv_obj_set_hidden(btn, true);
}
}
static void Account_keyboard_create(lv_obj_t* match_ta)
{
static const char * btnm_map[] = { "q","w","e","r","t","y","u","i","o","p","\n",
"a","s","d","f","g","h","j","k","l","\n",
"Up","z","x","c","v","b","n","m","del","\n",
"Num","FU",","," ",".","*",""
};
static lv_style_t style_btnm_bg;
lv_style_copy(&style_btnm_bg, &lv_style_pretty);
style_btnm_bg.body.radius = 0;
style_btnm_bg.body.padding.inner = 5;
style_btnm_bg.body.main_color = LV_COLOR_GRAY;
style_btnm_bg.body.grad_color = LV_COLOR_GRAY;
style_btnm_bg.text.color = LV_COLOR_WHITE;
style_btnm_bg.body.padding.top = 2;
style_btnm_bg.body.padding.bottom = 2;
lv_obj_t *obj_kb = lv_btnm_create(lv_scr_act(), NULL);
//lv_obj_set_size(obj_kb, scr_r_width, 200);
lv_obj_set_width(obj_kb, scr_r_width);
lv_btnm_set_map(obj_kb, btnm_map);
lv_obj_align(obj_kb, NULL, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
lv_btnm_set_style(obj_kb, LV_BTNM_STYLE_BG, &style_btnm_bg);
lv_obj_set_event_cb(obj_kb, keyboard_event_handle);
}
static void keyboard_event_handle(lv_obj_t * obj, lv_event_t event)
{
lv_obj_t *got_parent, *got_child;
static const char * btnm_map_lower [] = { "q","w","e","r","t","y","u","i","o","p","\n",
"a","s","d","f","g","h","j","k","l","\n",
"Up","z","x","c","v","b","n","m","del","\n",
"Num","FU",","," ",".","*",""
};
static const char * btnm_map_caps[] = { "Q","W","E","R","T","Y","Y","I","O","P","\n",
"A","S","D","F","G","H","J","K","L","\n",
"Down","Z","X","C","V","B","N","M","del","\n",
"Num","FU",","," ",".","*",""
};
static const char * btnm_map_nums[] = { "+","1","2","3","del","\n",
"-","4","5","6","*","\n",
"/","7","8","9","@","\n",
":",",","0",".","Bak",""
};
static const char * btnm_map_character[] = {",",".","?","!","<","\n",
":",";","~","/",">","\n",
"@","#","$","%","=","\n",
//"*","(",")","-","+",
""
};
char * btnm_control[] = {"del","Up","Down","Num","Bak","FU"};
if (event == LV_EVENT_VALUE_CHANGED) {
const char * txt = lv_btnm_get_active_btn_text(obj);
if (txt == btnm_control[0]) { //del
lv_ta_del_char(account_ta[0]);
}
else if (txt == btnm_control[1]) { //Up
lv_btnm_set_map(obj, btnm_map_caps);//btnm_map_caps
}
else if (txt == btnm_control[2]) { //Down
lv_btnm_set_map(obj, btnm_map_lower);
}
else if (txt == btnm_control[3]) { //Num
lv_btnm_set_map(obj, btnm_map_nums);
}
else if (txt == btnm_control[4]) { //return
lv_btnm_set_map(obj, btnm_map_lower);
}
else if (txt == btnm_control[5]) {
lv_btnm_set_map(obj, btnm_map_character);
}
else {
lv_ta_add_text(account_ta[0], txt);
}
}
}
}
Screenshot and/or video
If possible, add screenshots and/or videos about the current state.