cmaglie / FlashStorage

A convenient way to store data into Flash memory on the ATSAMD21 and ATSAMD51 processor family
202 stars 69 forks source link

_Dirty is not reset after commit #28

Open Jan21493 opened 5 years ago

Jan21493 commented 5 years ago

I've seen #11 and agree with it. When a value is written (EEPROMClass::update), _dirty is set, because a commit is required to make this change persistent.

A commit only writes data to flash memory, if neccessary - equals to if _dirty is set and makes sense as well. But where is the _dirty flag cleared? Otherwise after the first call of EEPROMClass::update the _dirty is always true and makes no sense anymore.

I propose to clear the dirty flag at the end of the commit:

void EEPROMClass::commit()
{
  if (!_initialized) init();
  if (_dirty) {
    _eeprom.valid = true;
    eeprom_storage.write(_eeprom);
    _dirty = false;
  }
}

With this statement you may call commit even within a loop and it does not harm flash memory, because the data is actually only written to flash, if some data was changed with a EEPROMClass::update before.

tuxedo0801 commented 4 years ago

@cmaglie How about a bugfix for this?