Changed the comment to be legible #209

pull/248/head
Hieromon Ikasamo 5 years ago
parent 5716bdd0a0
commit 756c9c28ea
  1. 28
      examples/EEPROM/EEPROM.ino
  2. 5
      src/AutoConnect.cpp

@ -5,14 +5,14 @@
This software is released under the MIT License. This software is released under the MIT License.
https://opensource.org/licenses/MIT https://opensource.org/licenses/MIT
This example demonstrates how allocates and handles the custom The AutoConnectConfig::boundaryOffset setting allows AutoConnect to
configuration for the Sketch. write its data to EEPROM while preserving custom configuration data.
When Sketch stores the own configuration data in the EEPROM, it must Similarly, when a Sketch writes its own data to EEPROM, it must
avoid conflict with the credentials stored by AutoConnect. preserve the data written by AutoConnect.
AutoConnectConfig::boundaryOffset designation helps with the conflict, This example demonstrates how to use the getEEPROMUsedSize() method to
but it is inadequate. Sketch uses AutoConnect::getCredentialSize to store custom configuration settings in EEPROM without conflicting with
get the size of the actual EEPROM area that should be handled for the AutoConnect's use of that storage. (Note: this applies to the ESP8266
own custom data I/O. only, not the ESP32.)
*/ */
#ifndef ARDUINO_ARCH_ESP8266 #ifndef ARDUINO_ARCH_ESP8266
@ -113,12 +113,7 @@ String toString(char* c, uint8_t length) {
String onEEPROM(AutoConnectAux& page, PageArgument& args) { String onEEPROM(AutoConnectAux& page, PageArgument& args) {
EEPROM_CONFIG_t eepromConfig; EEPROM_CONFIG_t eepromConfig;
// The actual area size of the EEPROM region to be given to EEPROM.begin(sizeof(eepromConfig));
// EEPROM.begin is the sum of the size of the own custom data and
// the size of the currently stored AutoConnect credentials.
// eg.
// EEPROM.begin(portal.getEEPROMUsedSize())
EEPROM.begin(portal.getEEPROMUsedSize());
EEPROM.get<EEPROM_CONFIG_t>(0, eepromConfig); EEPROM.get<EEPROM_CONFIG_t>(0, eepromConfig);
EEPROM.end(); EEPROM.end();
@ -136,6 +131,11 @@ 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));
// The actual area size of the EEPROM region to be given to
// EEPROM.begin is the sum of the size of the own custom data and
// the size of the currently stored AutoConnect credentials.
// eg.
// EEPROM.begin(portal.getEEPROMUsedSize())
EEPROM.begin(portal.getEEPROMUsedSize()); EEPROM.begin(portal.getEEPROMUsedSize());
EEPROM.put<EEPROM_CONFIG_t>(0, eepromConfig); EEPROM.put<EEPROM_CONFIG_t>(0, eepromConfig);
EEPROM.commit(); EEPROM.commit();

@ -747,9 +747,10 @@ bool AutoConnect::_loadAvailCredential(const char* ssid, const AC_PRINCIPLE_t pr
} }
/** /**
* Get current AutoConnectCredential size. * Get the total amount of memory required to hold the AutoConnect credentials
* and any custom configuration settings stored in EEPROM.
* This function is available only for ESP8266 use. * This function is available only for ESP8266 use.
* @return Size of the AutoConnectCredential * @return Combined size of AutoConnect credentials and custom settings.
*/ */
uint16_t AutoConnect::getEEPROMUsedSize(void) { uint16_t AutoConnect::getEEPROMUsedSize(void) {
#if defined(ARDUINO_ARCH_ESP8266) #if defined(ARDUINO_ARCH_ESP8266)

Loading…
Cancel
Save