Lv_textarea_set_max_length CREATING DUPLICATE INPUT

I need to take user input via textbox and save it to a variable. I have all this setup and working properly, but I NEED to set the max chars for input to 3. This is because I’m collecting IP address’ and each section must only take 3 chars. However, when I receive input (with max chars set to 3), the program creates a duplicate of the entered char.

For example, I will enter a “2” and I have my input printed to the console and saved to a variable. The outputted console data AND the saved variable value will be “22”. I have no idea why lv_testarea_set_max_length creates duplicates. Can someone please help me?

Hi @Tomas_Giannini

Please can you post a code sample to reproduce the problem.

Kind Regards,

Pete

funcCall maxChar

func

As you can see, I have a callback function line and also the max char line. Then when the callback function is calledv(Input_EventHandler), I figure out which input box was chosen and then print the data typed in that box to the console, in the next function call (concat). If i were to type “a”, the console will output “aa”

I know this is a lots of functions within functions, but my problem was still occurring when I had the print(str) in the first function call.

Hi @Tomas_Giannini,

I have had a quick look at this and so far I can see that the LV_EVENT_INSERT event is firing twice for each keyboard button entry, I expect this is what is causing your problem… To be honest right now I am not able to look into this further as I have other commitments. If you have time yourself it might be worth trying to track down why the event is happening twice, it does seem like a bug in the library. I will ask @embeddedt and @kisvegabor if they have anything to add here?

Kind Regards,

Pete

Looks like a bug in LVGL.

Relevant lines: https://github.com/lvgl/lvgl/blob/557342cc088424c48894e4acffccf40801663ddf/src/lv_widgets/lv_textarea.c#L337-L358

lv_textarea_add_text fires LV_EVENT_INSERT itself. Then, it can sometimes call itself again or call lv_textarea_add_char, both of which can fire LV_EVENT_INSERT again.

A generic workaround is to loop over your string and call lv_textarea_add_char(ta, _lv_txt_unicode_to_encoded(c)) for each character.

How would the workaround work though if the data being entered is duplicated? If I typed “abc” into a textbox and need to save it to a variable, it would be shown as “aabbcc”, so how would I be able to manually parse the string AND add it into the variable manually if the data I have to work with right off the bat is “aabbcc”?

Thank-you for trying to help me out.

Try the embeddedt-patch-1 branch.

So is the LVGL patched? Should the max char function work now without the problem I was having?

Hi @Tomas_Giannini,

@embeddedt & @kisvegabor have done some work on this branch, so would you be able to try it and let us know if all is well please? Then I am sure it can be added to the master branch.

Kind Regards,

Pete

Honestly, I was given a code project/solution for Visual Studio from my boss and I have been playing around with that. I don’t even know how to test what you’re asking me to test. Sorry for sounding clueless.

I figured out a workaround solution, so my program works decently. If you figure out that the max char function works properly, without firing LV_EVENT_INSERT twice, can you let me know?

Thank-you

The pull request was merged into master, so that and the next release of LVGL will have the fix included.

2 Likes