Hi,
I tried as follows.
In btn1 callback function “event_handler_btn1”, variable “btn1_state” are returning, when my finger toggle the button on the display screen:
// returning 3 and 0 when pressed. returning 1 and 2 when pressed again.
// pressed again returning 3 and 0. pressed again returning 1 and 2 .
// and so on.
In function “toggle_manually”, variable “btn1_state” are returning, when the function is called continuously(only a test):
// first function call returning 0 (LV_BTN_STATE_REL).
// second function call returning 2 (LV_BTN_STATE_TGL_REL).
// and so on.
why not returning the same values in the two functions ?
I would like to use both functions(“event_handler_btn” and “toggle_manually”) in the application.
Is the state of the button(btn1) synchronized in both functions ?
LV_BTN_STATE_TGL_REL
LV_BTN_STATE_TGL_PR
BTN1 create:
static lv_obj_t * btn1 = NULL; // global variable.
static lv_obj_t * label1 = NULL; // global variable.
btn1 = lv_btn_create(lv_scr_act(), NULL);
lv_obj_set_event_cb(btn1, event_handler_btn1);
lv_obj_set_size(btn1, 300, 140);
lv_obj_align(btn1, NULL, LV_ALIGN_CENTER, 0, -160);
lv_btn_set_toggle(btn1, true);
lv_btn_toggle(btn1);
label1 = lv_label_create(btn1, NULL);
lv_label_set_text(label1, "BUTTON 1 - OFF");
lv_obj_set_opa_scale_enable(btn1, true);
lv_obj_set_opa_scale(btn1, 100);
lv_btn_set_ink_in_time(btn1, 1000);
lv_btn_set_ink_wait_time(btn1, 100);
lv_btn_set_ink_out_time(btn1, 100);
BTN1 callback event_handler:
static void event_handler_btn1(lv_obj_t * button1, lv_event_t event_bt1)
{
lv_btn_state_t btn1_state = lv_btn_get_state(button1);
//printf("btn1_state = %d\n", btn1_state );
// returning 3 and 0 when pressed. returning 1 and 2 when pressed again.
// pressed again returning 3 and 0. pressed again returning 1 and 2...........................
if ( btn1_state == LV_BTN_STATE_TGL_REL )
{
lv_label_set_text(label1, "BUTTON 1 - OFF");
}
else if ( btn1_state == LV_BTN_STATE_TGL_PR )
{
lv_label_set_text(label1, "BUTTON 1 - ON");
}
// printf("event_bt1 = %d\n", event_bt1 );
}
BTN1 toggle “manually”:
static void toggle_manually( )
{
lv_btn_toggle( btn1 );
lv_btn_state_t btn1_state = lv_btn_get_state( btn1 );
printf("btn1_state = %d\n", btn1_state );
// returning 0 (LV_BTN_STATE_REL) and 2 (LV_BTN_STATE_TGL_REL).
if ( btn1_state == LV_BTN_STATE_TGL_REL ) // LV_BTN_STATE_TGL_REL = 2
{
lv_label_set_text(label1, "BUTTON 1 - OFF");
}
else if ( btn1_state == LV_BTN_STATE_TGL_PR ) // LV_BTN_STATE_TGL_PR = 3
{
lv_label_set_text(label1, "BUTTON 1 - ON");
}
}
Thank’s.