Trying to build a circular scale with needle line using EEZ Studio as start point

Description

I’m relatively new to EEZ Studio and lvgl but have a working development system and can built operational UI’s and very pleased to have found both products!

I’m trying to get a working scale and line needle defined in EEZ Studio to operate as a simple meter.

What MCU/Processor/Board and compiler are you using?

I’m using VSCode/PlatformIO on Mac and uploading to Elecrow/CrowPanel 5.0" display.

What LVGL version are you using?

v9 having started with v8 and used meter.

What do you want to achieve?

Initially a simple round scale using a line/needle pointer.

What have you tried so far?

I’ve tried to incorporate the lv_example_scale_6 code into my ecosystem, as a test, with some success (seemed to run into memory problems with layouts?) but I just cannot understand why my needle doesn’t work based on the EEZ generated code.

On the display I see the line as initially placed in EEZStudio but on first call to update it jumps to the top left of the scale box and never moves.

Code to reproduce

This is the code snippet generated by EEZ Studio to build the scale and line on the screen

            // TestScale
            lv_obj_t *obj = lv_scale_create(parent_obj);
            objects.test_scale = obj;
            lv_obj_set_pos(obj, 50, 36);
            lv_obj_set_size(obj, 240, 240);
            lv_scale_set_mode(obj, LV_SCALE_MODE_ROUND_INNER);
            lv_scale_set_range(obj, 0, 60);
            lv_scale_set_total_tick_count(obj, 61);
            lv_scale_set_major_tick_every(obj, 5);
            lv_scale_set_label_show(obj, true);
            lv_obj_set_style_length(obj, 5, LV_PART_ITEMS | LV_STATE_DEFAULT);
            lv_obj_set_style_length(obj, 10, LV_PART_INDICATOR | LV_STATE_DEFAULT);
            {
                lv_obj_t *parent_obj = obj;
                {
                    // TestNeedle
                    lv_obj_t *obj = lv_line_create(parent_obj);
                    objects.test_needle = obj;
                    lv_obj_set_pos(obj, 120, 120);
                    lv_obj_set_size(obj, 75, 5);
                    lv_obj_set_style_line_width(obj, 5, LV_PART_MAIN | LV_STATE_DEFAULT);
                    lv_obj_set_style_line_color(obj, lv_color_hex(0xffe10b0b), LV_PART_MAIN | LV_STATE_DEFAULT);
                    lv_obj_set_style_bg_opa(obj, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
                    lv_obj_set_style_bg_color(obj, lv_color_hex(0xff35c408), LV_PART_MAIN | LV_STATE_DEFAULT);
                }
            }

and then I’m calling this to update the needle

int32_t sTickValue;
...
lv_scale_set_line_needle_value(objects.test_scale, objects.test_needle, 75, sTickValue);

I feel stuck on what to try next.

Perhaps you can use lv_obj_t *obj = lv_line_create(objects.test_scale); instead of lv_obj_t *obj = lv_line_create(parent_obj);.

Thank you for your suggestion. I want to avoid changing the code generated by EEZ Studio but can confirm your suggestion didn’t change behaviour.

Did you find a solution? I have a similar problem with updating the needle.

This was a while ago but fortunately I put some comments in my code but this may or may not be the problem you are having?

EEZStudio was setting a size attribute for the needle line and I don’t think there is any way of stopping it doing that. I had to save the needle line attributes (width & colour) I wanted to preserve, then remove style info and re-set the attributes back on the line. This is what I am doing (obj is the needle line):

		// Save line width & colour
		int32_t width = lv_obj_get_style_line_width(obj, LV_PART_MAIN | LV_STATE_DEFAULT);
		lv_color_t colour = lv_obj_get_style_line_color(obj, LV_PART_MAIN | LV_STATE_DEFAULT);
		int32_t w = lv_obj_get_width(obj);
		int32_t h = lv_obj_get_height(obj);

		// We assume required dimensions set in EEZ Studio, so utilise these to
		// determine needle length for updates
		mNeedleLength = std::max(w, h);

		// Remove position & size info set by EEZ Studio
		// otherwise needle line doesn't appear to work
		lv_obj_remove_style(obj, NULL, LV_PART_MAIN);

		// Re-establish width & colour
		lv_obj_set_style_line_width(obj, width, LV_PART_MAIN | LV_STATE_DEFAULT);
		lv_obj_set_style_line_color(obj, colour, LV_PART_MAIN | LV_STATE_DEFAULT);

Hope this helps.