parent
ad07e1b448
commit
d281bb33e7
@ -0,0 +1,103 @@ |
||||
/**
|
||||
* Predefined AutoConnect configuration parameters. |
||||
* @file AutoConnectDefs.h |
||||
* @author hieromon@gmail.com |
||||
* @version 0.9.7 |
||||
* @date 2018-11-17 |
||||
* @copyright MIT license. |
||||
*/ |
||||
|
||||
#ifndef _AUTOCONNECTDEFS_H_ |
||||
#define _AUTOCONNECTDEFS_H_ |
||||
|
||||
// Uncomment the following AC_DEBUG to enable debug output.
|
||||
#define AC_DEBUG |
||||
|
||||
// Debug output destination can be defined externally with AC_DEBUG_PORT
|
||||
#ifndef AC_DEBUG_PORT |
||||
#define AC_DEBUG_PORT Serial |
||||
#endif // !AC_DEBUG_PORT
|
||||
#ifdef AC_DEBUG |
||||
#define AC_DBG(...) do {AC_DEBUG_PORT.print("[AC] "); AC_DEBUG_PORT.printf( __VA_ARGS__ );} while (0) |
||||
#else |
||||
#define AC_DBG(...) |
||||
#endif // !AC_DEBUG
|
||||
|
||||
// Indicator to specify that AutoConnectAux handles elements with JSON.
|
||||
#define AUTOCONNECT_USE_JSON |
||||
|
||||
// Predefined parameters
|
||||
// SSID that Captive portal started.
|
||||
#ifndef AUTOCONNECT_APID |
||||
#if defined(ARDUINO_ARCH_ESP8266) |
||||
#define AUTOCONNECT_APID "esp8266ap" |
||||
#elif defined(ARDUINO_ARCH_ESP32) |
||||
#define AUTOCONNECT_APID "esp32ap" |
||||
#endif // !ARDUINO_ARCH_ESP8266
|
||||
#endif // !AUTOCONNECT_APID
|
||||
|
||||
// Password that Captive portal started.
|
||||
#ifndef AUTOCONNECT_PSK |
||||
#define AUTOCONNECT_PSK "12345678" |
||||
#endif // !AUTOCONNECT_PSK
|
||||
|
||||
#ifndef AUTOCONNECT_AP_IP |
||||
#define AUTOCONNECT_AP_IP 0x01F4A8C0 //*< 192.168.244.1 */
|
||||
#endif // !AUTOCONNECT_AP_IP
|
||||
#ifndef AUTOCONNECT_AP_GW |
||||
#define AUTOCONNECT_AP_GW 0x01F4A8C0 //*< 192.168.244.1 */
|
||||
#endif // !AUTOCONNECT_AP_GW
|
||||
#ifndef AUTOCONNECT_AP_NM |
||||
#define AUTOCONNECT_AP_NM 0x00FFFFFF //*< 255.255.255.0 */
|
||||
#endif // !AUTOCONNECT_AP_NM
|
||||
|
||||
// AutoConnect menu root path
|
||||
#ifndef AUTOCONNECT_URI |
||||
#define AUTOCONNECT_URI "/_ac" |
||||
#endif // !AUTOCONNECT_URI
|
||||
|
||||
// Root URI of home path prepared by user sketch
|
||||
#ifndef AUTOCONNECT_HOMEURI |
||||
#define AUTOCONNECT_HOMEURI "/" |
||||
#endif // !AUTOCONNECT_HOMEURI
|
||||
|
||||
// AutoConnect menu title
|
||||
#ifndef AUTOCONNECT_MENU_TITLE |
||||
#define AUTOCONNECT_MENU_TITLE "AutoConnect" |
||||
#endif // !AUTOCONNECT_MENU_TITLE
|
||||
#define AUTOCONNECT_MENU_TITLE_CONNETED "Connected" |
||||
|
||||
// URIs of AutoConnect menu collection
|
||||
#define AUTOCONNECT_URI_CONFIG AUTOCONNECT_URI "/config" |
||||
#define AUTOCONNECT_URI_CONNECT AUTOCONNECT_URI "/connect" |
||||
#define AUTOCONNECT_URI_RESULT AUTOCONNECT_URI "/result" |
||||
#define AUTOCONNECT_URI_OPEN AUTOCONNECT_URI "/open" |
||||
#define AUTOCONNECT_URI_DISCON AUTOCONNECT_URI "/disc" |
||||
#define AUTOCONNECT_URI_RESET AUTOCONNECT_URI "/reset" |
||||
#define AUTOCONNECT_URI_SUCCESS AUTOCONNECT_URI "/success" |
||||
#define AUTOCONNECT_URI_FAIL AUTOCONNECT_URI "/fail" |
||||
|
||||
// Time-out limitation when AutoConnect::begin
|
||||
#ifndef AUTOCONNECT_TIMEOUT |
||||
#define AUTOCONNECT_TIMEOUT 30000 |
||||
#endif // !AUTOCONNECT_TIMEOUT
|
||||
|
||||
// Advance wait time
|
||||
#ifndef AUTOCONNECT_STARTUPTIME |
||||
#define AUTOCONNECT_STARTUPTIME 10 |
||||
#endif // !AUTOCONNECT_STARTUPTIME
|
||||
|
||||
// Default HTTP port
|
||||
#ifndef AUTOCONNECT_HTTPPORT |
||||
#define AUTOCONNECT_HTTPPORT 80 |
||||
#endif // !AUTOCONNECT_HTTPPORT
|
||||
|
||||
// DNS port
|
||||
#ifndef AUTOCONNECT_DNSPORT |
||||
#define AUTOCONNECT_DNSPORT 53 |
||||
#endif // !AUTOCONNECT_DNSPORT
|
||||
|
||||
// Explicitly avoiding unused warning with token handler of PageBuilder
|
||||
#define AC_UNUSED(expr) do { (void)(expr); } while (0) |
||||
|
||||
#endif // _AUTOCONNECTDEFS_H_
|
@ -0,0 +1,49 @@ |
||||
/**
|
||||
* Alias declarations for an accessible the AutoConnectElement class. |
||||
* @file AutoConnectAux.h |
||||
* @author hieromon@gmail.com |
||||
* @version 0.9.7 |
||||
* @date 2018-11-17 |
||||
* @copyright MIT license. |
||||
*/ |
||||
|
||||
#ifndef _AUTOCONNECTELEMENT_H_ |
||||
#define _AUTOCONENCTELEMENT_H_ |
||||
|
||||
#include "AutoConnectElementBasis.h" |
||||
//#include "AutoConnectElementBasisImpl.h"
|
||||
#ifdef AUTOCONNECT_USE_JSON |
||||
#include <ArduinoJson.h> |
||||
#include "AutoConnectElementJson.h" |
||||
//#include "AutoConnectElementJsonImpl.h"
|
||||
using AutoConnectElement = AutoConnectElementJson; |
||||
using AutoConnectButton = AutoConnectButtonJson; |
||||
using AutoConnectCheckbox = AutoConnectCheckboxJson; |
||||
using AutoConnectInput = AutoConnectInputJson; |
||||
using AutoConnectSelect = AutoConnectSelectJson; |
||||
using AutoConnectSubmit = AutoConnectSubmitJson; |
||||
using AutoConnectText = AutoConnectTextJson; |
||||
#else |
||||
using AutoConnectElement = AutoConnectElementBasis; |
||||
using AutoConnectButton = AutoConnectButtonBasis; |
||||
using AutoConnectCheckbox = AutoConnectCheckboxBasis; |
||||
using AutoConnectInput = AutoConnectInputBasis; |
||||
using AutoConnectSelect = AutoConnectSelectBasis; |
||||
using AutoConnectSubmit = AutoConnectSubmitBasis; |
||||
using AutoConnectText = AutoConnectTextBasis; |
||||
#endif |
||||
|
||||
/**
|
||||
* Support declare the AutoConnectElement variable with reducing the |
||||
* arguments. These macros declare the AutoConnectElement variable |
||||
* with the same name as a "name" argument. |
||||
*/ |
||||
#define ACElement(n, v) AutoConnectElement n(#n, v) |
||||
#define ACButton(n, ...) AutoConnectButton n(#n, ##__VA_ARGS__) |
||||
#define ACCheckbox(n, ...) AutoConnectCheckbox n(#n, ##__VA_ARGS__) |
||||
#define ACInput(n, ...) AutoConnectInput n(#n, ##__VA_ARGS__) |
||||
#define ACSelect(n, ...) AutoConnectSelect n(#n, ##__VA_ARGS__) |
||||
#define ACSubmit(n, ...) AutoConnectSubmit n(#n, ##__VA_ARGS__) |
||||
#define ACText(n, ...) AutoConnectText n(#n, ##__VA_ARGS__) |
||||
|
||||
#endif // _AUTOCONNECTELEMENT_H_
|
@ -0,0 +1,170 @@ |
||||
/**
|
||||
* Declaration of AutoConnectElement basic class. |
||||
* @file AutoConnectElementBasis.h |
||||
* @author hieromon@gmail.com |
||||
* @version 0.9.7 |
||||
* @date 2018-11-17 |
||||
* @copyright MIT license. |
||||
*/ |
||||
|
||||
#ifndef _AUTOCONNECTELEMENTBASIS_H_ |
||||
#define _AUTOCONNECTELEMENTBASIS_H_ |
||||
|
||||
#include <vector> |
||||
#include <memory> |
||||
|
||||
typedef enum { |
||||
AC_Button, |
||||
AC_Checkbox, |
||||
AC_Element, |
||||
AC_Input, |
||||
AC_Select, |
||||
AC_Submit, |
||||
AC_Text, |
||||
AC_Unknown |
||||
} ACElement_t; /**< AutoConnectElement class type */ |
||||
|
||||
/**
|
||||
* AutoConnectAux element base. |
||||
* Placed a raw text that can be added by user sketch. |
||||
* @param name A name string for the element. |
||||
* @param value A raw text to be placed in HTML. |
||||
*/ |
||||
class AutoConnectElementBasis { |
||||
public: |
||||
explicit AutoConnectElementBasis(const char* name = "", const char* value = "") : name(String(name)), value(String(value)) { |
||||
_type = AC_Element; |
||||
} |
||||
virtual ~AutoConnectElementBasis() {} |
||||
virtual const String toHTML(void) const { return value; } |
||||
const ACElement_t typeOf(void) const { return _type; } |
||||
|
||||
String name; /**< Element name */ |
||||
String value; /**< Element value */ |
||||
|
||||
protected: |
||||
ACElement_t _type; /**< Element type identifier */ |
||||
}; |
||||
|
||||
/**
|
||||
* Button arrangement class, a part of AutoConnectAux element. |
||||
* Place a labeled button that can be added by user sketch. |
||||
* @param name Button element name string. |
||||
* @param value Value string with the placed button. |
||||
* @param action Script code to execute with the button pushed. |
||||
*/ |
||||
class AutoConnectButtonBasis : virtual public AutoConnectElementBasis { |
||||
public: |
||||
explicit AutoConnectButtonBasis(const char* name = "", const char* value = "", const String action = String()) : AutoConnectElementBasis(name, value), action(action) { |
||||
_type = AC_Button; |
||||
} |
||||
~AutoConnectButtonBasis() {} |
||||
const String toHTML(void) const; |
||||
|
||||
String action; |
||||
}; |
||||
|
||||
/**
|
||||
* Checkbox arrangement class, a part of AutoConnectAux element. |
||||
* Place a optionally labeled input-box that can be added by user sketch. |
||||
* @param name Checkbox name string. |
||||
* @param value A string value associated with the input. |
||||
* @param label A label string that follows checkbox, optionally. |
||||
* The label is placed on the right side of the checkbox. |
||||
*/ |
||||
class AutoConnectCheckboxBasis : virtual public AutoConnectElementBasis { |
||||
public: |
||||
explicit AutoConnectCheckboxBasis(const char* name = "", const char* value = "", const char* label = "", const bool checked = false) : AutoConnectElementBasis(name, value), label(String(label)), checked(checked) { |
||||
_type = AC_Checkbox; |
||||
} |
||||
virtual ~AutoConnectCheckboxBasis() {} |
||||
const String toHTML(void) const; |
||||
|
||||
String label; /**< A label for a subsequent input box */ |
||||
bool checked; /**< The element should be pre-selected */ |
||||
}; |
||||
|
||||
/**
|
||||
* Input-box arrangement class, a part of AutoConnectAux element. |
||||
* Place a optionally labeled input-box that can be added by user sketch. |
||||
* @param name Input-box name string. |
||||
* @param value Default value string. This string display as a placeholder by the default. |
||||
* @param label A label string that follows Input-box, optionally. |
||||
* The label is placed in front of Input-box. |
||||
*/ |
||||
class AutoConnectInputBasis : virtual public AutoConnectElementBasis { |
||||
public: |
||||
explicit AutoConnectInputBasis(const char* name = "", const char* value = "", const char* label = "") : AutoConnectElementBasis(name, value), label(String(label)) { |
||||
_type = AC_Input; |
||||
} |
||||
virtual ~AutoConnectInputBasis() {} |
||||
const String toHTML(void) const; |
||||
|
||||
String label; /**< A label for a subsequent input box */ |
||||
}; |
||||
|
||||
/**
|
||||
* Selection-box arrangement class, A part of AutoConnectAux element. |
||||
* Place a optionally labeled Selection-box that can be added by user sketch. |
||||
* @param name Input-box name string. |
||||
* @param options String array display in a selection list. |
||||
* @param label A label string that follows Input-box, optionally. |
||||
* The label is placed in front of Input-box. |
||||
*/ |
||||
class AutoConnectSelectBasis : virtual public AutoConnectElementBasis { |
||||
public: |
||||
explicit AutoConnectSelectBasis(const char* name = "", std::vector<String> options = {}, const char* label = "") : AutoConnectElementBasis(name, ""), label(String(label)), _options(options) { |
||||
_type = AC_Select; |
||||
} |
||||
virtual ~AutoConnectSelectBasis() {} |
||||
const String toHTML(void) const; |
||||
void option(const String value) { _options.push_back(value); } |
||||
void empty(void) { _options.clear(); } |
||||
|
||||
String label; /**< A label for a subsequent input box */ |
||||
|
||||
protected: |
||||
std::vector<String> _options; /**< List options array */ |
||||
}; |
||||
|
||||
/**
|
||||
* Submit button arrangement class, a part of AutoConnectAux element. |
||||
* Place a submit button with a label that can be added by user sketch. |
||||
* With the button behavior, the values of the elements contained in |
||||
* the form would be sent using the post method. |
||||
* @param name Button name string. |
||||
* @param value Sending value string. |
||||
* @param uri Sending uri string. |
||||
*/ |
||||
class AutoConnectSubmitBasis : virtual public AutoConnectElementBasis { |
||||
public: |
||||
explicit AutoConnectSubmitBasis(const char* name = "", const char* value = "", const char* uri = "") : AutoConnectElementBasis(name, value), uri(String(uri)) { |
||||
_type = AC_Submit; |
||||
} |
||||
virtual ~AutoConnectSubmitBasis() {} |
||||
const String toHTML(void) const; |
||||
|
||||
String uri; /**< An url of submitting to */ |
||||
}; |
||||
|
||||
/**
|
||||
* Text arrangement class, a part of AutoConnectAux element. |
||||
* @param |
||||
* @param name Text name string. |
||||
* @param value Text value string. |
||||
* @param style A string of style-code for decoration, optionally. |
||||
* An arrangement text would be placed with <div> contains. A string |
||||
* of style-codes are given for '<div style=>'. |
||||
*/ |
||||
class AutoConnectTextBasis : virtual public AutoConnectElementBasis { |
||||
public: |
||||
explicit AutoConnectTextBasis(const char* name = "", const char* value = "", const char* style = "") : AutoConnectElementBasis(name, value), style(String(style)) { |
||||
_type = AC_Text; |
||||
} |
||||
virtual ~AutoConnectTextBasis() {} |
||||
const String toHTML(void) const; |
||||
|
||||
String style; /**< CSS style modifier native code */ |
||||
}; |
||||
|
||||
#endif // _AUTOCONNECTELEMENTBASIS_H_
|
@ -0,0 +1,173 @@ |
||||
/**
|
||||
* Declaration of AutoConnectElement extended classes using JSON. |
||||
* @file AutoConnectElementJson.h |
||||
* @author hieromon@gmail.com |
||||
* @version 0.9.7 |
||||
* @date 2018-11-17 |
||||
* @copyright MIT license. |
||||
*/ |
||||
|
||||
#ifndef _AUTOCONNECTELEMENTJSON_H_ |
||||
#define _AUTOCONNECTELEMENTJSON_H_ |
||||
|
||||
#include "AutoConnectElementBasis.h" |
||||
#include <ArduinoJson.h> |
||||
|
||||
#define AUTOCONNECT_JSON_KEY_AUX "aux" |
||||
#define AUTOCONNECT_JSON_KEY_ELEMENT "element" |
||||
#define AUTOCONNECT_JSON_KEY_ACTION "action" |
||||
#define AUTOCONNECT_JSON_KEY_CHECKED "checked" |
||||
#define AUTOCONNECT_JSON_KEY_LABEL "label" |
||||
#define AUTOCONNECT_JSON_KEY_NAME "name" |
||||
#define AUTOCONNECT_JSON_KEY_OPTIONS "options" |
||||
#define AUTOCONNECT_JSON_KEY_STYLE "style" |
||||
#define AUTOCONNECT_JSON_KEY_TYPE "type" |
||||
#define AUTOCONNECT_JSON_KEY_URI "uri" |
||||
#define AUTOCONNECT_JSON_KEY_VALUE "value" |
||||
#define AUTOCONNECT_JSON_TYPE_ACBUTTON "ACButton" |
||||
#define AUTOCONNECT_JSON_TYPE_ACCHECKBOX "ACCheckBox" |
||||
#define AUTOCONNECT_JSON_TYPE_ACELEMENT "ACElement" |
||||
#define AUTOCONNECT_JSON_TYPE_ACINPUT "ACInput" |
||||
#define AUTOCONNECT_JSON_TYPE_ACSELECT "ACSelect" |
||||
#define AUTOCONNECT_JSON_TYPE_ACSUBMIT "ACSubmit" |
||||
#define AUTOCONNECT_JSON_TYPE_ACTEXT "ACText" |
||||
|
||||
/**
|
||||
* AutoConnectAux element base with handling with JSON object. |
||||
* Placed a raw text that can be added by user sketch. |
||||
* @param name A name string for the element. |
||||
* @param value A raw text to be placed in HTML. |
||||
*/ |
||||
class AutoConnectElementJson : virtual public AutoConnectElementBasis { |
||||
public: |
||||
explicit AutoConnectElementJson(const char* name = "", const char* value = "") { |
||||
AutoConnectElementBasis::name = name; |
||||
AutoConnectElementBasis::value = value; |
||||
} |
||||
~AutoConnectElementJson() {} |
||||
virtual bool loadElement(const JsonObject& json); |
||||
|
||||
protected: |
||||
void _setElement(const JsonObject& json); |
||||
}; |
||||
|
||||
/**
|
||||
* Button arrangement class, a part of AutoConnectAux element with |
||||
* handling JSON object. |
||||
* Place a labeled button that can be added by user sketch. |
||||
* @param name Button element name string. |
||||
* @param value Value string with the placed button. |
||||
* @param action Script code to execute with the button pushed. |
||||
*/ |
||||
class AutoConnectButtonJson : public AutoConnectElementJson, public AutoConnectButtonBasis { |
||||
public: |
||||
explicit AutoConnectButtonJson(const char* name = "", const char* value = "", const String action = String()) { |
||||
AutoConnectButtonBasis::name = name; |
||||
AutoConnectButtonBasis::value = value; |
||||
AutoConnectButtonBasis::action = action; |
||||
} |
||||
~AutoConnectButtonJson() {} |
||||
bool loadElement(const JsonObject& json); |
||||
}; |
||||
|
||||
/**
|
||||
* Checkbox arrangement class, a part of AutoConnectAux element with |
||||
* handling JSON object. |
||||
* Place a optionally labeled input-box that can be added by user sketch. |
||||
* @param name Checkbox name string. |
||||
* @param value A string value associated with the input. |
||||
* @param label A label string that follows checkbox, optionally. |
||||
* The label is placed on the right side of the checkbox. |
||||
*/ |
||||
class AutoConnectCheckboxJson : public AutoConnectElementJson, public AutoConnectCheckboxBasis { |
||||
public: |
||||
explicit AutoConnectCheckboxJson(const char* name = "", const char* value = "", const char* label = "", const bool checked = false) { |
||||
AutoConnectCheckboxBasis::name = name; |
||||
AutoConnectCheckboxBasis::value = value; |
||||
AutoConnectCheckboxBasis::label = label; |
||||
AutoConnectCheckboxBasis::checked = checked; |
||||
} |
||||
~AutoConnectCheckboxJson() {} |
||||
bool loadElement(const JsonObject& json); |
||||
}; |
||||
|
||||
/**
|
||||
* Input-box arrangement class, a part of AutoConnectAux element with |
||||
* handling JSON object. |
||||
* Place a optionally labeled input-box that can be added by user sketch. |
||||
* @param name Input-box name string. |
||||
* @param value Default value string. This string display as a placeholder by the default. |
||||
* @param label A label string that follows Input-box, optionally. |
||||
* The label is placed in front of Input-box. |
||||
*/ |
||||
class AutoConnectInputJson : public AutoConnectElementJson, public AutoConnectInputBasis { |
||||
public: |
||||
explicit AutoConnectInputJson(const char* name = "", const char* value = "", const char* label = "") { |
||||
AutoConnectInputBasis::name = name; |
||||
AutoConnectInputBasis::value = value; |
||||
AutoConnectInputBasis::label = label; |
||||
} |
||||
~AutoConnectInputJson() {} |
||||
bool loadElement(const JsonObject& json); |
||||
}; |
||||
|
||||
/**
|
||||
* Selection-box arrangement class, A part of AutoConnectAux element. |
||||
* Place a optionally labeled Selection-box that can be added by user sketch. |
||||
* @param name Input-box name string. |
||||
* @param options String array display in a selection list. |
||||
* @param label A label string that follows Input-box, optionally. |
||||
* The label is placed in front of Input-box. |
||||
*/ |
||||
class AutoConnectSelectJson : public AutoConnectElementJson, public AutoConnectSelectBasis { |
||||
public: |
||||
explicit AutoConnectSelectJson(const char* name = "", std::vector<String> options = {}, const char* label = "") { |
||||
AutoConnectSelectBasis::name = name; |
||||
AutoConnectSelectBasis::_options = options; |
||||
AutoConnectSelectBasis::label = label; |
||||
} |
||||
~AutoConnectSelectJson() {} |
||||
bool loadElement(const JsonObject& json); |
||||
}; |
||||
|
||||
/**
|
||||
* Submit button arrangement class, a part of AutoConnectAux element. |
||||
* Place a submit button with a label that can be added by user sketch. |
||||
* With the button behavior, the values of the elements contained in |
||||
* the form would be sent using the post method. |
||||
* @param name Button name string. |
||||
* @param value Sending value string. |
||||
* @param uri Sending uri string. |
||||
*/ |
||||
class AutoConnectSubmitJson : public AutoConnectElementJson, public AutoConnectSubmitBasis { |
||||
public: |
||||
explicit AutoConnectSubmitJson(const char* name = "", const char* value = "", const char* uri = "") { |
||||
AutoConnectSubmitBasis::name = name; |
||||
AutoConnectSubmitBasis::value = value; |
||||
AutoConnectSubmitBasis::uri = uri; |
||||
} |
||||
~AutoConnectSubmitJson() {} |
||||
bool loadElement(const JsonObject& json); |
||||
}; |
||||
|
||||
/**
|
||||
* Text arrangement class, a part of AutoConnectAux element. |
||||
* @param |
||||
* @param name Text name string. |
||||
* @param value Text value string. |
||||
* @param style A string of style-code for decoration, optionally. |
||||
* An arrangement text would be placed with <div> contains. A string |
||||
* of style-codes are given for '<div style=>'. |
||||
*/ |
||||
class AutoConnectTextJson : public AutoConnectElementJson, public AutoConnectTextBasis { |
||||
public: |
||||
explicit AutoConnectTextJson(const char* name = "", const char* value = "", const char* style = "") { |
||||
AutoConnectTextBasis::name = name; |
||||
AutoConnectTextBasis::value = value; |
||||
AutoConnectTextBasis::style = style; |
||||
} |
||||
~AutoConnectTextJson() {} |
||||
bool loadElement(const JsonObject& json); |
||||
}; |
||||
|
||||
#endif // _AUTOCONNECTELEMENTJSON_H_
|
@ -0,0 +1,140 @@ |
||||
/**
|
||||
* Implementation of AutoConnectElementJson classes. |
||||
* @file AutoConnectElementImpl.h |
||||
* @author hieromon@gmail.com |
||||
* @version 0.9.7 |
||||
* @date 2018-11-17 |
||||
* @copyright MIT license. |
||||
*/ |
||||
|
||||
#ifndef _AUTOCONNECTELEMENTJSONIMPL_H_ |
||||
#define _AUTOCONNECTELEMENTJSONIMPL_H_ |
||||
|
||||
#include "AutoConnectElementJson.h" |
||||
|
||||
/**
|
||||
* Set items common to any type of AutoConnectElement from JSON objects. |
||||
* @param json A JSON object with the definition of AutoConnectElement. |
||||
*/ |
||||
void AutoConnectElementJson::_setElement(const JsonObject& json) { |
||||
name = json.get<String>(F(AUTOCONNECT_JSON_KEY_NAME)); |
||||
value = json.get<String>(F(AUTOCONNECT_JSON_KEY_VALUE)); |
||||
} |
||||
|
||||
/**
|
||||
* Load an element member value from the JSON object. |
||||
* @param json A JSON object with the definition of AutoConnectElement. |
||||
* @return true AutoConnectElement loaded |
||||
* @return false Type of AutoConnectElement is mismatched. |
||||
*/ |
||||
bool AutoConnectElementJson::loadElement(const JsonObject& json) { |
||||
String type = json.get<String>(F(AUTOCONNECT_JSON_KEY_TYPE)); |
||||
if (type.equalsIgnoreCase(F(AUTOCONNECT_JSON_TYPE_ACELEMENT))) { |
||||
_setElement(json); |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
/**
|
||||
* Load a button element attribute member from the JSON object. |
||||
* @param json A JSON object with the definition of AutoConnectElement. |
||||
* @return true AutoConnectElement loaded |
||||
* @return false Type of AutoConnectElement is mismatched. |
||||
*/ |
||||
bool AutoConnectButtonJson::loadElement(const JsonObject& json) { |
||||
String type = json.get<String>(F(AUTOCONNECT_JSON_KEY_TYPE)); |
||||
if (type.equalsIgnoreCase(F(AUTOCONNECT_JSON_TYPE_ACBUTTON))) { |
||||
_setElement(json); |
||||
action = json.get<String>(F(AUTOCONNECT_JSON_KEY_ACTION)); |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
/**
|
||||
* Load a checkbox element attribute member from the JSON object. |
||||
* @param json A JSON object with the definition of AutoConnectElement. |
||||
* @return true AutoConnectElement loaded |
||||
* @return false Type of AutoConnectElement is mismatched. |
||||
*/ |
||||
bool AutoConnectCheckboxJson::loadElement(const JsonObject& json) { |
||||
String type = json.get<String>(F(AUTOCONNECT_JSON_KEY_TYPE)); |
||||
if (type.equalsIgnoreCase(F(AUTOCONNECT_JSON_TYPE_ACCHECKBOX))) { |
||||
_setElement(json); |
||||
label = json.get<String>(F(AUTOCONNECT_JSON_KEY_LABEL)); |
||||
checked = json.get<bool>(F(AUTOCONNECT_JSON_KEY_CHECKED)); |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
/**
|
||||
* Load a input-box element attribute member from the JSON object. |
||||
* @param json A JSON object with the definition of AutoConnectElement. |
||||
* @return true AutoConnectElement loaded |
||||
* @return false Type of AutoConnectElement is mismatched. |
||||
*/ |
||||
bool AutoConnectInputJson::loadElement(const JsonObject& json) { |
||||
String type = json.get<String>(F(AUTOCONNECT_JSON_KEY_TYPE)); |
||||
if (type.equalsIgnoreCase(F(AUTOCONNECT_JSON_TYPE_ACINPUT))) { |
||||
_setElement(json); |
||||
label = json.get<String>(F(AUTOCONNECT_JSON_KEY_LABEL)); |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
/**
|
||||
* Load a select element attribute member from the JSON object. |
||||
* @param json A JSON object with the definition of AutoConnectElement. |
||||
* @return true AutoConnectElement loaded |
||||
* @return false Type of AutoConnectElement is mismatched. |
||||
*/ |
||||
bool AutoConnectSelectJson::loadElement(const JsonObject& json) { |
||||
String type = json.get<String>(F(AUTOCONNECT_JSON_KEY_TYPE)); |
||||
if (type.equalsIgnoreCase(F(AUTOCONNECT_JSON_TYPE_ACSELECT))) { |
||||
_setElement(json); |
||||
empty(); |
||||
label = json.get<String>(F(AUTOCONNECT_JSON_KEY_LABEL)); |
||||
JsonArray& optionArray = json[AUTOCONNECT_JSON_KEY_OPTIONS]; |
||||
for (auto value : optionArray) |
||||
option(value.as<String>()); |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
/**
|
||||
* Load a submit element attribute member from the JSON object. |
||||
* @param json A JSON object with the definition of AutoConnectElement. |
||||
* @return true AutoConnectElement loaded |
||||
* @return false Type of AutoConnectElement is mismatched. |
||||
*/ |
||||
bool AutoConnectSubmitJson::loadElement(const JsonObject& json) { |
||||
String type = json.get<String>(F(AUTOCONNECT_JSON_KEY_TYPE)); |
||||
if (type.equalsIgnoreCase(F(AUTOCONNECT_JSON_TYPE_ACSUBMIT))) { |
||||
_setElement(json); |
||||
uri = json.get<String>(F(AUTOCONNECT_JSON_KEY_URI)); |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
/**
|
||||
* Load a text element attribute member from the JSON object. |
||||
* @param json A JSON object with the definition of AutoConnectElement. |
||||
* @return true AutoConnectElement loaded |
||||
* @return false Type of AutoConnectElement is mismatched. |
||||
*/ |
||||
bool AutoConnectTextJson::loadElement(const JsonObject& json) { |
||||
String type = json.get<String>(F(AUTOCONNECT_JSON_KEY_TYPE)); |
||||
if (type.equalsIgnoreCase(F(AUTOCONNECT_JSON_TYPE_ACTEXT))) { |
||||
_setElement(json); |
||||
style = json.get<String>(F(AUTOCONNECT_JSON_KEY_STYLE)); |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
#endif // _AUTOCONNECTELEMENTJSONIMPL_H_
|
Loading…
Reference in new issue