1- #include < EEPROM.h>
2-
31#include " InterruptCallback.hpp"
42
53#include " LcdMenu.hpp"
64#include " Mount.hpp"
75#include " Utility.hpp"
6+ #include " EPROMStore.hpp"
87
98// mountstatus
109#define STATUS_PARKED 0B0000000000000000
@@ -106,6 +105,18 @@ void Mount::startTimerInterrupts()
106105
107106}
108107
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+
109120// ///////////////////////////////
110121//
111122// readPersistentData
@@ -124,29 +135,44 @@ void Mount::startTimerInterrupts()
124135void Mount::readPersistentData ()
125136{
126137 // 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);
129143
130144 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" );
133150 }
134151
135152 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" );
138158 }
139159
140160 float speed = 1.0 ;
141161 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 ;
143163 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" );
145168 }
146169
147170 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" );
150176 }
151177
152178 setSpeedCalibration (speed, false );
@@ -159,15 +185,17 @@ void Mount::readPersistentData()
159185// ///////////////////////////////
160186void Mount::writePersistentData (int which, int val)
161187{
162- int flag = 0x00 ;
188+ uint8_t flag = 0x00 ;
163189 int loByteLocation = 0 ;
164190 int hiByteLocation = 0 ;
165191
166192 // 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 ) {
168196 // ... 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);
171199 }
172200 switch (which) {
173201 case RA_STEPS:
@@ -176,6 +204,7 @@ void Mount::writePersistentData(int which, int val)
176204 flag |= 0x01 ;
177205 loByteLocation = 6 ;
178206 hiByteLocation = 7 ;
207+ LOGV2 (DEBUG_INFO," Mount: EEPROM Write: Updating RA steps to %d" , val);
179208 }
180209 break ;
181210 case DEC_STEPS:
@@ -184,6 +213,7 @@ void Mount::writePersistentData(int which, int val)
184213 flag |= 0x02 ;
185214 loByteLocation = 8 ;
186215 hiByteLocation = 9 ;
216+ LOGV2 (DEBUG_INFO," Mount: EEPROM Write: Updating DEC steps to %d" , val);
187217 }
188218 break ;
189219 case SPEED_FACTOR_DECIMALS:
@@ -192,6 +222,7 @@ void Mount::writePersistentData(int which, int val)
192222 flag |= 0x04 ;
193223 loByteLocation = 0 ;
194224 hiByteLocation = 3 ;
225+ LOGV2 (DEBUG_INFO," Mount: EEPROM Write: Updating Speed factor to %d" , val);
195226 }
196227 break ;
197228 case BACKLASH_CORRECTION:
@@ -200,19 +231,20 @@ void Mount::writePersistentData(int which, int val)
200231 flag |= 0x08 ;
201232 loByteLocation = 10 ;
202233 hiByteLocation = 11 ;
234+ LOGV2 (DEBUG_INFO," Mount: EEPROM Write: Updating Backlash to %d" , val);
203235 }
204236 break ;
205237 }
206238
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);
208240
209- EEPROMupdate (4 , flag);
210- EEPROMupdate (5 , 0xBE );
241+ EPROMStore::Storage ()-> update (4 , flag);
242+ EPROMStore::Storage ()-> update (5 , 0xBE );
211243
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 );
214246
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);
216248}
217249
218250// ///////////////////////////////
0 commit comments