In my project, with esp32 wroom 32, I need to rotate a line in run time execution, following the angle received from an IMU.
I tried to use lv_obj_set_style_transform_angle but it doesn’t work.
In my project, with esp32 wroom 32, I need to rotate a line in run time execution, following the angle received from an IMU.
I tried to use lv_obj_set_style_transform_angle but it doesn’t work.
@edoardomalgarida, I suggest that you create a component to serve as a container and apply rotation according to IMU changes. Here is an example.
lv_obj_t *container = NULL;
void contatiner_event_cb(lv_event_t *e)
{
float angle_degrees = 0.f;
static float start_angle = 0.f;
angle_degrees = start_angle + 10.0f;
lv_obj_t *target = lv_event_get_target(e);
lv_obj_set_style_transform_pivot_x(target, lv_obj_get_width(target) / 2, 0);
lv_obj_set_style_transform_pivot_y(target, lv_obj_get_height(target) / 2, 0);
lv_obj_set_style_transform_rotation(target, (int)(angle_degrees * 10), 0);
start_angle = angle_degrees;
}
void timer_value_change_cb (lv_timer_t *timer)
{
lv_obj_send_event(container, LV_EVENT_VALUE_CHANGED, NULL);
}
container = lv_obj_create(lv_screen_active());
lv_obj_remove_style_all(container);
lv_obj_set_size(container, 100, 100);
lv_obj_remove_flag(container, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_add_event_cb(container, contatiner_event_cb , LV_EVENT_VALUE_CHANGED, NULL);
lv_obj_t * obj = lv_line_create(container);
static lv_point_precise_t p[] = {{10, 30}, {30, 50}};
lv_line_set_points(obj, p, 2);
lv_timer_t * t = lv_timer_create(timer_value_change_cb, 100 * 5, NULL);
lv_timer_resume(t);