diff --git a/examples/gui-generic-api/gui-generic-api.ino b/examples/gui-generic-api/gui-generic-api.ino index 51fee86..9449728 100644 --- a/examples/gui-generic-api/gui-generic-api.ino +++ b/examples/gui-generic-api/gui-generic-api.ino @@ -15,7 +15,10 @@ const char *ssid = "ESPUI"; const char *password = "espui"; const char *hostname = "espui"; +uint16_t status; uint16_t button1; +uint16_t millisLabelId; +uint16_t switchOne; void numberCall( Control* sender, int type ) { Serial.println( sender->value ); @@ -51,7 +54,7 @@ void buttonExample(Control *sender, int type) { switch (type) { case B_DOWN: Serial.println("Status: Start"); - ESPUI.updateControl("Status:", "Start"); + ESPUI.updateControlValue(status, "Start"); ESPUI.getControl(button1)->color = ControlColor::Carrot; ESPUI.updateControl(button1); @@ -59,7 +62,7 @@ void buttonExample(Control *sender, int type) { case B_UP: Serial.println("Status: Stop"); - ESPUI.updateControl("Status:", "Stop"); + ESPUI.updateControlValue(status, "Stop"); ESPUI.getControl(button1)->color = ControlColor::Peterriver; ESPUI.updateControl(button1); @@ -201,7 +204,7 @@ void setup(void) { Serial.print("IP address: "); Serial.println(WiFi.getMode() == WIFI_AP ? WiFi.softAPIP() : WiFi.localIP()); - ESPUI.addControl(ControlType::Label, "Status:", "Stop", ControlColor::Turquoise); + status = ESPUI.addControl(ControlType::Label, "Status:", "Stop", ControlColor::Turquoise); uint16_t select1 = ESPUI.addControl(ControlType::Select, "Select:", "", ControlColor::Alizarin, Control::noParent, &selectExample); @@ -211,12 +214,12 @@ void setup(void) { ESPUI.addControl(ControlType::Text, "Text Test:", "a Text Field", ControlColor::Alizarin, Control::noParent, &textCall); - ESPUI.addControl(ControlType::Label, "Millis:", "0", ControlColor::Emerald, Control::noParent); + millisLabelId = ESPUI.addControl(ControlType::Label, "Millis:", "0", ControlColor::Emerald, Control::noParent); 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); ESPUI.addControl(ControlType::PadWithCenter, "Pad with center", "", ControlColor::Sunflower, Control::noParent, &padExample); ESPUI.addControl(ControlType::Pad, "Pad without center", "", ControlColor::Carrot, Control::noParent, &padExample); - ESPUI.addControl(ControlType::Switcher, "Switch one", "", ControlColor::Alizarin, Control::noParent, &switchExample); + switchOne = ESPUI.addControl(ControlType::Switcher, "Switch one", "", ControlColor::Alizarin, Control::noParent, &switchExample); ESPUI.addControl(ControlType::Switcher, "Switch two", "", ControlColor::None, Control::noParent, &otherSwitchExample); ESPUI.addControl(ControlType::Slider, "Slider one", "30", ControlColor::Alizarin, Control::noParent, &slider); ESPUI.addControl(ControlType::Slider, "Slider two", "100", ControlColor::Alizarin, Control::noParent, &slider); @@ -252,7 +255,7 @@ void loop(void) { if (millis() - oldTime > 5000) { ESPUI.updateControlValue(millisLabelId, String(millis())); testSwitchState = !testSwitchState; - ESPUI.updateControlValue("Switch one", testSwitchState ? "1" : "0"); + ESPUI.updateControlValue(switchOne, testSwitchState ? "1" : "0"); oldTime = millis(); } diff --git a/examples/tabbedGui/tabbedGui.ino b/examples/tabbedGui/tabbedGui.ino index 423390a..973e13f 100644 --- a/examples/tabbedGui/tabbedGui.ino +++ b/examples/tabbedGui/tabbedGui.ino @@ -16,6 +16,9 @@ const char* password = "espui"; const char* hostname = "espui"; uint16_t button1; +uint16_t switchOne; +uint16_t status; +uint16_t millisLabelId; void numberCall( Control* sender, int type ) { Serial.println( sender->value ); @@ -49,7 +52,7 @@ void buttonExample( Control* sender, int type ) { switch ( type ) { case B_DOWN: Serial.println( "Status: Start" ); - ESPUI.updateControl( "Status:", "Start" ); + ESPUI.updateControlValue( status, "Start" ); ESPUI.getControl( button1 )->color = ControlColor::Carrot; ESPUI.updateControl( button1 ); @@ -57,7 +60,7 @@ void buttonExample( Control* sender, int type ) { case B_UP: Serial.println( "Status: Stop" ); - ESPUI.updateControl( "Status:", "Stop" ); + ESPUI.updateControlValue( status, "Stop" ); ESPUI.getControl( button1 )->color = ControlColor::Peterriver; ESPUI.updateControl( button1 ); @@ -203,7 +206,7 @@ void setup( void ) { uint16_t tab3 = ESPUI.addControl( ControlType::Tab, "Settings 3", "Settings 3" ); // shown above all tabs - ESPUI.addControl( ControlType::Label, "Status:", "Stop", ControlColor::Turquoise ); + status = ESPUI.addControl( ControlType::Label, "Status:", "Stop", ControlColor::Turquoise ); uint16_t select1 = ESPUI.addControl( ControlType::Select, "Select:", "", ControlColor::Alizarin, tab1, &selectExample ); ESPUI.addControl( ControlType::Option, "Option1", "Opt1", ControlColor::Alizarin, select1 ); @@ -218,7 +221,7 @@ void setup( void ) { ESPUI.addControl( ControlType::Button, "Other Button", "Press", ControlColor::Wetasphalt, tab1, &buttonExample ); ESPUI.addControl( ControlType::PadWithCenter, "Pad with center", "", ControlColor::Sunflower, tab2, &padExample ); ESPUI.addControl( ControlType::Pad, "Pad without center", "", ControlColor::Carrot, tab3, &padExample ); - ESPUI.addControl( ControlType::Switcher, "Switch one", "", ControlColor::Alizarin, tab3, &switchExample ); + switchOne = ESPUI.addControl( ControlType::Switcher, "Switch one", "", ControlColor::Alizarin, tab3, &switchExample ); ESPUI.addControl( ControlType::Switcher, "Switch two", "", ControlColor::None, tab3, &otherSwitchExample ); ESPUI.addControl( ControlType::Slider, "Slider one", "30", ControlColor::Alizarin, tab1, &slider ); ESPUI.addControl( ControlType::Slider, "Slider two", "100", ControlColor::Alizarin, tab3, &slider ); @@ -252,10 +255,10 @@ void loop( void ) { static bool switchi = false; if ( millis() - oldTime > 5000 ) { - ESPUI.updateControl( "Millis:", String( millis() ) ); + ESPUI.updateControlValue( millisLabelId, String( millis() ) ); switchi = !switchi; - ESPUI.updateControl( "Switch one", switchi ? "1" : "0" ); - + ESPUI.updateControlValue( switchOne, switchi ? "1" : "0" ); + oldTime = millis(); } }