Description
When an event is triggered by touching a switch, LV_EVENT_CLICKED
and LV_EVENT_PRESSED
events occur only once, while LV_EVENT_VALUE_CHANGED
occurs twice.
Is this normal?
static void event_handler_x(lv_event_t * e)
{
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t * obj = lv_event_get_target(e);
if(code == LV_EVENT_VALUE_CHANGED) {
// repeat twice
LV_LOG_USER("State: %s\n", lv_obj_has_state(obj, LV_STATE_CHECKED) ? "On" : "Off");
}
else if(code == LV_EVENT_CLICKED) {
// only once
LV_LOG_USER("State: %s\n", lv_obj_has_state(obj, LV_STATE_CHECKED) ? "On" : "Off");
}
else if(code == LV_EVENT_PRESSED) {
// only once
LV_LOG_USER("State: %s\n", lv_obj_has_state(obj, LV_STATE_CHECKED) ? "On" : "Off");
}
}
void example(void)
{
lv_obj_set_flex_flow(lv_scr_act(), LV_FLEX_FLOW_COLUMN);
lv_obj_set_flex_align(lv_scr_act(), LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
lv_obj_t * sw;
sw = lv_switch_create(lv_scr_act());
lv_obj_add_event_cb(sw, event_handler_x, LV_EVENT_CLICKED, NULL);
sw = lv_switch_create(lv_scr_act());
lv_obj_add_event_cb(sw, event_handler_x, LV_EVENT_CLICKED, NULL);
sw = lv_switch_create(lv_scr_act());
lv_obj_add_event_cb(sw, event_handler_x, LV_EVENT_PRESSED, NULL);
sw = lv_switch_create(lv_scr_act());
lv_obj_add_event_cb(sw, event_handler_x, LV_EVENT_VALUE_CHANGED, NULL);
}
What MCU/Processor/Board and compiler are you using?
What LVGL version are you using?
What do you want to achieve?
What have you tried so far?
Code to reproduce
Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.
The code block(s) should be formatted like:
/*You code here*/
Screenshot and/or video
If possible, add screenshots and/or videos about the current state.