Zanduino / INA

Combined Arduino library for reading multiple INA2xx power monitor devices
GNU General Public License v3.0
158 stars 40 forks source link

Try to avoid EEPROM footprint #82

Open ortegafernando opened 3 years ago

ortegafernando commented 3 years ago

Hi, I have read your great library, and I am using it in memory, not in EEPROM.

But I found that INA.begin function does this:

#if defined(ESP32) || defined(ESP8266)
    EEPROM.begin(_EEPROM_size + _EEPROM_offset);  // If ESP32 then allocate 512 Bytes
    maxDevices = (_EEPROM_size) / sizeof(inaEE);  // and compute number of devices

Will EEPROM.begin be better in Class constructor to use it in conjunction of _expectedDevices.

I mean, all stuff about initializating EEPROM could be in Class constructor?

Thanks.

SV-Zanshin commented 3 years ago

I've changed this from a "bug" to an "enhancement" because the way the library currently works is not incorrect, it is just different from what you would like to see. The addition of the ESP32 and ESP8266 devices came after the initial library was developed and considering the amount of free RAM these devices have (at least compared to an Atmel microprocessor) a generous allocation of 512B is made. This allocation is not done during class instantiation, as the library was developed to push all of the actual initialization into the begin() method rather than class instantiation. This gives greater flexibility at runtime where sometimes the hardware is not initialized by Arduino IDE at the point in time where the class is instantiated - many libraries use this "delay" tactic.

It would be possible to change this 512B allocation to a size of (expected_devices * instance size) to reduce the memory footprint.

Is there a specific problem that you are seeing, or is this more of a general discussion as to how to make the library more generally useable?