1
- #include < EEPROM.h>
2
-
3
1
#include " InterruptCallback.hpp"
4
2
5
3
#include " LcdMenu.hpp"
6
4
#include " Mount.hpp"
7
5
#include " Utility.hpp"
6
+ #include " EPROMStore.hpp"
8
7
9
8
// mountstatus
10
9
#define STATUS_PARKED 0B0000000000000000
@@ -106,6 +105,18 @@ void Mount::startTimerInterrupts()
106
105
107
106
}
108
107
108
+ // ///////////////////////////////
109
+ //
110
+ // readConfiguration
111
+ //
112
+ // ///////////////////////////////
113
+ void Mount::readConfiguration ()
114
+ {
115
+ LOGV1 (DEBUG_INFO, " Mount: Reading configuration data from EEPROM" );
116
+ readPersistentData ();
117
+ LOGV1 (DEBUG_INFO, " Mount: Done reading configuration data from EEPROM" );
118
+ }
119
+
109
120
// ///////////////////////////////
110
121
//
111
122
// readPersistentData
@@ -124,29 +135,44 @@ void Mount::startTimerInterrupts()
124
135
void Mount::readPersistentData ()
125
136
{
126
137
// Read the magic marker byte and state
127
- int marker = EEPROM.read (4 ) + EEPROM.read (5 ) * 256 ;
128
- LOGV2 (DEBUG_MOUNT_VERBOSE, " EEPROM: Marker: %x " , marker);
138
+ uint8_t markerLo=EPROMStore::Storage ()->read (4 );
139
+ uint8_t markerHi=EPROMStore::Storage ()->read (5 );
140
+
141
+ uint16_t marker = (uint16_t )markerLo + (uint16_t )markerHi * 256 ;
142
+ LOGV4 (DEBUG_INFO, " Mount: EEPROM: Marker: %x (L:%d H:%d)" , marker, markerLo, markerHi);
129
143
130
144
if ((marker & 0xFF01 ) == 0xBE01 ) {
131
- _stepsPerRADegree = EEPROM.read (6 ) + EEPROM.read (7 ) * 256 ;
132
- LOGV2 (DEBUG_MOUNT," EEPROM: RA Marker OK! RA steps/deg is %d" , _stepsPerRADegree);
145
+ _stepsPerRADegree = EPROMStore::Storage ()->read (6 ) + EPROMStore::Storage ()->read (7 ) * 256 ;
146
+ LOGV2 (DEBUG_INFO," Mount: EEPROM: RA Marker OK! RA steps/deg is %d" , _stepsPerRADegree);
147
+ }
148
+ else {
149
+ LOGV1 (DEBUG_INFO," Mount: EEPROM: No stored value for RA steps" );
133
150
}
134
151
135
152
if ((marker & 0xFF02 ) == 0xBE02 ) {
136
- _stepsPerDECDegree = EEPROM.read (8 ) + EEPROM.read (9 ) * 256 ;
137
- LOGV2 (DEBUG_MOUNT," EEPROM: DEC Marker OK! DEC steps/deg is %d" , _stepsPerDECDegree);
153
+ _stepsPerDECDegree = EPROMStore::Storage ()->read (8 ) + EPROMStore::Storage ()->read (9 ) * 256 ;
154
+ LOGV2 (DEBUG_INFO," Mount: EEPROM: DEC Marker OK! DEC steps/deg is %d" , _stepsPerDECDegree);
155
+ }
156
+ else {
157
+ LOGV1 (DEBUG_INFO," Mount: EEPROM: No stored value for DEC steps" );
138
158
}
139
159
140
160
float speed = 1.0 ;
141
161
if ((marker & 0xFF04 ) == 0xBE04 ) {
142
- int adjust = EEPROM. read (0 ) + EEPROM. read (3 ) * 256 ;
162
+ int adjust = EPROMStore::Storage ()-> read (0 ) + EPROMStore::Storage ()-> read (3 ) * 256 ;
143
163
speed = 1.0 + 1.0 * adjust / 10000.0 ;
144
- LOGV3 (DEBUG_MOUNT," EEPROM: Speed Marker OK! Speed adjust is %d, speedFactor is %f" , adjust, speed);
164
+ LOGV3 (DEBUG_INFO," Mount: EEPROM: Speed Marker OK! Speed adjust is %d, speedFactor is %f" , adjust, speed);
165
+ }
166
+ else {
167
+ LOGV1 (DEBUG_INFO," Mount: EEPROM: No stored value for speed factor" );
145
168
}
146
169
147
170
if ((marker & 0xFF08 ) == 0xBE08 ) {
148
- _backlashCorrectionSteps = EEPROM.read (10 ) + EEPROM.read (11 ) * 256 ;
149
- LOGV2 (DEBUG_MOUNT," EEPROM: Backlash Steps Marker OK! Backlash correction is %d" , _backlashCorrectionSteps);
171
+ _backlashCorrectionSteps = EPROMStore::Storage ()->read (10 ) + EPROMStore::Storage ()->read (11 ) * 256 ;
172
+ LOGV2 (DEBUG_INFO," Mount: EEPROM: Backlash Steps Marker OK! Backlash correction is %d" , _backlashCorrectionSteps);
173
+ }
174
+ else {
175
+ LOGV1 (DEBUG_INFO," Mount: EEPROM: No stored value for backlash correction" );
150
176
}
151
177
152
178
setSpeedCalibration (speed, false );
@@ -159,15 +185,17 @@ void Mount::readPersistentData()
159
185
// ///////////////////////////////
160
186
void Mount::writePersistentData (int which, int val)
161
187
{
162
- int flag = 0x00 ;
188
+ uint8_t flag = 0x00 ;
163
189
int loByteLocation = 0 ;
164
190
int hiByteLocation = 0 ;
165
191
166
192
// If we're written something before...
167
- if (EEPROM.read (5 ) == 0xBE ) {
193
+ uint8_t magicMarker = EPROMStore::Storage ()->read (5 );
194
+ LOGV4 (DEBUG_INFO," Mount: EEPROM Write: Marker is %x, flag is %x (%d)" , magicMarker, flag, flag);
195
+ if (magicMarker == 0xBE ) {
168
196
// ... read the current state ...
169
- flag = EEPROM. read (4 );
170
- LOGV3 (DEBUG_MOUNT, " EEPROM Write: Marker is 0xBE, flag is %x (%d)" , flag, flag);
197
+ flag = EPROMStore::Storage ()-> read (4 );
198
+ LOGV3 (DEBUG_INFO, " Mount: EEPROM Write: Marker is 0xBE, flag is %x (%d)" , flag, flag);
171
199
}
172
200
switch (which) {
173
201
case RA_STEPS:
@@ -176,6 +204,7 @@ void Mount::writePersistentData(int which, int val)
176
204
flag |= 0x01 ;
177
205
loByteLocation = 6 ;
178
206
hiByteLocation = 7 ;
207
+ LOGV2 (DEBUG_INFO," Mount: EEPROM Write: Updating RA steps to %d" , val);
179
208
}
180
209
break ;
181
210
case DEC_STEPS:
@@ -184,6 +213,7 @@ void Mount::writePersistentData(int which, int val)
184
213
flag |= 0x02 ;
185
214
loByteLocation = 8 ;
186
215
hiByteLocation = 9 ;
216
+ LOGV2 (DEBUG_INFO," Mount: EEPROM Write: Updating DEC steps to %d" , val);
187
217
}
188
218
break ;
189
219
case SPEED_FACTOR_DECIMALS:
@@ -192,6 +222,7 @@ void Mount::writePersistentData(int which, int val)
192
222
flag |= 0x04 ;
193
223
loByteLocation = 0 ;
194
224
hiByteLocation = 3 ;
225
+ LOGV2 (DEBUG_INFO," Mount: EEPROM Write: Updating Speed factor to %d" , val);
195
226
}
196
227
break ;
197
228
case BACKLASH_CORRECTION:
@@ -200,19 +231,20 @@ void Mount::writePersistentData(int which, int val)
200
231
flag |= 0x08 ;
201
232
loByteLocation = 10 ;
202
233
hiByteLocation = 11 ;
234
+ LOGV2 (DEBUG_INFO," Mount: EEPROM Write: Updating Backlash to %d" , val);
203
235
}
204
236
break ;
205
237
}
206
238
207
- LOGV3 (DEBUG_MOUNT_VERBOSE, " EEPROM Write: New Marker is 0xBE, flag is %x (%d)" , flag, flag);
239
+ LOGV3 (DEBUG_INFO, " Mount: EEPROM Write: New Marker is 0xBE, flag is %x (%d)" , flag, flag);
208
240
209
- EEPROMupdate (4 , flag);
210
- EEPROMupdate (5 , 0xBE );
241
+ EPROMStore::Storage ()-> update (4 , flag);
242
+ EPROMStore::Storage ()-> update (5 , 0xBE );
211
243
212
- EEPROMupdate (loByteLocation, val & 0x00FF );
213
- EEPROMupdate (hiByteLocation, (val >> 8 ) & 0x00FF );
244
+ EPROMStore::Storage ()-> update (loByteLocation, val & 0x00FF );
245
+ EPROMStore::Storage ()-> update (hiByteLocation, (val >> 8 ) & 0x00FF );
214
246
215
- LOGV5 (DEBUG_MOUNT, " EEPROM Write: wrote %x to %d and %x to %d" , val & 0x00FF , loByteLocation, (val >> 8 ) & 0x00FF , hiByteLocation);
247
+ LOGV5 (DEBUG_INFO, " Mount: EEPROM Write: Wrote %x to %d and %x to %d" , val & 0x00FF , loByteLocation, (val >> 8 ) & 0x00FF , hiByteLocation);
216
248
}
217
249
218
250
// ///////////////////////////////
0 commit comments