-
-
Notifications
You must be signed in to change notification settings - Fork 7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New EEPROM library. #2794
New EEPROM library. #2794
Conversation
To avoid having a .cpp just for an extern variable definition, `static` has been chosen over `extern`. As the `EEPROMClass` class simply wraps functionality located elsewhere, it is completely compiled away. Even though each translation unit which includes the header will get a copy with internal linkage, there is no associated overhead. More info [here](http://stackoverflow.com/questions/29098518/extern-variable-only-in-header-unexpectedly-working-why)
@ArduinoBot build this please |
This pull request resolves #178 |
Removed hard coded lengths, which were incorrect for standard Arduino's now.
Hi @Chris--A ,
I prepared a patch (https://gist.github.com/facchinm/93f52a9092d02b010d69) to address these issues, if you believe it's ok I'll merge with that patch applied. |
Probably better to use ifdef guards, like https://github.com/matthijskooijman/Arduino/blob/b85c0bf59812ebba27beb0744758be63632f76b3/hardware/arduino/avr/cores/arduino/WString.h#L62 |
I'd prefer not to use ifdefs in the examples, but of course it's better than an example that does not compile 😉 |
Indeed examples should be as simple as possible. Less noise there is, the easier to explain/understand |
Hi everyone. Thanks for taking the time to respond. As a hobby programmer trying to build a bit of a reputable background, its quite satisfying to see interest in one of my projects so quickly 😄. I do agree, the C++11 functionality should be left until applicable. I'm happy for it to be removed. I do admit the examples were quite rushed. As for the use of Once my version is released as part of the IDE, I plan on starting a forum thread for support, reference and discussion. Not only to inform and help new users with the library, but to get the wider community knowledgeable in it too. It will help create a documentation for all levels of knowledge, or at least provide tips on how to improve the library reference. As a member of the forums for over three years, I have seen how newbies have changed from being artists and photographers. Compared to now, where a large portion of new users have programming experience in other languages, and being able to use things like references and pointer arithmetic while having the technical things like hardware concepts abstracted away could be deemed quite useful. I will take some time after work today and add some improvements. I would like to add a readme and document the new functions (old methods included). As for the pointer and reference examples go, maybe they would be better suited rewritten as documentation, and eventually, some examples that actually use them appropriately, so I'll remove them too. I'm sure some convincing examples will arise once I put it to the forum, I've got a few nice ideas myself, like basic wear leveling. Anyway, I should be able to get something done before Italy wakes up (if this is where you are). Cheers, Chris Andrews. |
I have applied the contents of the patch and added a readme. If you are happy with it, feel free to merge.
Branch deleted, now available in Arduino repo: https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/libraries/EEPROM/README.md |
Hi @Chris--A , Cheers! |
Absolutely awesome, Any forecast on when 1.6.2 is scheduled to be released, I'm assuming at least a few weeks maybe months? |
EEPROM Library V 2.0
This is a new, not just updated, version of the EEPROM library ready for review.
Might as well start with the most important thing first: Yes, this is 100% backwards compatible with the previous version. The new features it provides come with no additional overhead yet provide a huge level of convenience to the end user.
There are a few advanced things I would like to add to this library, however to avoid obfuscating the benefits of this initial proposal, I will add a separate pull request later if this library becomes integrated within the Arduino package.
I can also write a complete documentation up in the form of a readme.md. Then it'll just need copying into the library reference (http://arduino.cc/en/Reference/EEPROM).
Cheers.
New Methods
EEPROM.update( addr, val )
This function is similar to
EEPROM.write()
however thismethod only writes data if the cell contents is different.
EEPROM.get( addr, obj )
This function will retrieve any item from the EEPROM located
at the address specified. It takes a reference to the object
which is filled with the data. Its reference is also returned.
EEPROM.put( addr, obj )
This function will write any item to the EEPROM at the address
specified. This function uses the 'update' method to write its
data, and therefore only rewrites changed cells.
EEPROM.length()
This function returns the number of cells in the EEPROM.
Some AVR processors have larger EEPROM's than others.
EEPROM.begin()
This function returns an
EEPtr
pointing to the first cellin the EEPROM. This is used for iteration by STL objects,
custom iteration and C++11 ranged for loops.
EEPROM.end()
This function returns an
EEPtr
pointing to the locationafter the last EEPROM cell. Used with
begin()
to providecustom iteration and C++11 ranged for loops.
Subscript operator:
EEPROM[x]
This allows using the identifier
EEPROM
like an array.EEPROM cells can be read and written directly
using this method. This operator returns an
EERef
object.New Interfaces
EERef
classThis object references an EEPROM cell.
Its purpose is to mimic a typical byte of RAM, however its storage is the EEPROM.
This class has an overhead of two bytes, similar to storing a pointer to an EEPROM cell.
See example eeprom_reference for usage instructions.
EEPtr
classThis object is a bidirectional pointer to EEPROM cells represented by
EERef
objects.Just like a normal pointer type, this type can be dereferenced and repositioned using
increment/decrement operators. See example eeprom_pointer for usage instructions.
New examples
EEPROM.update()
EEPROM.put()
EEPROM.get()
EEPtr
class.EERef
class.Future.
Thanks for reading, let me know what your thoughts are.