Changed getEEPROMUsedSize #209

pull/248/head
Hieromon Ikasamo 5 years ago
parent 84d18dedae
commit 5716bdd0a0
  1. 8
      examples/EEPROM/EEPROM.ino
  2. 11
      src/AutoConnect.cpp
  3. 2
      src/AutoConnect.h

@ -9,7 +9,7 @@
configuration for the Sketch. configuration for the Sketch.
When Sketch stores the own configuration data in the EEPROM, it must When Sketch stores the own configuration data in the EEPROM, it must
avoid conflict with the credentials stored by AutoConnect. avoid conflict with the credentials stored by AutoConnect.
AutoConnectConfig::boundayOffet designation helps with the conflict, AutoConnectConfig::boundaryOffset designation helps with the conflict,
but it is inadequate. Sketch uses AutoConnect::getCredentialSize to but it is inadequate. Sketch uses AutoConnect::getCredentialSize to
get the size of the actual EEPROM area that should be handled for the get the size of the actual EEPROM area that should be handled for the
own custom data I/O. own custom data I/O.
@ -117,8 +117,8 @@ String onEEPROM(AutoConnectAux& page, PageArgument& args) {
// EEPROM.begin is the sum of the size of the own custom data and // EEPROM.begin is the sum of the size of the own custom data and
// the size of the currently stored AutoConnect credentials. // the size of the currently stored AutoConnect credentials.
// eg. // eg.
// sizeof(EEPROM_CONFIG_t) + portal.getCredentialSize() // EEPROM.begin(portal.getEEPROMUsedSize())
EEPROM.begin(sizeof(EEPROM_CONFIG_t) + portal.getCredentialSize()); EEPROM.begin(portal.getEEPROMUsedSize());
EEPROM.get<EEPROM_CONFIG_t>(0, eepromConfig); EEPROM.get<EEPROM_CONFIG_t>(0, eepromConfig);
EEPROM.end(); EEPROM.end();
@ -136,7 +136,7 @@ String onEEPROMWrite(AutoConnectAux& page, PageArgument& args) {
strncpy(eepromConfig.data2, page["data2"].value.c_str(), sizeof(EEPROM_CONFIG_t::data2)); strncpy(eepromConfig.data2, page["data2"].value.c_str(), sizeof(EEPROM_CONFIG_t::data2));
strncpy(eepromConfig.data3, page["data3"].value.c_str(), sizeof(EEPROM_CONFIG_t::data3)); strncpy(eepromConfig.data3, page["data3"].value.c_str(), sizeof(EEPROM_CONFIG_t::data3));
EEPROM.begin(sizeof(EEPROM_CONFIG_t) + portal.getCredentialSize()); EEPROM.begin(portal.getEEPROMUsedSize());
EEPROM.put<EEPROM_CONFIG_t>(0, eepromConfig); EEPROM.put<EEPROM_CONFIG_t>(0, eepromConfig);
EEPROM.commit(); EEPROM.commit();
EEPROM.end(); EEPROM.end();

@ -747,12 +747,17 @@ bool AutoConnect::_loadAvailCredential(const char* ssid, const AC_PRINCIPLE_t pr
} }
/** /**
* Get current AutoConnectCredential size * Get current AutoConnectCredential size.
* This function is available only for ESP8266 use.
* @return Size of the AutoConnectCredential * @return Size of the AutoConnectCredential
*/ */
uint16_t AutoConnect::getCredentialSize(void) { uint16_t AutoConnect::getEEPROMUsedSize(void) {
#if defined(ARDUINO_ARCH_ESP8266)
AutoConnectCredential credentials(_apConfig.boundaryOffset); AutoConnectCredential credentials(_apConfig.boundaryOffset);
return credentials.dataSize(); return _apConfig.boundaryOffset + credentials.dataSize();
#elif defined(ARDUINO_ARCH_ESP32)
return 0;
#endif
} }
/** /**

@ -252,7 +252,7 @@ class AutoConnect {
String where(void) const { return _auxUri; } String where(void) const { return _auxUri; }
inline void enableMenu(const uint16_t items) { _apConfig.menuItems |= items; } inline void enableMenu(const uint16_t items) { _apConfig.menuItems |= items; }
inline void disableMenu(const uint16_t items) { _apConfig.menuItems &= (0xffff ^ items); } inline void disableMenu(const uint16_t items) { _apConfig.menuItems &= (0xffff ^ items); }
uint16_t getCredentialSize(void); uint16_t getEEPROMUsedSize(void);
/** For AutoConnectAux described in JSON */ /** For AutoConnectAux described in JSON */
#ifdef AUTOCONNECT_USE_JSON #ifdef AUTOCONNECT_USE_JSON

Loading…
Cancel
Save