s00500 / ESPUI

A simple web user interface library for ESP32 and ESP8266

Home Page:https://valencia.lbsfilm.at/midterm-presentation/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Values from all controls on the page/Accessing a control by name

az-z opened this issue · comments

commented

I apologize for filing so many tickets. I file 2 questions in a single ticket.

  1. Is there a way to cycle thru all existing controls and obtain their values?
    e.g I have 4 numbers, 3 text, and one option controls, there is only one button.
    to obtain values from all these controls i can think of 2 methods:
    a. write 4+3+1 callbacks
    b. write one callback for a button and cycle thru all controls' values.
    how can I accomplish "b" without manually listing all controls?

  2. in a callback, how can I access a particular control? is there a name? I see there is some kind of id, but not sure what does it mean of how it can be used.

1: since arduino is single threaded one simple solution would be to use global variables and store values in each callback

2: when you create a control you get back it's index basically. This can be used to identify the control. To get parameters of this control use the getControl function first and then use the pointer to the control to retrieve it's parameters
eg:
Serial.println(ESPUI.getControl(switchOne)->value);

commented

@s00500 Lukas, thank you for a quick reply.
the getControl returns Control :
Control *getControl(uint16_t id);

is there a way to use it in the "case" so i can have one callback function instead of 8 ?

you mean a switch statement ? You can switch on the ESPUI.getControl(switchOne)->type for the enum defined in ESPUI.h

roughly like
switch(ESPUI.getControl(switchOne)->type) {
case ControlType::Button:
break;
}

Try to read the code in ESPUI.h and ESPUI.cpp and learn from it ;-)

commented

yes, i saw that technique in the examples.
i think the only way is to have an array of ids and in the callback go over the array and read associated values from controls..
thank you Lukas!