25
25
26
26
/* **
27
27
EERef class.
28
-
28
+
29
29
This object references an EEPROM cell.
30
30
Its purpose is to mimic a typical byte of RAM, however its storage is the EEPROM.
31
31
This class has an overhead of two bytes, similar to storing a pointer to an EEPROM cell.
@@ -35,11 +35,11 @@ struct EERef{
35
35
36
36
EERef ( const int index )
37
37
: index( index ) {}
38
-
38
+
39
39
// Access/read members.
40
40
uint8_t operator *() const { return eeprom_read_byte ( /* (uint8_t*)*/ index ); }
41
- operator const uint8_t () const { return **this ; }
42
-
41
+ operator uint8_t () const { return **this ; }
42
+
43
43
// Assignment/write members.
44
44
EERef &operator =( const EERef &ref ) { return *this = *ref; }
45
45
EERef &operator =( uint8_t in ) { return eeprom_write_byte ( /* (uint8_t*)*/ index, in ), *this ; }
@@ -53,47 +53,47 @@ struct EERef{
53
53
EERef &operator |=( uint8_t in ) { return *this = **this | in; }
54
54
EERef &operator <<=( uint8_t in ) { return *this = **this << in; }
55
55
EERef &operator >>=( uint8_t in ) { return *this = **this >> in; }
56
-
56
+
57
57
EERef &update ( uint8_t in ) { return in != *this ? *this = in : *this ; }
58
-
58
+
59
59
/* * Prefix increment/decrement **/
60
60
EERef& operator ++() { return *this += 1 ; }
61
61
EERef& operator --() { return *this -= 1 ; }
62
-
62
+
63
63
/* * Postfix increment/decrement **/
64
- uint8_t operator ++ (int ){
64
+ uint8_t operator ++ (int ){
65
65
uint8_t ret = **this ;
66
66
return ++(*this ), ret;
67
67
}
68
68
69
- uint8_t operator -- (int ){
69
+ uint8_t operator -- (int ){
70
70
uint8_t ret = **this ;
71
71
return --(*this ), ret;
72
72
}
73
-
73
+
74
74
int index; // Index of current EEPROM cell.
75
75
};
76
76
77
77
/* **
78
78
EEPtr class.
79
-
79
+
80
80
This object is a bidirectional pointer to EEPROM cells represented by EERef objects.
81
- Just like a normal pointer type, this can be dereferenced and repositioned using
81
+ Just like a normal pointer type, this can be dereferenced and repositioned using
82
82
increment/decrement operators.
83
83
***/
84
84
85
85
struct EEPtr {
86
86
87
87
EEPtr ( const int index )
88
88
: index( index ) {}
89
-
90
- operator const int () const { return index; }
89
+
90
+ operator int () const { return index; }
91
91
EEPtr &operator =( int in ) { return index = in, *this ; }
92
-
92
+
93
93
// Iterator functionality.
94
94
bool operator !=( const EEPtr &ptr ) { return index != ptr.index ; }
95
95
EERef operator *() { return index; }
96
-
96
+
97
97
/* * Prefix & Postfix increment/decrement **/
98
98
EEPtr& operator ++() { return ++index, *this ; }
99
99
EEPtr& operator --() { return --index, *this ; }
@@ -105,7 +105,7 @@ struct EEPtr{
105
105
106
106
/* **
107
107
EEPROMClass class.
108
-
108
+
109
109
This object represents the entire EEPROM space.
110
110
It wraps the functionality of EEPtr and EERef into a basic interface.
111
111
This class is also 100% backwards compatible with earlier Arduino core releases.
@@ -118,20 +118,20 @@ struct EEPROMClass{
118
118
uint8_t read ( int idx ) { return EERef ( idx ); }
119
119
void write ( int idx, uint8_t val ) { (EERef ( idx )) = val; }
120
120
void update ( int idx, uint8_t val ) { EERef ( idx ).update ( val ); }
121
-
121
+
122
122
// STL and C++11 iteration capability.
123
123
EEPtr begin () { return 0x00 ; }
124
124
EEPtr end () { return length (); } // Standards requires this to be the item after the last valid entry. The returned pointer is invalid.
125
125
uint16_t length () { return E2END; }
126
-
126
+
127
127
// Functionality to 'get' and 'put' objects to and from EEPROM.
128
128
template < typename T > T &get ( int idx, T &t ){
129
129
EEPtr e = idx;
130
130
uint8_t *ptr = (uint8_t *) &t;
131
131
for ( int count = sizeof (T) ; count ; --count, ++e ) *ptr++ = *e;
132
132
return t;
133
133
}
134
-
134
+
135
135
template < typename T > const T &put ( int idx, const T &t ){
136
136
EEPtr e = idx;
137
137
const uint8_t *ptr = (const uint8_t *) &t;
0 commit comments