Obtain the value (text string) in a Function of the TextArea that the Keyboard populates
What have you tried so far?
Tried several things, but this just produces an empty string. scrAnimationStartTimeEntry2 is the name of the TextArea widget that’s receiving the characters from the keyboard.
Thank you! That got me on the right track. I was thrown off because I was getting build errors without putting the TextArea name in quotes. Turns out that I needed to preceed the TextArea name with “ui_”. Once I removed the quotes, like in your example above, and added “ui_” preceeding the name, it works fine now. Thank you.
I’m using the same code as the previous person but I’m not having the same amount of success.
// Define as global variable, since I’ll be using it in other functions
const char *txt = “”; // Initialize with an empty string
void getValue(lv_event_t *e) {
txt = lv_textarea_get_text(ui_FlowRate);
Serial.print("User input: ");
Serial.println(txt);
// I’ve also tried flushing it to no avail
}
I’ve tried printing to the serial monitor just for debugging purposes, my real end goal is to pass it to other functions such as:
void volumeDispense(lv_event_t *e) {
// Concatenate "D, " with the user input
char commandToSend[20]; // Adjust the size as needed
snprintf(commandToSend, sizeof(commandToSend), “D, %s”, txt);
//snprintf(commandToSend, sizeof(commandToSend), “D, 150”); This was just to text that the function indeed works.
Any help would be greatly appreciated, thank you for your time
Edit:
I forgot to mention, it does print to the serial monitor, after about ten minutes, whereas I would like for it to print immediately.
This should work fine immediately. Maybe there’s some problem with your background processes/threads or serial link that causes that much delay. As a test/troubleshooting step you can try setting a label-widget to the obtained txt with something like lv_label_set_text(ui_Label, txt) instead of putting the result to the console, it should appear/update fast on the screen if you call lv_task_handler frequently enough (in max. 5…20ms period). And if that works fine, you can use txt similarly in other function as well, according to your end goal. (Or if it’s only needed at that single place, you can even use the lv_textarea_get_text(ui_Flowrate) result directly locally in that callback, avoiding the need for the global variable.)
That sounds like an interesting workaround I’ll be sure to try that! The serial monitor wasn’t all that important anyway, just using it for debugging. I appreciate the speedy response, however I found another work around. I think they issue was that I was setting the txt = lv_textarea_get_text(ui_FlowRate); in the wrong place; I had it in the events file with the rest of the functions rather than in the main UI.C file. This still doesn’t print it to the serial, but I’m able to call the txt and use it, which is enough for my purposes.
Thank you so much for your time!
Lazaro
P.S. For those in a similar situation, if in the ui_events.c file you get errors about the string variable being out of bounds: make sure to define it as an extern in the ui.h, this should about do it:) (i.e. extern char* txt;)
It’s better avoiding modification of ui.h and other exported files (except maybe ui_events.c) because on a next export from SquareLine Studio you’ll lose those changes. YMMV.