Description
What MCU/Processor/Board and compiler are you using?
ESP32 on a WT32 SC01 board
What LVGL version are you using? Version 9
What do you want to achieve?
Scale widget that I can get the needle to move based on an int variable.
The program compiles, loads, and runs. But resets every time the lv_scale_set_line_needle_value is run.
What have you tried so far?
Code to reproduce
//GLOBAL OBJECTS
lv_obj_t * house_gauge;
v_obj_t* house_needle;
// IN STARTUP()
create_scale(house_gauge, SCALE_SIZE_X, SCALE_SIZE_Y, 0, 60, SCALE_POS_X1, SCALE_POS_Y1, house_needle);
// IN LOOP()
lv_scale_set_line_needle_value(house_gauge, house_needle, 60, house_value());
void create_scale(lv_obj_t * lvobj, int size_w, int size_h, int scale_start, int scale_end, int position_x, int position_y, lv_obj_t *needle_obj) {
// create the base scale widget
lvobj = lv_scale_create(lv_screen_active());
lv_obj_set_pos(lvobj, position_x, position_y);
lv_scale_set_mode(lvobj, LV_SCALE_MODE_ROUND_OUTER);
lv_obj_set_size(lvobj, size_w, size_h);
lv_obj_set_style_bg_opa(lvobj, LV_OPA_COVER, 0);
lv_obj_set_style_bg_color(lvobj, lv_palette_lighten(LV_PALETTE_RED, 5), 0);
lv_obj_set_style_radius(lvobj, LV_RADIUS_CIRCLE, 0);
lv_obj_set_style_clip_corner(lvobj, true, 0);
lv_scale_set_label_show(lvobj, true);
lv_scale_set_total_tick_count(lvobj, 31);
lv_scale_set_major_tick_every(lvobj, 5);
lv_obj_set_style_length(lvobj, 4, LV_PART_ITEMS);
lv_obj_set_style_length(lvobj, 10, LV_PART_INDICATOR);
lv_scale_set_range(lvobj, scale_start, scale_end);
lv_scale_set_angle_range(lvobj, 270);
lv_scale_set_rotation(lvobj, 135);
// create the needle
needle_obj = lv_line_create(lvobj);
lv_scale_set_line_needle_value(lvobj, needle_obj, 60, 0);
lv_obj_set_style_line_width(needle_obj, 6, LV_PART_MAIN);
lv_obj_set_style_line_rounded(needle_obj, true, LV_PART_MAIN);
//Colouring
static lv_style_t indicator_style;
lv_style_init(&indicator_style);
// Label style properties
lv_style_set_text_font(&indicator_style, LV_FONT_DEFAULT);
lv_style_set_text_color(&indicator_style, lv_palette_darken(LV_PALETTE_GREEN, 3));
// Major tick properties
lv_style_set_line_color(&indicator_style, lv_palette_darken(LV_PALETTE_GREEN, 3));
lv_style_set_width(&indicator_style, 10U); //Tick length
lv_style_set_line_width(&indicator_style, 2U); //Tick width
lv_obj_add_style(lvobj, &indicator_style, LV_PART_INDICATOR);
static lv_style_t minor_ticks_style;
lv_style_init(&minor_ticks_style);
lv_style_set_line_color(&minor_ticks_style, lv_palette_lighten(LV_PALETTE_GREEN, 2));
lv_style_set_width(&minor_ticks_style, 5U); //Tick length
lv_style_set_line_width(&minor_ticks_style, 2U); //Tick width
lv_obj_add_style(lvobj, &minor_ticks_style, LV_PART_ITEMS);
static lv_style_t main_line_style;
lv_style_init(&main_line_style);
// Main line properties
lv_style_set_arc_color(&main_line_style, lv_palette_darken(LV_PALETTE_GREEN, 3));
lv_style_set_arc_width(&main_line_style, 2U); //Tick width
lv_obj_add_style(lvobj, &main_line_style, LV_PART_MAIN);
}