From 756c9c28eae8ca60df9828cb7df22cde92c6034a Mon Sep 17 00:00:00 2001 From: Hieromon Ikasamo Date: Thu, 23 Apr 2020 18:54:27 +0900 Subject: [PATCH] Changed the comment to be legible #209 --- examples/EEPROM/EEPROM.ino | 28 ++++++++++++++-------------- src/AutoConnect.cpp | 5 +++-- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/examples/EEPROM/EEPROM.ino b/examples/EEPROM/EEPROM.ino index 3e4b829..8e812ba 100644 --- a/examples/EEPROM/EEPROM.ino +++ b/examples/EEPROM/EEPROM.ino @@ -5,14 +5,14 @@ This software is released under the MIT License. https://opensource.org/licenses/MIT - This example demonstrates how allocates and handles the custom - configuration for the Sketch. - When Sketch stores the own configuration data in the EEPROM, it must - avoid conflict with the credentials stored by AutoConnect. - AutoConnectConfig::boundaryOffset designation helps with the conflict, - but it is inadequate. Sketch uses AutoConnect::getCredentialSize to - get the size of the actual EEPROM area that should be handled for the - own custom data I/O. + The AutoConnectConfig::boundaryOffset setting allows AutoConnect to + write its data to EEPROM while preserving custom configuration data. + Similarly, when a Sketch writes its own data to EEPROM, it must + preserve the data written by AutoConnect. + This example demonstrates how to use the getEEPROMUsedSize() method to + store custom configuration settings in EEPROM without conflicting with + AutoConnect's use of that storage. (Note: this applies to the ESP8266 + only, not the ESP32.) */ #ifndef ARDUINO_ARCH_ESP8266 @@ -113,12 +113,7 @@ String toString(char* c, uint8_t length) { String onEEPROM(AutoConnectAux& page, PageArgument& args) { EEPROM_CONFIG_t eepromConfig; - // 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(sizeof(eepromConfig)); EEPROM.get(0, eepromConfig); 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.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.put(0, eepromConfig); EEPROM.commit(); diff --git a/src/AutoConnect.cpp b/src/AutoConnect.cpp index fa68dcf..0c25e47 100644 --- a/src/AutoConnect.cpp +++ b/src/AutoConnect.cpp @@ -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. - * @return Size of the AutoConnectCredential + * @return Combined size of AutoConnect credentials and custom settings. */ uint16_t AutoConnect::getEEPROMUsedSize(void) { #if defined(ARDUINO_ARCH_ESP8266)