From 33a5e5b3cb81e960e10d7ae8d4b3a2940d38660b Mon Sep 17 00:00:00 2001 From: Pablo Sanchez Date: Thu, 18 Feb 2016 23:29:00 -0500 Subject: [PATCH] Added an option to the WiFiManagerParameter so that a parameter can be read-only. This is done in a way that does not break an existing program by having a constructor for either way. If a "1" is added to the end of the parameter list then the field becomes readonly. The HTML will add the "readonly" option. --- WiFiManager.cpp | 28 +++++++++++++++++++++++++--- WiFiManager.h | 5 ++++- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 45ffb9f..227b989 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -12,7 +12,8 @@ #include "WiFiManager.h" -WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length) { + +WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length, int rofield) { _id = id; _placeholder = placeholder; _length = length; @@ -23,6 +24,25 @@ WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placehold if (defaultValue != NULL) { strncpy(_value, defaultValue, length); } + if (rofield == 0) { + _rofield = " readonly"; + } else { + _rofield = ""; + } +} + +WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length) { + _id = id; + _placeholder = placeholder; + _length = length; + _value = new char[length + 1]; + for (int i = 0; i < length; i++) { + _value[i] = 0; + } + if (defaultValue != NULL) { + strncpy(_value, defaultValue, length); + } + _rofield = ""; } const char* WiFiManagerParameter::getValue() { @@ -37,6 +57,9 @@ const char* WiFiManagerParameter::getPlaceholder() { int WiFiManagerParameter::getValueLength() { return _length; } +const char* WiFiManagerParameter::getRofield() { + return _rofield; +} WiFiManager::WiFiManager() { } @@ -415,6 +438,7 @@ void WiFiManager::handleWifi(boolean scan) { snprintf(parLength, 2, "%d", _params[i]->getValueLength()); pitem.replace("{l}", parLength); pitem.replace("{v}", _params[i]->getValue()); + pitem.replace("{r}", _params[i]->getRofield()); page += pitem; } @@ -679,5 +703,3 @@ String WiFiManager::toStringIp(IPAddress ip) { res += String(((ip >> 8 * 3)) & 0xFF); return res; } - - diff --git a/WiFiManager.h b/WiFiManager.h index 512d51f..ae501c6 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -28,7 +28,7 @@ const char HTTP_PORTAL_OPTIONS[] PROGMEM = "
Scan"; @@ -40,16 +40,19 @@ const char HTTP_END[] PROGMEM = ""; class WiFiManagerParameter { public: WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length); + WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length, int rofield); const char *getID(); const char *getValue(); const char *getPlaceholder(); int getValueLength(); + const char *getRofield(); private: const char *_id; const char *_placeholder; char *_value; int _length; + const char *_rofield; friend class WiFiManager; };