hiiii
i m new in the display gui interface
i use ILI9341 320x240 and pic32
everything works fine but i have some GUI issues that i think i never Done before
first i create a simple display graphics which has a one stop button ,one button metrix and some labels and symbols
now i want a simple call back of buttons which has been in that button matrix but when i put stop button event in the call back of button matrix my GUI suddenly didn’t working and buttons pf button matrix didn’t recognized
how i put stop button as a call back of button matrix ???
and one another issue i notice that there is no lv_btn_set_action() in btn.c
i mean.
when i pressed any button of button matrix , stop button execute and also that button matrix in the same parent screen and both can be clickable and both have a callbacks functions
my call backs and btn matrix codes given below
static lv_obj_t * lable_object;
static lv_obj_t * symbol_object;
static lv_obj_t * text_object;
static lv_obj_t * btnm1;
static lv_obj_t * btnm2;
static lv_obj_t * btnm3;
static lv_obj_t * btnm4;
static lv_obj_t * back_btn;
static lv_obj_t * stop_btn;
static lv_obj_t * kb;
static lv_obj_t * ta;
static lv_obj_t * scr;
static lv_obj_t * scr2;
uint16_t i;
void stop_btn_event(lv_obj_t * obj, lv_event_t event) {
switch (event) {
case LV_EVENT_PRESSED:
lable_object = lv_label_create(lv_scr_act(), NULL);
lv_obj_set_pos(lable_object, 0, 300); /Set its position/
lv_label_set_text(lable_object, “Connecting…”);
printf(“Pressed\r\n”);
break;
case LV_EVENT_RELEASED:
lv_obj_del(lable_object);
break;
}
}
const char * btnm_map[] = {“Extrude”, “Macro”, “NIL”, “\n”,
“Control”, “Print”, “Keyboard”, “\n”,
“Setup”, “Air/LED”, “Mandrel”, “”};
void event_handler(lv_obj_t * obj, lv_event_t event) {
if (event == LV_EVENT_PRESSED && lv_btnm_get_active_btn_text(obj)) {
// const char * txt = lv_btnm_get_active_btn_text(obj);
// for (i = 0; i < 9; i++) {
if (lv_btnm_get_active_btn_text(obj) == btnm_map[0] ) {
printf("extrude\r\n");
}
if (lv_btnm_get_active_btn_text(obj) == btnm_map[1] )
{
printf("macro\r\n");
}
if (lv_btnm_get_active_btn_text(obj) == btnm_map[2] )
{
printf("nill\r\n");
}
if (lv_btnm_get_active_btn_text(obj) == btnm_map[4] )
{
lv_obj_clean(lv_scr_act());
STOP_BTN();
symbol(LV_SYMBOL_WIFI, 210, 5);
Text("Current C 0.0 0.0", 0, 60);
Text("Active C", 0, 90);
Text("Standby C", 0, 120);
symbol(LV_SYMBOL_HOME, 20, 150);
btnm2 = lv_btnm_create(lv_scr_act(), NULL);
lv_btnm_set_map(btnm2, btnm_map);
lv_obj_set_size(btnm2, 240, 120);
lv_obj_set_pos(btnm2, 0, 180);
lv_obj_set_event_cb(btnm2, event_handler);
printf("controll\r\n");
}
if (lv_btnm_get_active_btn_text(obj) == btnm_map[5] )
{
lv_obj_del(text_object);
lv_obj_del(symbol_object);
Text("Extruder %",0, 150);
printf("print\r\n");
}
if (lv_btnm_get_active_btn_text(obj) == btnm_map[6]) {
static lv_style_t rel_style, pr_style;
lv_style_copy(&rel_style, &lv_style_btn_rel);
rel_style.body.radius = 0;
rel_style.body.border.width = 1;
lv_style_copy(&pr_style, &lv_style_btn_pr);
pr_style.body.radius = 0;
pr_style.body.border.width = 1;
/*Create a keyboard and apply the styles*/
kb = lv_kb_create(lv_scr_act(), NULL);
lv_obj_set_size(kb, 240, 50);
lv_obj_set_pos(kb, 0, 90);
lv_kb_set_cursor_manage(kb, true);
lv_kb_set_style(kb, LV_KB_STYLE_BG, &lv_style_transp_tight);
lv_kb_set_style(kb, LV_KB_STYLE_BTN_REL, &rel_style);
lv_kb_set_style(kb, LV_KB_STYLE_BTN_PR, &pr_style);
/*Create a text area. The keyboard will write here*/
ta = lv_ta_create(lv_scr_act(), NULL);
lv_obj_set_size(ta, 240, 30);
lv_obj_set_pos(ta, 0, 0);
// lv_obj_align(ta, NULL, LV_ALIGN_IN_TOP_MID, 0, 10);
lv_ta_set_text(ta, "");
/*Assign the text area to the keyboard*/
lv_kb_set_ta(kb, ta);
printf("keyboard\r\n");
}
if (lv_btnm_get_active_btn_text(obj) == btnm_map[8] )
{
lv_obj_del(stop_btn);
lv_obj_del(symbol_object);
// lv_obj_del(kb);
// lv_obj_del(ta);
lv_obj_del(text_object);
Text(“Free RAM : 25532”,0,0);
printf(“setup\r\n”);
}
if (lv_btnm_get_active_btn_text(obj) == btnm_map[9] )
{
printf(“airled\r\n”);
}
if (lv_btnm_get_active_btn_text(obj) == btnm_map[10] )
{
printf(“mandrel\r\n”);
}
}
// printf("%s was pressed\r\n", txt);
// }
}
bool my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data) {
static lv_coord_t last_x = 0;
static lv_coord_t last_y = 0;
/*Save the state and save the pressed coordinate*/
data->state = (isTouching() == 0) ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL;
if (data->state == LV_INDEV_STATE_PR) getPosition(&last_x, &last_y, 1, 0x5);
/*Set the coordinates (if released use the last pressed coordinates)*/
data->point.x = last_x;
data->point.y = last_y;
return false; /*Return `false` because we are not buffering and no more data to read*/
}
void STOP_BTN() {
stop_btn = lv_btn_create(lv_scr_act(), NULL); /Add a button the current screen/
lv_obj_set_pos(stop_btn, 0, 0); /Set its position/
lv_obj_set_size(stop_btn, 70, 30); /Set its size/
lv_obj_t * label = lv_label_create(stop_btn, NULL); /Add a label to the button/
lv_label_set_text(label, “STOP”); /Set the labels text/
static lv_style_t style_btn_rel; /A variable to store the released style/
lv_style_copy(&style_btn_rel, &lv_style_plain); /Initialize from a built-in style/
style_btn_rel.body.border.color = lv_color_hex3(ILI9341_BLACK);
style_btn_rel.body.border.width = 1;
style_btn_rel.body.main_color = lv_color_hex3(ILI9341_RED);
style_btn_rel.body.grad_color = lv_color_hex3(ILI9341_RED);
style_btn_rel.body.shadow.width = 4;
style_btn_rel.body.shadow.type = LV_SHADOW_BOTTOM;
style_btn_rel.body.radius = LV_RADIUS_CIRCLE;
style_btn_rel.text.color = lv_color_hex3(ILI9341_WHITE);
static lv_style_t style_btn_pr; /A variable to store the pressed style/
lv_style_copy(&style_btn_pr, &style_btn_rel); /Initialize from the released style/
style_btn_pr.body.border.color = lv_color_hex3(ILI9341_BLACK);
style_btn_pr.body.main_color = lv_color_hex3(ILI9341_GOLD);
style_btn_pr.body.grad_color = lv_color_hex3(ILI9341_GOLD);
style_btn_pr.body.shadow.width = 2;
style_btn_pr.text.color = lv_color_hex3(ILI9341_BLACK);
lv_btn_set_style(stop_btn, LV_BTN_STYLE_REL, &style_btn_rel); /Set the button’s released style/
lv_btn_set_style(stop_btn, LV_BTN_STYLE_PR, &style_btn_pr); /Set the button’s pressed style/
lv_obj_set_event_cb(stop_btn, stop_btn_event);
}
void lv_ex_btnm_1(void) {
btnm1 = lv_btnm_create(lv_scr_act(), NULL);
lv_btnm_set_map(btnm1, btnm_map);
lv_obj_set_size(btnm1, 240, 120);
lv_obj_set_pos(btnm1, 0, 180);
lv_obj_set_event_cb(btnm1, event_handler);
}
void symbol(const char * text, lv_coord_t x, lv_coord_t y) {
symbol_object = lv_label_create(lv_scr_act(), NULL);
lv_obj_set_pos(symbol_object, x, y); /Set its position/
lv_label_set_text(symbol_object, text);
}
void Text(const char * text, lv_coord_t x, lv_coord_t y) {
text_object = lv_label_create(lv_scr_act(), NULL);
lv_obj_set_pos(text_object, x, y); /Set its position/
lv_label_set_text(text_object, text);
}
void slide1(void) {
STOP_BTN();
symbol(LV_SYMBOL_WIFI, 210, 5);
Text("Current C 0.0 0.0", 0, 60);
Text("Active C", 0, 90);
Text("Standby C", 0, 120);
symbol(LV_SYMBOL_HOME, 20, 150);
lv_ex_btnm_1();
}
void Keyboard(void)
{
/Create styles for the keyboard/
static lv_style_t rel_style, pr_style;
lv_style_copy(&rel_style, &lv_style_btn_rel);
rel_style.body.radius = 0;
rel_style.body.border.width = 1;
lv_style_copy(&pr_style, &lv_style_btn_pr);
pr_style.body.radius = 0;
pr_style.body.border.width = 1;
/*Create a keyboard and apply the styles*/
lv_obj_t *kb = lv_kb_create(lv_scr_act(), NULL);
lv_obj_set_size(kb, 240, 50);
lv_obj_set_pos(kb, 0, 90);
lv_kb_set_cursor_manage(kb, true);
lv_kb_set_style(kb, LV_KB_STYLE_BG, &lv_style_transp_tight);
lv_kb_set_style(kb, LV_KB_STYLE_BTN_REL, &rel_style);
lv_kb_set_style(kb, LV_KB_STYLE_BTN_PR, &pr_style);
/*Create a text area. The keyboard will write here*/
lv_obj_t *ta = lv_ta_create(lv_scr_act(), NULL);
lv_obj_set_size(ta, 240, 30);
lv_obj_set_pos(ta, 0, 0);
// lv_obj_align(ta, NULL, LV_ALIGN_IN_TOP_MID, 0, 10);
lv_ta_set_text(ta, “”);
/*Assign the text area to the keyboard*/
lv_kb_set_ta(kb, ta);
}
void setup() {
static lv_disp_buf_t disp_buf;
static lv_color_t buf1[LV_HOR_RES_MAX * 22]; /*Declare a buffer for 10 lines*/
//static lv_color_t buf2[LV_HOR_RES_MAX * 10]; /*Declare a buffer for 10 lines*/
lv_disp_buf_init(&disp_buf, buf1, NULL, LV_HOR_RES_MAX * 22);
lv_disp_drv_t disp_drv; /*Descriptor of a display driver*/
lv_disp_drv_init(&disp_drv); /*Basic initialization*/
disp_drv.flush_cb = my_disp_flush;
// disp_drv.hor_res = 240;
// disp_drv.ver_res = 320;
disp_drv.buffer = &disp_buf; /Assign the buffer to the display/
lv_disp_drv_register(&disp_drv); /Finally register the driver/
lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv); /*Descriptor of a input device driver*/
indev_drv.type = LV_INDEV_TYPE_POINTER; /*Touch pad is a pointer-like device*/
indev_drv.read_cb = my_touchpad_read; /*Set your driver function*/
lv_indev_drv_register(&indev_drv); /*Finally register the driver*/
}