-
Couldn't load subscription status.
- Fork 7.7k
Description
Hardware:
Board: ESP32 Dev Module
Core Installation version: 1.0.6, 2.0.0
IDE name: Arduino IDE
Flash Frequency: 80Mhz
PSRAM enabled: No
Upload Speed: 921600
Computer OS: Windows 10
Description:
EEPROM.length() always returns zero if using the default global EEPROM instance. Using my own instance, like the eeprom_class example, I can get the length defined in the constructor (_user_defined_size) not the size defined in begin(size) (_size). Related to #2280.
Sketch: (leave the backquotes for code formatting)
#include "EEPROM.h"
void setup() {
Serial.begin(115200);
delay(1000);
EEPROM.begin(0x100);
Serial.println(EEPROM.length()); // always zero for global EEPROM instance
}
void loop() {
}Expected behavior
EEPROM.length() should return the available size of EEPROM even if using the global instance.
Possible improvements
I have created two pull requests. If it looks good for you, please consider merging one of them.
#5774 Add EEPROM::capacity() method to get _user_defined_data and EEPROM::length() returns _size
capacity()method returns_user_defined_sizethat is set by the constructorlength()returns_sizethat is the true available size of EEPROM
#5775 Remove _user_defined_size and just use _size
I think this is better because _user_defined_size seems to be redundant for me. Just using _size is much clear.
_user_defined_sizeis removed because it is redundant in the current codelength()returns_sizethat is the true available size of EEPROM