diff --git a/mkdocs/datatips.md b/mkdocs/datatips.md index abbb546..e104d38 100644 --- a/mkdocs/datatips.md +++ b/mkdocs/datatips.md @@ -14,6 +14,10 @@ Use [int()](https://www.arduino.cc/reference/en/language/variables/conversion/in AutoConnectInput& input = aux.getElement("INPUT"); int value = input.value.toInt(); ``` +You can shorten it and write as like: +```cpp +int value = aux["INPUT"].value.toInt(); +``` ### Float @@ -23,6 +27,10 @@ Use [float()](https://www.arduino.cc/reference/en/language/variables/conversion/ AutoConnectInput& input = aux.getElement("INPUT"); float value = input.value.toFloat(); ``` +You can shorten it and write as like: +```cpp +float value = aux["INPUT"].value.toFloat(); +``` ### Date & Time @@ -36,7 +44,7 @@ The easiest way is to use the [Arduino Time Library](https://www.pjrc.com/teensy time_t tm; int Year, Month, Day, Hour, Minute, Second; -AutoConnectInput& input = aux.getElement("INPUT"); +AutoConnectInput& input = aux.["INPUT"].as(); sscanf(input.value.c_str(), "%d-%d-%d %d:%d:%d", &Year, &Month, &Day, &Hour, &Minute, &Second); tm.Year = CalendarYrToTm(Year); tm.Month = Month; @@ -52,7 +60,7 @@ To convert a String to an IP address, use **IPAddress::fromString**. To stringiz ```cpp IPAddress ip; -AutoConnectInput& input aux.getElement("INPUT"); +AutoConnectInput& input aux["INPUT"].as(); ip.fromString(input.value); input.value = ip.toString(); ``` @@ -108,9 +116,9 @@ static const char input_page[] PROGMEM = R"raw( AutoConnect portal; String checkIPAddress(AutoConnectAux& aux, PageArgument& args) { - AutoConnectAux* input_page = portal.aux("/"); - AutoConnectInput& ipaddress = input_page->getElement("ipaddress"); - AutoConnectText& result = aux.getElement("result"); + AutoConnectAux& input_page = *portal.aux("/"); + AutoConnectInput& ipaddress = input_page["ipaddress"].as(); + AutoConnectText& result = aux["result"].as(); if (ipaddress.isValid()) { result.value = "IP Address " + ipaddress.value + " is OK.";