mrrwa / NmraDcc

NMRA Digital Command Control (DCC) Library
GNU Lesser General Public License v2.1
137 stars 53 forks source link

Resetting the decoder #61

Closed marko-pi closed 2 years ago

marko-pi commented 2 years ago

On resetting the decoder, CV8 -> 8, notifyCVResetFactoryDefault() is triggered seven times. It is probably not a good idea for EEPROM to be rewritten too many times.

As a patch, I used if (FactoryDefaultCVIndex == 0) in front of FactoryDefaultCVIndex = sizeof(FactoryDefaultCVs)/sizeof(CVPair);

This reduces seven EEPROM writes to "only" three.

I am using PiSPROG DCC controller/programmer and ATmega328.

Best regards!

kiwi64ajs commented 2 years ago

I don't think this is really an issue as the NmraDcc library reads the current EEPROM value and compares the current value to the new value first before overwriting it to avoid needless EEPROM Writes.

Here is the code: https://github.com/mrrwa/NmraDcc/blob/master/NmraDcc.cpp#L871