Open b-blake opened 2 years ago
I do like this idea. It seems like it should save a little bit of wear on the device by not writing unless necessary.
Are you interested in submitting a PR with this change perhaps?
What is a PR? How do I submit one? Do I get and Brownie Points?
It will have the biggest impact when erasing an EEPROM.
@b-blake PR is Pull Request. Essentially it's proposing a change in the library that then can get reviewed by project maintainers and merged in if accepted.
There is a guide here: https://learn.adafruit.com/contribute-to-circuitpython-with-git-and-github/create-your-pull-request that gives a more in depth description and covers the process. That whole guide contains great information to get you started contributing to CircuitPython libraries.
@FoamyGuy OK, I have not modified your code to add this feature. I looked and am not sure where in the code a byte is actually written to the EEPROM. So I guess I will have to leave it as an idea the code manager considers for implementation. Thank you for the offer.
@b-blake It writes to the EEPROM ultimately from here: https://github.com/adafruit/Adafruit_CircuitPython_24LC32/blob/f8fc83fcaa170fae0f0c5021d15548891534f531/adafruit_24lc32.py#L133-L154
The line near the end does the writing specifically. It could be put inside of an if statement that checks the address / value and then only calls _write
if they aren't the same already.
FG,
I found that line/part. Where is a byte read? I have yet to figure out how to read the byte that is about to be written. I don't find a self._read(address) or similar that I can call and test on. I figure I am 50% fluent in Python/CircuitPython. ;-)
BBB
I think you can read a value using square brackets just like it's done in the examples.
self[address]
should read the value at the given address.
Thank you for the tip, however whoever wrote the code is smarter than me. The self._write() call only handle's individual bytes. bytearrays are handled someplace else. buffer = self[address] did not work. The code stopped at the new line of code, no error thrown.
Only Write to a byte if it is different. Read the byte and compare before writing the byte.