diff --git a/.gitignore b/.gitignore index bfd3ae4..fb1320b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,12 @@ # Files generated by build -/site \ No newline at end of file +.vs/ +__vm/ +debug/ +img/ +*.tmp +*.TMP +*.sln +*.vcxproj +*.vcxproj.filters +.pioenvs +.piolibdeps diff --git a/src/AutoConnectCredentail.cpp b/src/AutoConnectCredentail.cpp index b5185b2..111e382 100644 --- a/src/AutoConnectCredentail.cpp +++ b/src/AutoConnectCredentail.cpp @@ -11,7 +11,7 @@ #include "AutoConnectCredentail.h" #define AC_IDENTIFIER "AC_CREDT" -#define AC_HEADERSIZE ((int)(AC_IDENTIFIER_OFFSET + sizeof(AC_IDENTIFIER) - 1 + sizeof(uint8_t) + sizeof(uint16_t))) +#define AC_HEADERSIZE ((int)(_offset + sizeof(AC_IDENTIFIER) - 1 + sizeof(uint8_t) + sizeof(uint16_t))) /** * AutoConnectCredential constructor takes the available count of saved @@ -33,15 +33,22 @@ * Free area are filled with FF, which is reused as an area for insertion. */ AutoConnectCredential::AutoConnectCredential() { + AutoConnectCredential(AC_IDENTIFIER_OFFSET); +} + +AutoConnectCredential::AutoConnectCredential(uint16_t offset) { char id_c[sizeof(AC_IDENTIFIER) - 1]; uint8_t c; + // Save offset for the credential area. + _offset = offset; + EEPROM.begin(AC_HEADERSIZE); // Validate the save area of the EEPROM. // If it is a valid area, retrieve the stored number of entries, // if the identifier is not saved, initialize the EEPROM area. - for (c = AC_IDENTIFIER_OFFSET; c < AC_IDENTIFIER_OFFSET + sizeof(id_c); c++) { + for (c = _offset; c < _offset + sizeof(id_c); c++) { id_c[c] = static_cast(EEPROM.read(c)); } if (!strncmp(id_c, AC_IDENTIFIER, sizeof(id_c))) { diff --git a/src/AutoConnectCredentail.h b/src/AutoConnectCredentail.h index 7edfa16..b6943b6 100644 --- a/src/AutoConnectCredentail.h +++ b/src/AutoConnectCredentail.h @@ -31,6 +31,7 @@ extern "C" { class AutoConnectCredential { public: AutoConnectCredential(); + AutoConnectCredential(uint16_t offset); ~AutoConnectCredential(); uint8_t entries() { return _entries; } bool del(const char* ssid); @@ -44,6 +45,7 @@ class AutoConnectCredential { uint16_t _containSize; /**< Container size */ int _dp; /**< The current address in EEPROM */ int _ep; /**< The current entry address in EEPROM */ + uint16_t _offset; /**< The offset for the saved area of credentials in EEPROM. */ }; #endif // _AUTOCONNECTCREDENTAIL_H_