LED widget local value problem

Important: unclear posts may not receive useful answers.

Before posting

  • Get familiar with Markdown to format and structure your post
  • Be sure to update lvgl from the latest version from the master branch.
  • Be sure you have checked the relevant part of the documentation.
  • If applicable use the Simulator to eliminate hardware related issues.

Delete this section if you read and applied the mentioned points.

Description

I set local values for two LEDs, but the values are not as intended.

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

Visual studio 2019

What LVGL version are you using?

7.10

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:
main.c (15.8 KB)

Screenshot and/or video

If possible, add screenshots and/or videos about the current state.
LVGL Simmulation

It would be helpful if you explained what exactly is “not as intended”.

1 Like

Hi jupeos

Green_led is “OK: %d” and red_led is “NG: %d”. Two LEDs are displayed as OK or NG at the same time.
Please refer to the code below.

sprintf(char_buff, “NG : %d”, 0);
lv_obj_set_style_local_value_str(led_red, LV_LED_PART_MAIN, LV_STATE_DEFAULT, char_buff);

sprintf(char_buff, “OK : %d”, 0);
lv_obj_set_style_local_value_str(led_green, LV_LED_PART_MAIN, LV_STATE_DEFAULT, char_buff);

Thank you for your interest.

I think it’s because you are using the same buffer (char_buff) for both.

I agree with @embeddedt. You need to make your buffers persistent beyond the scope of this function, too. From the style docs

value_str ( const char * ): Pointer to text to display. Only the pointer is saved! (Don’t use local variable with lv_style_set_value_str, instead use static, global or dynamically allocated data).

Solved using two different buffers.
thanks.