lvgl 5.1:
lv_res_t UserDisplay::swAction(lv_obj_t *sw)
{
json *tempData = static_cast<json *>(lv_obj_get_free_ptr(sw));
*tempData = lv_sw_get_state(sw);
return LV_RES_OK;
}
...
lv_sw_set_action(compSw.back().second, swAction);
lv_obj_set_free_ptr(compSw.back().second, &it.value());
...
I used to associate pointers of data to be associated in this way.
This code is beautiful and short.
But I didn’t find this function in lvgl6.1. Is there any alternative function and use example?
lvgl 6.1
void UserDisplay::swAction(lv_obj_t *sw, lv_event_t event) //SW的动作
{
if (event == LV_EVENT_VALUE_CHANGED)
{
json *tempData = //TOOD How to get associate point from *sw?
*tempData = lv_sw_get_state(sw);
}
}
...
lv_sw_set_action(compSw.back().second, swAction);
//TODO How to associate JSON pointer to swaction?
...