Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WiFiManagerParameter Checkboxes and Radios #1775

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
432 changes: 357 additions & 75 deletions WiFiManager.cpp

Large diffs are not rendered by default.

75 changes: 63 additions & 12 deletions WiFiManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,34 +203,85 @@ class WiFiManagerParameter {
*/
WiFiManagerParameter();
WiFiManagerParameter(const char *custom);
WiFiManagerParameter(const char *id, const char *label);
WiFiManagerParameter(const char *id, const char *label, const char *defaultValue, int length);
WiFiManagerParameter(const char *id, const char *label, const char *defaultValue, int length, const char *custom);
WiFiManagerParameter(const char *id, const char *label, const char *defaultValue, int length, const char *custom, int labelPlacement);
~WiFiManagerParameter();
WiFiManagerParameter(const char *name, const char *label);
WiFiManagerParameter(const char *name, const char *label, const char *defaultValue, int maxLength);
WiFiManagerParameter(const char *name, const char *label, const char *defaultValue, int maxLength, const char *custom);
WiFiManagerParameter(const char *name, const char *label, const char *defaultValue, int maxLength, const char *custom, int labelPlacement);
virtual ~WiFiManagerParameter();
// WiFiManagerParameter& operator=(const WiFiManagerParameter& rhs);

const char *getID() const;
const char *getName() const;
const char *getID() const; // @deprecated, use getName
const char *getValue() const;
const char *getLabel() const;
const char *getPlaceholder() const; // @deprecated, use getLabel
int getValueLength() const;
int getValueLength() const; // @deprecated, use getValueMaxLength
int getValueMaxLength() const;
int getLabelPlacement() const;
virtual const char *getCustomHTML() const;
void setValue(const char *defaultValue, int length);
void setValue(const char *defaultValue, int maxLength);

virtual String getHTML() const;
virtual void setValueReceived(const char* value);

protected:
void init(const char *id, const char *label, const char *defaultValue, int length, const char *custom, int labelPlacement);
void init(const char *name, const char *label, const char *defaultValue, int maxLength, const char *custom, int labelPlacement);

WiFiManagerParameter& operator=(const WiFiManagerParameter&);
const char *_id;
const char *_id; // @deprecated this should be _name
const char *_label;
char *_value;
int _length;
int _length; // @deprecated this should be _maxLength
int _labelPlacement;

const char *_customHTML;
friend class WiFiManager;
};

class WiFiManagerParameterCheckbox : public WiFiManagerParameter {
public:
WiFiManagerParameterCheckbox(
const char* name,
const char* label,
const char* value,
bool checked = false,
const char* custom = "",
int labelPlacement = WFM_LABEL_AFTER);

virtual String getHTML() const;
virtual void setValueReceived(const char* value);

bool getChecked() const;
void setChecked(bool checked);

private:
bool _checked;
};

class WiFiManagerParameterRadio : public WiFiManagerParameter {
public:
WiFiManagerParameterRadio(
const char* name,
const char* custom = "",
int labelPlacement = WFM_LABEL_AFTER);

void addOption(const char* id, const char* label, const char* value, bool selected);
void clear();

virtual String getHTML() const;
virtual void setValueReceived(const char* value);

private:
struct RadioOption {
const char* id;
const char* label;
const char* value;
};

bool valueSelected(const char* value) const;
String generateOptionHTML(const RadioOption& option) const;

std::vector<RadioOption> options;
size_t maxBufferSize;
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void loop() {

void saveParamsCallback () {
Serial.println("Get Params:");
Serial.print(custom_mqtt_server.getID());
Serial.print(custom_mqtt_server.getName());
Serial.print(" : ");
Serial.println(custom_mqtt_server.getValue());
}
4 changes: 2 additions & 2 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ setSTAStaticIPConfig KEYWORD2
setAPCallback KEYWORD2
setSaveConfigCallback KEYWORD2
addParameter KEYWORD2
getID KEYWORD2
getName KEYWORD2
getValue KEYWORD2
getPlaceholder KEYWORD2
getValueLength KEYWORD2
getValueMaxLength KEYWORD2

#######################################
# Constants (LITERAL1)
Expand Down
1 change: 1 addition & 0 deletions wm_consts_en.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ const char T_i[] PROGMEM = "{i}"; // @token i
const char T_n[] PROGMEM = "{n}"; // @token n
const char T_p[] PROGMEM = "{p}"; // @token p
const char T_t[] PROGMEM = "{t}"; // @token t
const char T_T[] PROGMEM = "{T}"; // @token T
const char T_l[] PROGMEM = "{l}"; // @token l
const char T_c[] PROGMEM = "{c}"; // @token c
const char T_e[] PROGMEM = "{e}"; // @token e
Expand Down
1 change: 1 addition & 0 deletions wm_consts_fr.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const char T_i[] PROGMEM = "{i}"; // @token i
const char T_n[] PROGMEM = "{n}"; // @token n
const char T_p[] PROGMEM = "{p}"; // @token p
const char T_t[] PROGMEM = "{t}"; // @token t
const char T_T[] PROGMEM = "{T}"; // @token T
const char T_l[] PROGMEM = "{l}"; // @token l
const char T_c[] PROGMEM = "{c}"; // @token c
const char T_e[] PROGMEM = "{e}"; // @token e
Expand Down
1 change: 1 addition & 0 deletions wm_strings_en.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const char HTTP_FORM_END[] PROGMEM = "<br/><br/><button type='submit'>Sa
const char HTTP_FORM_LABEL[] PROGMEM = "<label for='{i}'>{t}</label>";
const char HTTP_FORM_PARAM_HEAD[] PROGMEM = "<hr><br/>";
const char HTTP_FORM_PARAM[] PROGMEM = "<br/><input id='{i}' name='{n}' maxlength='{l}' value='{v}' {c}>\n"; // do not remove newline!
const char HTTP_FORM_PARAM_CHECK[] PROGMEM = "<input type='{T}' name='{n}' id='{i}' value='{v}' {c}>\n";

const char HTTP_SCAN_LINK[] PROGMEM = "<br/><form action='/wifi?refresh=1' method='POST'><button name='refresh' value='1'>Refresh</button></form>";
const char HTTP_SAVED[] PROGMEM = "<div class='msg'>Saving Credentials<br/>Trying to connect ESP to network.<br />If it fails reconnect to AP to try again</div>";
Expand Down
1 change: 1 addition & 0 deletions wm_strings_es.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const char HTTP_FORM_END[] PROGMEM = "<br/><br/><button type='submit'>Sa
const char HTTP_FORM_LABEL[] PROGMEM = "<label for='{i}'>{t}</label>";
const char HTTP_FORM_PARAM_HEAD[] PROGMEM = "<hr><br/>";
const char HTTP_FORM_PARAM[] PROGMEM = "<br/><input id='{i}' name='{n}' maxlength='{l}' value='{v}' {c}>\n"; // do not remove newline!
const char HTTP_FORM_PARAM_CHECK[] PROGMEM = "<input type='{T}' name='{n}' id='{i}' value='{v}' {c}>\n";

const char HTTP_SCAN_LINK[] PROGMEM = "<br/><form action='/wifi?refresh=1' method='POST'><button name='refresh' value='1'>Refresh</button></form>";
const char HTTP_SAVED[] PROGMEM = "<div class='msg'>Saving Credentials<br/>Trying to connect ESP to network.<br />If it fails reconnect to AP to try again</div>";
Expand Down
1 change: 1 addition & 0 deletions wm_strings_fr.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const char HTTP_FORM_END[] PROGMEM = "<br/><br/><button type='submit'>En
const char HTTP_FORM_LABEL[] PROGMEM = "<label for='{i}'>{t}</label>";
const char HTTP_FORM_PARAM_HEAD[] PROGMEM = "<hr><br/>";
const char HTTP_FORM_PARAM[] PROGMEM = "<br/><input id='{i}' name='{n}' maxlength='{l}' value='{v}' {c}>\n"; // do not remove newline!
const char HTTP_FORM_PARAM_CHECK[] PROGMEM = "<input type='{T}' name='{n}' id='{i}' value='{v}' {c}>\n";

const char HTTP_SCAN_LINK[] PROGMEM = "<br/><form action='/wifi?refresh=1' method='POST'><button name='refresh' value='1'>Rafraichir</button></form>";
const char HTTP_SAVED[] PROGMEM = "<div class='msg'>Enregistrer l'accès<br/>L'ESP essai de se connecter au réseau.<br />Si échec, merci de vous reconnecter à nouveau.</div>";
Expand Down