Description
I try to use HW button to control TFT LCD (240x320).
And method button_read() is not called periodically or when I pushed the button.
What MCU/Processor/Board and compiler are you using?
I am using stm32h750 and ARM compiler v. 5.
What LVGL version are you using?
I am using LVGL 7.5.
What do you want to achieve?
I want to process the click of the button. And I want to get more understanding how to work with input devices.
What have you tried so far?
I found some info how to work with this.
Such as:
https://docs.lvgl.io/v7/en/html/porting/indev.html#button
Code to reproduce
/* main.c */
lv_init();
input_device_init ();
tft_init();
user_button();
/* user_button.c */
void input_device_init (void) {
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_BUTTON;
indev_drv.read_cb = button_read;
indev = lv_indev_drv_register(&indev_drv);
lv_indev_set_button_points(indev, points);
lv_indev_enable(indev, true);
g = lv_group_create();
// lv_indev_set_group(indev, g);
}
void user_button(void) {
lv_obj_t * btn = lv_btn_create(lv_scr_act(), NULL);
lv_obj_set_pos(btn, 0, 0);
lv_obj_set_size(btn, 40, 40);
lv_obj_set_event_cb(btn, btn_event_cb);
// lv_obj_set_click (btn, true);
lv_obj_t * label = lv_label_create(btn, NULL);
lv_label_set_text(label, "b1");
lv_group_add_obj(g, btn);
}
static void btn_event_cb(lv_obj_t * btn, lv_event_t event) {
if(event == LV_EVENT_CLICKED) {
static uint8_t cnt = 0;
cnt++;
/*Get the first child of the button which is the label and change its text*/
lv_obj_t * label = lv_obj_get_child(btn, NULL);
lv_label_set_text_fmt(label, "Button: %d", cnt);
}
}
bool button_read (lv_indev_drv_t * drv, lv_indev_data_t*data) {
static uint32_t last_btn = 0;
int btn_pr = my_btn_read();
if(btn_pr >= 0) {
last_btn = btn_pr;
data->state = LV_INDEV_STATE_PR; /*Set the pressed state*/
} else {
data->state = LV_INDEV_STATE_REL; /*Set the released state*/
}
data->btn_id = last_btn;
return false;
}
int my_btn_read (void) {
// return id pushed button
return 1;
}
Screenshot and/or video
My example is the simple button in the upper left corner.