diff options
author | Chris--A <chris@genx.biz> | 2015-03-19 17:13:32 +1000 |
---|---|---|
committer | Chris--A <chris@genx.biz> | 2015-03-19 17:13:32 +1000 |
commit | fd4323f360885725c736c90745ee57dbca20e8a0 (patch) | |
tree | 34b56149fb0c46a4b59366fab0fd1600dd755da8 /libraries/EEPROM | |
parent | c9ec4eabdab373c756a624f42660acaf0ec6812d (diff) |
Small tweaks to EEPROM lib and examples.
Diffstat (limited to 'libraries/EEPROM')
-rw-r--r-- | libraries/EEPROM/EEPROM.h | 30 | ||||
-rw-r--r-- | libraries/EEPROM/examples/eeprom_iteration/eeprom_iteration.ino | 8 | ||||
-rw-r--r-- | libraries/EEPROM/examples/eeprom_pointer/eeprom_pointer.ino | 2 |
3 files changed, 14 insertions, 26 deletions
diff --git a/libraries/EEPROM/EEPROM.h b/libraries/EEPROM/EEPROM.h index ae2645e..cde75db 100644 --- a/libraries/EEPROM/EEPROM.h +++ b/libraries/EEPROM/EEPROM.h @@ -92,28 +92,16 @@ struct EEPtr{ operator const int() const { return index; } EEPtr &operator=( int in ) { return index = in, *this; } - //Iterator functionality. bool operator!=( const EEPtr &ptr ) { return index != ptr.index; } - EERef operator*() { return( this->index ); } - + EERef operator*() { return index; } - /** Prefix increment/decrement **/ + /** Prefix & Postfix increment/decrement **/ EEPtr& operator++() { return ++index, *this; } EEPtr& operator--() { return --index, *this; } - - - /** Postfix increment/decrement **/ - EEPtr operator++ (int){ - int ret = index; - return ++index, ret; - } + EEPtr operator++ (int) { return index++; } + EEPtr operator-- (int) { return index--; } - EEPtr operator-- (int){ - int ret = index; - return --index, ret; - } - int index; //Index of current EEPROM cell. }; @@ -128,15 +116,15 @@ struct EEPtr{ struct EEPROMClass{ //Basic user access methods. - EERef operator[]( const int index ) { return( index ); } - uint8_t read( int idx ) { return (EERef( idx )); } + EERef operator[]( const int idx ) { return idx; } + uint8_t read( int idx ) { return EERef( idx ); } void write( int idx, uint8_t val ) { (EERef( idx )) = val; } void update( int idx, uint8_t val ) { EERef( idx ).update( val ); } //STL and C++11 iteration capability. - EEPtr begin() { return( 0x00 ); } - EEPtr end() { return length(); } //Standards requires this to be the item after the last valid entry. The returned pointer is invalid. - uint16_t length() { return E2END + 1; } + EEPtr begin() { return 0x00; } + EEPtr end() { return length(); } //Standards requires this to be the item after the last valid entry. The returned pointer is invalid. + uint16_t length() { return E2END + 1; } //Functionality to 'get' and 'put' objects to and from EEPROM. template< typename T > T &get( int idx, T &t ){ diff --git a/libraries/EEPROM/examples/eeprom_iteration/eeprom_iteration.ino b/libraries/EEPROM/examples/eeprom_iteration/eeprom_iteration.ino index 34071fc..a2d825c 100644 --- a/libraries/EEPROM/examples/eeprom_iteration/eeprom_iteration.ino +++ b/libraries/EEPROM/examples/eeprom_iteration/eeprom_iteration.ino @@ -42,14 +42,14 @@ void setup() { Iterate the EEPROM using a do-while loop. ***/ - int idx = 0; + int idx = 0; //Used 'idx' to avoid name conflict with 'index' above. do{ //Add one to each cell in the EEPROM - EEPROM[ index ] += 1; - index++; - }while( index < EEPROM.length() ); + EEPROM[ idx ] += 1; + idx++; + }while( idx < EEPROM.length() ); /*** Iterate the EEPROM using a C++11 ranged for loop. diff --git a/libraries/EEPROM/examples/eeprom_pointer/eeprom_pointer.ino b/libraries/EEPROM/examples/eeprom_pointer/eeprom_pointer.ino index b56b681..637cdb7 100644 --- a/libraries/EEPROM/examples/eeprom_pointer/eeprom_pointer.ino +++ b/libraries/EEPROM/examples/eeprom_pointer/eeprom_pointer.ino @@ -54,7 +54,7 @@ void setup() { of the C++11 ranged for loop. ***/ - for( EEPtr ptr = EEPROM.begin() ; item != EEPROM.end() ; ++item ){ + for( EEPtr ptr = EEPROM.begin() ; ptr != EEPROM.end() ; ++ptr ){ Serial.print( *ptr, HEX ); Serial.print( ", " ); } |