Skip to content

Commit fd4323f

Browse files
committed
Small tweaks to EEPROM lib and examples.
1 parent c9ec4ea commit fd4323f

File tree

3 files changed

+14
-26
lines changed

3 files changed

+14
-26
lines changed

libraries/EEPROM/EEPROM.h

+9-21
Original file line numberDiff line numberDiff line change
@@ -92,28 +92,16 @@ struct EEPtr{
9292
operator const int() const { return index; }
9393
EEPtr &operator=( int in ) { return index = in, *this; }
9494

95-
9695
//Iterator functionality.
9796
bool operator!=( const EEPtr &ptr ) { return index != ptr.index; }
98-
EERef operator*() { return( this->index ); }
99-
97+
EERef operator*() { return index; }
10098

101-
/** Prefix increment/decrement **/
99+
/** Prefix & Postfix increment/decrement **/
102100
EEPtr& operator++() { return ++index, *this; }
103101
EEPtr& operator--() { return --index, *this; }
104-
105-
106-
/** Postfix increment/decrement **/
107-
EEPtr operator++ (int){
108-
int ret = index;
109-
return ++index, ret;
110-
}
102+
EEPtr operator++ (int) { return index++; }
103+
EEPtr operator-- (int) { return index--; }
111104

112-
EEPtr operator-- (int){
113-
int ret = index;
114-
return --index, ret;
115-
}
116-
117105
int index; //Index of current EEPROM cell.
118106
};
119107

@@ -128,15 +116,15 @@ struct EEPtr{
128116
struct EEPROMClass{
129117

130118
//Basic user access methods.
131-
EERef operator[]( const int index ) { return( index ); }
132-
uint8_t read( int idx ) { return (EERef( idx )); }
119+
EERef operator[]( const int idx ) { return idx; }
120+
uint8_t read( int idx ) { return EERef( idx ); }
133121
void write( int idx, uint8_t val ) { (EERef( idx )) = val; }
134122
void update( int idx, uint8_t val ) { EERef( idx ).update( val ); }
135123

136124
//STL and C++11 iteration capability.
137-
EEPtr begin() { return( 0x00 ); }
138-
EEPtr end() { return length(); } //Standards requires this to be the item after the last valid entry. The returned pointer is invalid.
139-
uint16_t length() { return E2END + 1; }
125+
EEPtr begin() { return 0x00; }
126+
EEPtr end() { return length(); } //Standards requires this to be the item after the last valid entry. The returned pointer is invalid.
127+
uint16_t length() { return E2END + 1; }
140128

141129
//Functionality to 'get' and 'put' objects to and from EEPROM.
142130
template< typename T > T &get( int idx, T &t ){

libraries/EEPROM/examples/eeprom_iteration/eeprom_iteration.ino

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ void setup() {
4242
Iterate the EEPROM using a do-while loop.
4343
***/
4444

45-
int idx = 0;
45+
int idx = 0; //Used 'idx' to avoid name conflict with 'index' above.
4646

4747
do{
4848

4949
//Add one to each cell in the EEPROM
50-
EEPROM[ index ] += 1;
51-
index++;
52-
}while( index < EEPROM.length() );
50+
EEPROM[ idx ] += 1;
51+
idx++;
52+
}while( idx < EEPROM.length() );
5353

5454
/***
5555
Iterate the EEPROM using a C++11 ranged for loop.

libraries/EEPROM/examples/eeprom_pointer/eeprom_pointer.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void setup() {
5454
of the C++11 ranged for loop.
5555
***/
5656

57-
for( EEPtr ptr = EEPROM.begin() ; item != EEPROM.end() ; ++item ){
57+
for( EEPtr ptr = EEPROM.begin() ; ptr != EEPROM.end() ; ++ptr ){
5858
Serial.print( *ptr, HEX );
5959
Serial.print( ", " );
6060
}

0 commit comments

Comments
 (0)