adafruit / Adafruit_CircuitPython_24LC32

CircuitPython Driver for Adafruit 24LC32 I2C EEPROM Breakout 32Kbit / 4 KB
MIT License
6 stars 6 forks source link

Only write if byte is different #9

Open b-blake opened 2 years ago

b-blake commented 2 years ago

Only Write to a byte if it is different. Read the byte and compare before writing the byte.

FoamyGuy commented 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?

b-blake commented 2 years ago

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.

FoamyGuy commented 2 years ago

@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.

b-blake commented 2 years ago

@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.

FoamyGuy commented 2 years ago

@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.

b-blake commented 2 years ago

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

FoamyGuy commented 2 years ago

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.

b-blake commented 2 years ago

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.