How to change sender->id?
baylf2000 opened this issue · 2 comments
I'm trying to work out how to modify the sender id as presented to the callback function. In the examples given, like the below, the method specifies a callback "textCall"...
ESPUI.text("Text Test:", &textCall, ControlColor::Alizarin, "a Text Field");
And in the examples, that callback contains a "Control" parameter with an id available as sender->id
.
void textCall(Control* sender, int type)
{
Serial.print("Text: ID: ");
Serial.print(sender->id);
Serial.print(", Value: ");
Serial.println(sender->value);
}
In my tests with multiple fields, it appears this value is dynamically generated, as each field contains a different id. My question is, are we able to set this in advance? I'd like to use a single callback for multiple fields, however I'd need a way to determine which field is calling the callback.
Never mind, I answered my own question. That id value is used internally for tying the html components to their values. We're supposed to use the void* userparameter.
Each instance of control has a unique id. Each control pointer is unique. You can keep a table of control pointers and search through it or you can keep a map of ID to some structure you have to track them.
Best is to use a lambda for each control type