From 37935bbcea0f6006bb8854700723211065127fc9 Mon Sep 17 00:00:00 2001 From: Hieromon Ikasamo Date: Fri, 4 Jan 2019 05:54:31 +0900 Subject: [PATCH] Under the work of v0.9.7 documentation --- mkdocs/acelements.md | 78 +++++++++++++++++++++++++---- mkdocs/achandling.md | 7 ++- mkdocs/acintro.md | 114 +++++++++++++++++++++++++++++++++++++----- mkdocs/acjson.md | 4 +- mkdocs/api.md | 2 +- mkdocs/apiaux.md | 8 ++- mkdocs/apiconfig.md | 5 +- mkdocs/apielements.md | 111 ++++++++++++++++++++++++++++++++++++++++ 8 files changed, 301 insertions(+), 28 deletions(-) create mode 100644 mkdocs/apielements.md diff --git a/mkdocs/acelements.md b/mkdocs/acelements.md index 45fa474..b16e2ed 100644 --- a/mkdocs/acelements.md +++ b/mkdocs/acelements.md @@ -2,23 +2,77 @@ Representative HTML elements for making the custom Web page are provided as AutoConnectElements. -- AutoConnectButton: Labeled action button -- AutoConnectCheckbox: Labeled checkbox -- AutoConnectElement: General tag -- AutoConnectInput: Labeled text input box -- AutoConnectRadio: Labeled radio button -- AutoConnectSelect: Selection list -- AutoConnectSubmit: Submit button -- AutoConnectText: Style attributed text +- [AutoConnectButton](#autoconnectbutton): Labeled action button +- [AutoConnectCheckbox](#autoconnectcheckbox): Labeled checkbox +- [AutoConnectElement](#autoconnectelement-a-basic-class-of-elements): General tag +- [AutoConnectInput](#autoconnectinput): Labeled text input box +- [AutoConnectRadio](#autoconnectradio): Labeled radio button +- [AutoConnectSelect](#autoconnectselect): Selection list +- [AutoConnectSubmit](#autoconnectsubmit): Submit button +- [AutoConnectText](#autoconnecttext): Style attributed text Each element has a common attribute and its own attributes. ## Layout on custom Web page -You can specify the direction to arrange the radio buttons as **AutoConnectRadio** vertically or horizontally. The checkbox as **AutoConnectCheckbox** is not divided in a line by each element. In order to arrange vertically, it is necessary to clearly indicate the **<br>** tag. Other elements are aligned vertically. This basic layout depends on the CSS of the AutoConnect menu so it can not be changed drastically. +You can specify the direction to arrange the radio buttons as [**AutoConnectRadio**](#autoconnectradio) vertically or horizontally. The checkbox as [**AutoConnectCheckbox**](#autoconnectcheckbox) is not divided in a line by each element. In order to arrange vertically, it is necessary to clearly indicate the **<br>** tag. Other elements are arranged vertically in the order of addition to AutoConnectAux. This basic layout depends on the CSS of the AutoConnect menu so it can not be changed drastically. ## AutoConnectElement - A basic class of elements +AutoConnectElement is a base class for other element classes and has common attributes for all elements. It can also be used as a [variant](#variant-for-autoconnectelements) of each element. The following items are attributes that AutoConnectElement has and are common to other elements. + +### name + +Every element has a name. **Name** is the String data type. To access its element in the sketches you can identify by the name. Its method is useful for loading elements in JSON. In the load function of AutoConnectElement(s) described [**later**](acjson.md), these objects are not created in advance by sketches. Therefore, access to the attribute of that element by name as follows: + +```cpp hl_lines="4 10" +AutoConnectAux customPage("Custom page", "/custom_page"); +const char ELEMENT_TEXT[] PROGMEM = R"( +{ + "name": "text1", + "type": "ACText", + "value": "Hello, world" +} +)"; +customPage.loadElement(ELEMENT_TEXT); +AutoConnectText& text1 = customPage.getElement("text1"); +text1.style = "text-align:center;color:#2f4f4f;" +``` + +The above example accesses the *text1* element which loaded from JSON using AutoConnectAux's [**getElement**](apiaux.md#getelement) function by name and sets the [**style**](#style) attribute. + +### value + +**Value** is the source of the HTML code generated with the element and its data type is String. Characteristics of Value vary depending on the element. The value of AutoConnectElement is native HTML code. A string of value is output as HTML as it is. + +### type + +**Type** indicates the type of the element and represented as the *ACElement_t* enumeration type in the sketch. Since AutoConnectElement also acts as a variant of other elements, it can be applied to handle elements collectively. At that time, the type can be referred to by the [**typeOf()**](apielements.md#typeof) function. The following example changes the font color of all [AutoConnectText](#autoconnecttext) elements of a custom web page to gray. + +```cpp hl_lines="5" +AutoConnectAux customPage; + +AutoConnectElementVT& elements = customPage.getElements(); +for (AutoConnectElement& elm : elememts) { + if (elm.typeOf() == AC_Text) { + AutoConnectText& text = reinterpret_cast(elm); + text.style = "color:gray;"; + } +} +``` + +The enumerators for *ACElement_t* are as follows: + +- AutoConnetButton: **AC_Button** +- AutoConnectCheckbox: **AC_Checkbox** +- AutoConnectElement: **AC_Element** +- AutoConnectInput: **AC_Input** +- AutoConnectRadio: **AC_Radio** +- AutoConnectSelect: **AC_Select** +- AutoConnectSubmit: **AC_Submit** +- AutoConnectText: **AC_Text** +- Uninitialized element: **AC_Unknown** + ## AutoConnectButton ## AutoConnectCheckbox @@ -33,3 +87,9 @@ You can specify the direction to arrange the radio buttons as **AutoConnectRadio ## AutoConnectText +## How to coding for the elements + +### Variant for AutoConnectElements + + + diff --git a/mkdocs/achandling.md b/mkdocs/achandling.md index 860d924..a891e30 100644 --- a/mkdocs/achandling.md +++ b/mkdocs/achandling.md @@ -1,7 +1,10 @@ - +## Handing AutoConnectElements in the sketches ## loading and saving AutoConnectElements -## page transition +## Page transition ## Parameter handling + +WebServer.args, PageArgument +Handling in 'on' handler \ No newline at end of file diff --git a/mkdocs/acintro.md b/mkdocs/acintro.md index 61871c8..0dd23ac 100644 --- a/mkdocs/acintro.md +++ b/mkdocs/acintro.md @@ -31,20 +31,9 @@ You can create multiple custom pages, integrate them into the AutoConnect menu,
    -
  • False is specified as the third parameter of 'aux2' in the above code. The third parameter of the AutoConnectAux constructor is an indicator of whether it's shown to the AutoConnect menu. Right animation is the execution result of the above code. You will see that the custom web page's menu is displayed only in the last two lines. Because 'aux1' and 'aux2' in this example have a pair of page transitions. The sketch of this animation is written to transition to 'aux2' by the utility of the AutoConnectSubmit element owned by 'aux1'.2
    An 'aux2' page transitions only from the submit button of 'aux1'. It is a page that saves the parameters you entered on the previous page as shown in mqttRSSI in the library example. It is to want to hide 'aux2' from AutoConnect menu lines. The third parameter of the AutoConnectAux constructor is used for this purpose.
  • +
  • False is specified as the third parameter of 'aux2' in the above code. The third parameter of the AutoConnectAux constructor is an indicator of whether it's shown to the AutoConnect menu. Right animation is the execution result of the above code. You will see that the custom web page's menu is displayed only in the last two lines. Because 'aux1' and 'aux2' in this example have a pair of page transitions. The sketch of this animation is written to transition to 'aux2' by the utility of the AutoConnectSubmit element owned by 'aux1'.2
    An 'aux2' page transitions only from the submit button of 'aux1'. It is a page that saves the parameters you entered on the previous page as shown in mqttRSSI in the library example. It is to want to hide 'aux2' from AutoConnect menu lines. The third parameter of the AutoConnectAux constructor is used for this purpose.
-## Basic steps to use custom Web pages - -So, the basic procedure is as follows. - -1. Create or define AutoConnectAux. -2. Create or define [AutoConnectElement(s)](acelements.md). -3. Add [AutoConnectElement(s)](acelements.md) to AutoConnectAux. -4. Create more AutoConnectAux containing [AutoConnectElement(s)](acelements.md), if necessary. -5. Join prepared AutoConnectAux(s) to [AutoConnect](api.md#autoconnect-api). -6. Invoke [AutoConnect::begin()](api.md#begin). - [^2]: The sketch is actually this: ```cpp @@ -75,6 +64,107 @@ So, the basic procedure is as follows. } ``` +## Basic steps to use custom Web pages + +So, the basic procedure is as follows. + +1. Create or define AutoConnectAux. +2. Create or define [AutoConnectElement(s)](acelements.md). +3. Add [AutoConnectElement(s)](acelements.md) to AutoConnectAux. +4. Create more AutoConnectAux containing [AutoConnectElement(s)](acelements.md), if necessary. +5. Join prepared AutoConnectAux(s) to [AutoConnect](api.md#join). +6. Invoke [AutoConnect::begin()](api.md#begin). + +## Write the custom Web page with JSON + +You can also write the custom Web page in JSON without using sketch codes.[^3] It is possible to describe the entire page in JSON and can be described for each element also. The JSON description can be saved in SPIFFS or SD and read using AutoConnect's [**load**](api.md#load) function. If you take this approach, you can further reduce the above basic steps. However, this method consumes a lot of memory. +The following JSON code and sketch will execute the custom Web page as the example in the above figure. That is, the sketch of this code and footnote[^2] is equivalent. + +**custom_page.json** +```json +[ + { + "title": "MQTT Setting", + "uri": "/mqtt_setting", + "menu": true, + "element": [ + { + "name": "header", + "type": "ACText", + "value": "MQTT broker settings" + }, + { + "name": "caption1", + "type": "ACText", + "value": "Publishing the WiFi..." + }, + { + "name": "save", + "type": "ACSubmit", + "value": "SAVE", + "uri": "/mqtt_save" + } + ] + }, + { + "title": "MQTT Setting", + "uri": "/mqtt_save", + "menu": false, + "element": [ + { + "name": "caption2", + "type": "ACText", + "value": "Save parameters" + }, + { + "name": "start", + "type": "ACSubmit", + "value": "START", + "uri": "/mqtt_start" + } + ] + }, + { + "title": "MQTT Start", + "uri": "/mqtt_start", + "menu": true, + "element": [] + } +] +``` + +**The sketch** +```cpp hl_lines="15 16" +#include +#include +#include +#include + +AutoConnect portal; + +void setup() { + delay(1000); + Serial.begin(115200); + Serial.println(); + + SPIFFS.begin(); + + File page = SPIFFS.open("/custom_page.json", "r"); + portal.load(page); + + page.close(); + SPIFFS.end(); + + portal.begin(); +} + +void loop() { + portal.handleClient(); +} +``` + +[^3]: Installation of the [ArduinoJson](https://github.com/bblanchon/ArduinoJson) v.5.13.4 library is required. +