@@ -101,33 +101,41 @@ struct EERef{
101
101
struct EEBit {
102
102
103
103
// Constructor, use by passing in index of EEPROM byte, then index of bit to read.
104
- EEBit ( int index, uint8_t bidx )
105
- : ref( index ), mask( 0x01 << bidx ) {}
104
+ EEBit ( EEBitPtr ptr )
105
+ : ptr( ptr ) {}
106
106
107
107
// Modifier functions.
108
- EEBit &setIndex ( uint8_t bidx ) { return mask = (0x01 << bidx), *this ; }
109
108
EEBit &set () { return *this = true ; }
110
109
EEBit &clear () { return *this = false ; }
111
110
112
111
// Read/write functions.
113
- operator bool () const { return ref & mask; }
114
- EEBit &operator =( const EEBit © ) { return *this = ( const bool ) copy; }
112
+ operator bool () const { return *ptr. ref & ptr. mask ; }
113
+ EEBit &operator =( const EEBit © ) { return *this = ( bool ) copy; }
115
114
116
115
EEBit &operator =( const bool © ){
117
- if ( copy ) ref |= mask;
118
- else ref &= ~mask;
116
+ EERef cell = *ptr.ref ;
117
+ if ( copy ) cell |= ptr.mask ;
118
+ else cell &= ~mask;
119
119
return *this ;
120
120
}
121
121
122
+ const EEBitPtr ptr;
123
+ }
124
+
125
+ struct EEBitPtr {
126
+ // Constructor, use by passing in index of EEPROM byte, then index of bit to read.
127
+ EEBitPtr ( int index, uint8_t bidx )
128
+ : ptr( index ), mask( 0x01 << bidx ) {}
129
+
122
130
// Iterator functionality.
123
- EEBit& operator *() { return *this ; }
124
- bool operator ==( const EEBit &bit ) { return (mask == bit.mask ) && (ref. index == bit.ref . index ); }
125
- bool operator !=( const EEBit &bit ) { return !(*this == bit); }
131
+ EEBit operator *() const { return EEBit ( *this ) ; }
132
+ bool operator ==( const EEBitPtr &bit ) const { return (mask == bit.mask ) && (ptr == bit.ptr ); }
133
+ bool operator !=( const EEBitPtr &bit ) const { return !(*this == bit); }
126
134
127
135
// Prefix & Postfix increment/decrement
128
136
EEBit& operator ++(){
129
137
if ( mask & 0x80 ){
130
- ++ref. index ;
138
+ ++ptr ;
131
139
mask = 0x01 ;
132
140
}else {
133
141
mask <<= 1 ;
@@ -137,7 +145,7 @@ struct EEBit{
137
145
138
146
EEBit& operator --(){
139
147
if ( mask & 0x01 ){
140
- --ref. index ;
148
+ --ptr ;
141
149
mask = 0x80 ;
142
150
}else {
143
151
mask >>= 1 ;
@@ -155,14 +163,17 @@ struct EEBit{
155
163
return --(*this ), cpy;
156
164
}
157
165
158
- EERef ref ; // Reference to EEPROM cell.
166
+ EEPtr ptr ; // Reference to EEPROM cell.
159
167
uint8_t mask; // Mask of bit to read/write.
160
168
};
161
169
170
+ // Deferred definition till EEBitPtr becomes available.
171
+ inline EEBitPtr EEBit::operator &() const { return ptr; }
172
+
162
173
// Deferred definition till EEBit becomes available.
163
- inline EEBit EERef::operator []( const int bidx ) { return EEBit ( index , bidx ); }
164
- inline EEBit EERef::begin () { return EEBit ( index , 0 ); }
165
- inline EEBit EERef::end () { return EEBit ( index + 1 , 0 ); }
174
+ inline EEBit EERef::operator []( const int bidx ) { return * EEBitPtr ( index , bidx ); }
175
+ inline EEBitPtr EERef::begin () { return EEBitPtr ( index , 0 ); }
176
+ inline EEBitPtr EERef::end () { return EEBitPtr ( index + 1 , 0 ); }
166
177
167
178
168
179
/* **
0 commit comments