mirror of
https://github.com/s00500/ESPUI.git
synced 2024-11-21 17:40:54 +00:00
Added an example for using the new extended parameter callback
This commit is contained in:
parent
1419b2dec0
commit
511840fa97
@ -49,6 +49,7 @@ void getTimeCallback(Control *sender, int type);
|
||||
void graphAddCallback(Control *sender, int type);
|
||||
void graphClearCallback(Control *sender, int type);
|
||||
void randomString(char *buf, int len);
|
||||
void extendedCallback(Control* sender, int type, void* param);
|
||||
|
||||
//UI handles
|
||||
uint16_t wifi_ssid_text, wifi_pass_text;
|
||||
@ -81,7 +82,7 @@ void setUpUI() {
|
||||
auto maintab = ESPUI.addControl(Tab, "", "Basic controls");
|
||||
|
||||
ESPUI.addControl(Separator, "General controls", "", None, maintab);
|
||||
ESPUI.addControl(Button, "Button", "Button 1", Alizarin, maintab, generalCallback);
|
||||
ESPUI.addControl(Button, "Button", "Button 1", Alizarin, maintab, extendedCallback, (void*)19);
|
||||
mainLabel = ESPUI.addControl(Label, "Label", "Label text", Emerald, maintab, generalCallback);
|
||||
mainSwitcher = ESPUI.addControl(Switcher, "Switcher", "", Sunflower, maintab, generalCallback);
|
||||
|
||||
@ -360,7 +361,23 @@ void generalCallback(Control *sender, int type) {
|
||||
Serial.println(sender->value);
|
||||
}
|
||||
|
||||
|
||||
// Most elements in this test UI are assigned this generic callback which prints some
|
||||
// basic information. Event types are defined in ESPUI.h
|
||||
// The extended param can be used to hold a pointer to additional information
|
||||
// or for C++ it can be used to return a this pointer for quick access
|
||||
// using a lambda function
|
||||
void extendedCallback(Control* sender, int type, void* param)
|
||||
{
|
||||
Serial.print("CB: id(");
|
||||
Serial.print(sender->id);
|
||||
Serial.print(") Type(");
|
||||
Serial.print(type);
|
||||
Serial.print(") '");
|
||||
Serial.print(sender->label);
|
||||
Serial.print("' = ");
|
||||
Serial.println(sender->value);
|
||||
Serial.println(String("param = ") + String((int)param));
|
||||
}
|
||||
|
||||
void setup() {
|
||||
randomSeed(0);
|
||||
|
@ -55,8 +55,9 @@ void buttonCallback(Control* sender, int type)
|
||||
}
|
||||
}
|
||||
|
||||
void buttonExample(Control* sender, int type)
|
||||
void buttonExample(Control* sender, int type, void* param)
|
||||
{
|
||||
Serial.println(String("param: ") + String(int(param)));
|
||||
switch (type)
|
||||
{
|
||||
case B_DOWN:
|
||||
@ -210,7 +211,8 @@ void setup(void)
|
||||
}
|
||||
#else
|
||||
uint32_t chipid = ESP.getChipId();
|
||||
#endif char ap_ssid[25];
|
||||
#endif
|
||||
char ap_ssid[25];
|
||||
snprintf(ap_ssid, 26, "ESPUI-%08X", chipid);
|
||||
WiFi.softAP(ap_ssid);
|
||||
|
||||
@ -249,7 +251,7 @@ void setup(void)
|
||||
button1 = ESPUI.addControl(
|
||||
ControlType::Button, "Push Button", "Press", ControlColor::Peterriver, Control::noParent, &buttonCallback);
|
||||
ESPUI.addControl(
|
||||
ControlType::Button, "Other Button", "Press", ControlColor::Wetasphalt, Control::noParent, &buttonExample);
|
||||
ControlType::Button, "Other Button", "Press", ControlColor::Wetasphalt, Control::noParent, &buttonExample, (void*)19);
|
||||
ESPUI.addControl(
|
||||
ControlType::PadWithCenter, "Pad with center", "", ControlColor::Sunflower, Control::noParent, &padExample);
|
||||
ESPUI.addControl(ControlType::Pad, "Pad without center", "", ControlColor::Carrot, Control::noParent, &padExample);
|
||||
|
@ -60,8 +60,9 @@ void buttonCallback(Control* sender, int type)
|
||||
}
|
||||
}
|
||||
|
||||
void buttonExample(Control* sender, int type)
|
||||
void buttonExample(Control* sender, int type, void* param)
|
||||
{
|
||||
Serial.println(String("param: ") + String(int(param)));
|
||||
switch (type)
|
||||
{
|
||||
case B_DOWN:
|
||||
@ -227,7 +228,7 @@ void setup(void)
|
||||
statusLabelId = ESPUI.label("Status:", ControlColor::Turquoise, "Stop");
|
||||
millisLabelId = ESPUI.label("Millis:", ControlColor::Emerald, "0");
|
||||
ESPUI.button("Push Button", &buttonCallback, ControlColor::Peterriver, "Press");
|
||||
ESPUI.button("Other Button", &buttonExample, ControlColor::Wetasphalt, "Press");
|
||||
ESPUI.button("Other Button", &buttonExample, ControlColor::Wetasphalt, "Press", (void*)19);
|
||||
ESPUI.padWithCenter("Pad with center", &padExample, ControlColor::Sunflower);
|
||||
ESPUI.pad("Pad without center", &padExample, ControlColor::Carrot);
|
||||
testSwitchId = ESPUI.switcher("Switch one", &switchExample, ControlColor::Alizarin, false);
|
||||
|
@ -54,8 +54,9 @@ void buttonCallback(Control* sender, int type)
|
||||
}
|
||||
}
|
||||
|
||||
void buttonExample(Control* sender, int type)
|
||||
void buttonExample(Control* sender, int type, void* param)
|
||||
{
|
||||
Serial.println(String("param: ") + String(int(param)));
|
||||
switch (type)
|
||||
{
|
||||
case B_DOWN:
|
||||
@ -251,7 +252,7 @@ void setup(void)
|
||||
ESPUI.addControl(ControlType::Label, "Millis:", "0", ControlColor::Emerald, tab1);
|
||||
button1 = ESPUI.addControl(
|
||||
ControlType::Button, "Push Button", "Press", ControlColor::Peterriver, tab1, &buttonCallback);
|
||||
ESPUI.addControl(ControlType::Button, "Other Button", "Press", ControlColor::Wetasphalt, tab1, &buttonExample);
|
||||
ESPUI.addControl(ControlType::Button, "Other Button", "Press", ControlColor::Wetasphalt, tab1, &buttonExample, (void*)19);
|
||||
ESPUI.addControl(ControlType::PadWithCenter, "Pad with center", "", ControlColor::Sunflower, tab2, &padExample);
|
||||
ESPUI.addControl(ControlType::Pad, "Pad without center", "", ControlColor::Carrot, tab3, &padExample);
|
||||
switchOne = ESPUI.addControl(ControlType::Switcher, "Switch one", "", ControlColor::Alizarin, tab3, &switchExample);
|
||||
|
@ -60,8 +60,9 @@ void buttonCallback(Control* sender, int type)
|
||||
}
|
||||
}
|
||||
|
||||
void buttonExample(Control* sender, int type)
|
||||
void buttonExample(Control* sender, int type, void* param)
|
||||
{
|
||||
Serial.println(String("param: ") + String(int(param)));
|
||||
switch (type)
|
||||
{
|
||||
case B_DOWN:
|
||||
@ -228,7 +229,7 @@ void setup(void)
|
||||
statusLabelId = ESPUI.label("Status:", ControlColor::Turquoise, "Stop");
|
||||
millisLabelId = ESPUI.label("Millis:", ControlColor::Emerald, "0");
|
||||
ESPUI.button("Push Button", &buttonCallback, ControlColor::Peterriver, "Press");
|
||||
ESPUI.button("Other Button", &buttonExample, ControlColor::Wetasphalt, "Press");
|
||||
ESPUI.button("Other Button", &buttonExample, ControlColor::Wetasphalt, "Press", (void*)19);
|
||||
ESPUI.padWithCenter("Pad with center", &padExample, ControlColor::Sunflower);
|
||||
ESPUI.pad("Pad without center", &padExample, ControlColor::Carrot);
|
||||
testSwitchId = ESPUI.switcher("Switch one", &switchExample, ControlColor::Alizarin, false);
|
||||
|
Loading…
Reference in New Issue
Block a user