Skip to content

Commit be48a4d

Browse files
Addressed PR feedback
1 parent d83b538 commit be48a4d

File tree

2 files changed

+65
-26
lines changed

2 files changed

+65
-26
lines changed

Software/Arduino code/OpenAstroTracker/src/Mount.cpp

Lines changed: 64 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,45 @@
4141
#define SLEW_MASK_WEST B1000
4242
#define SLEW_MASK_ANY B1111
4343

44+
// EPROM constants
45+
#define EEPROM_MAGIC_MASK 0xFE00 // If these bits are set to 0xBE00, something has been written to the EEPROM
46+
#define EEPROM_MAGIC_EXTENDED_MASK 0xFE00 // If these bits are set to 0xBF00, an extended value has been written to the EEPROM
47+
#define EEPROM_MAGIC_MARKER 0xBE00
48+
#define EEPROM_MAGIC_EXTENDED_MARKER 0xBF00
49+
50+
// The markjer bits for the first 8 values stored in EEPROM.
51+
#define EEPROM_RA_STEPS_BIT 0x0001
52+
#define EEPROM_DEC_STEPS_BIT 0x0002
53+
#define EEPROM_SPEED_FACTOR_BIT 0x0004
54+
#define EEPROM_BACKLASH_STEPS_BIT 0x0008
55+
#define EEPROM_LATITUDE_BIT 0x0010
56+
#define EEPROM_LONGITUDE_BIT 0x0020
57+
#define EEPROM_PITCH_OFFSET_BIT 0x0040
58+
#define EEPROM_ROLL_OFFSET_BIT 0x0080
59+
60+
// The mask bits to test what is stored
61+
#define EEPROM_MAGIC_MASK_RA_STEPS (EEPROM_MAGIC_MASK | EEPROM_RA_STEPS_BIT)
62+
#define EEPROM_MAGIC_MASK_DEC_STEPS (EEPROM_MAGIC_MASK | EEPROM_DEC_STEPS_BIT)
63+
#define EEPROM_MAGIC_MASK_SPEED_FACTOR (EEPROM_MAGIC_MASK | EEPROM_SPEED_FACTOR_BIT)
64+
#define EEPROM_MAGIC_MASK_BACKLASH_STEPS (EEPROM_MAGIC_MASK | EEPROM_BACKLASH_STEPS_BIT)
65+
#define EEPROM_MAGIC_MASK_LATITUDE (EEPROM_MAGIC_MASK | EEPROM_LATITUDE_BIT)
66+
#define EEPROM_MAGIC_MASK_LONGITUDE (EEPROM_MAGIC_MASK | EEPROM_LONGITUDE_BIT)
67+
#define EEPROM_MAGIC_MASK_PITCH_OFFSET (EEPROM_MAGIC_MASK | EEPROM_PITCH_OFFSET_BIT)
68+
#define EEPROM_MAGIC_MASK_ROLL_OFFSET (EEPROM_MAGIC_MASK | EEPROM_ROLL_OFFSET_BIT)
69+
70+
// The result bits (after masking with above mask) to indicate what is stored
71+
#define EEPROM_RA_STEPS_MARKER_BIT (EEPROM_MAGIC_MARKER | EEPROM_RA_STEPS_BIT)
72+
#define EEPROM_DEC_STEPS_MARKER_BIT (EEPROM_MAGIC_MARKER | EEPROM_DEC_STEPS_BIT)
73+
#define EEPROM_SPEED_FACTOR_MARKER_BIT (EEPROM_MAGIC_MARKER | EEPROM_SPEED_FACTOR_BIT)
74+
#define EEPROM_BACKLASH_STEPS_MARKER_BIT (EEPROM_MAGIC_MARKER | EEPROM_BACKLASH_STEPS_BIT)
75+
#define EEPROM_LATITUDE_MARKER_BIT (EEPROM_MAGIC_MARKER | EEPROM_LATITUDE_BIT)
76+
#define EEPROM_LONGITUDE_MARKER_BIT (EEPROM_MAGIC_MARKER | EEPROM_LONGITUDE_BIT)
77+
#define EEPROM_PITCH_OFFSET_MARKER_BIT (EEPROM_MAGIC_MARKER | EEPROM_PITCH_OFFSET_BIT)
78+
#define EEPROM_ROLL_OFFSET_MARKER_BIT (EEPROM_MAGIC_MARKER | EEPROM_ROLL_OFFSET_BIT)
79+
80+
// Extended bits
81+
#define EEPROM_PARKING_POS_MARKER_BIT 0x0001
82+
4483
const char* formatStringsDEC[] = {
4584
"",
4685
" %c%02d@ %02d' %02d\"", // LCD Menu w/ cursor
@@ -196,15 +235,15 @@ void Mount::readPersistentData()
196235

197236
LOGV2(DEBUG_INFO, F("Mount: EEPROM: Magic Marker: %x "), marker);
198237

199-
if ((marker & 0xFE01) == 0xBE01) {
238+
if ((marker & EEPROM_MAGIC_MASK_RA_STEPS) == EEPROM_RA_STEPS_MARKER_BIT) {
200239
_stepsPerRADegree = EPROMStore::read(6) + EPROMStore::read(7) * 256;
201240
LOGV2(DEBUG_INFO,F("Mount: EEPROM: RA Marker OK! RA steps/deg is %d"), _stepsPerRADegree);
202241
}
203242
else{
204243
LOGV1(DEBUG_INFO,F("Mount: EEPROM: No stored value for RA steps"));
205244
}
206245

207-
if ((marker & 0xFE02) == 0xBE02) {
246+
if ((marker & EEPROM_MAGIC_MASK_DEC_STEPS) == EEPROM_DEC_STEPS_MARKER_BIT) {
208247
_stepsPerDECDegree = EPROMStore::read(8) + EPROMStore::read(9) * 256;
209248
LOGV2(DEBUG_INFO,F("Mount: EEPROM: DEC Marker OK! DEC steps/deg is %d"), _stepsPerDECDegree);
210249
}
@@ -213,7 +252,7 @@ void Mount::readPersistentData()
213252
}
214253

215254
float speed = 1.0;
216-
if ((marker & 0xFE04) == 0xBE04) {
255+
if ((marker & EEPROM_MAGIC_MASK_SPEED_FACTOR) == EEPROM_SPEED_FACTOR_MARKER_BIT) {
217256
int adjust = EPROMStore::read(0) + EPROMStore::read(3) * 256;
218257
speed = 1.0 + 1.0 * adjust / 10000.0;
219258
LOGV3(DEBUG_INFO,F("Mount: EEPROM: Speed Marker OK! Speed adjust is %d, speedFactor is %f"), adjust, speed);
@@ -222,23 +261,23 @@ void Mount::readPersistentData()
222261
LOGV1(DEBUG_INFO,F("Mount: EEPROM: No stored value for speed factor"));
223262
}
224263

225-
if ((marker & 0xFE08) == 0xBE08) {
264+
if ((marker & EEPROM_MAGIC_MASK_BACKLASH_STEPS) == EEPROM_BACKLASH_STEPS_MARKER_BIT) {
226265
_backlashCorrectionSteps = EPROMStore::read(10) + EPROMStore::read(11) * 256;
227266
LOGV2(DEBUG_INFO,F("Mount: EEPROM: Backlash Steps Marker OK! Backlash correction is %d"), _backlashCorrectionSteps);
228267
}
229268
else {
230269
LOGV1(DEBUG_INFO,F("Mount: EEPROM: No stored value for backlash correction"));
231270
}
232271

233-
if ((marker & 0xFE10) == 0xBE10) {
272+
if ((marker & EEPROM_MAGIC_MASK_LATITUDE) == EEPROM_LATITUDE_MARKER_BIT) {
234273
_latitude = 1.0f * EPROMStore::readInt16(12, 13) / 100.0f;
235274
LOGV2(DEBUG_INFO,F("Mount: EEPROM: Latitude Marker OK! Latitude is %f"), _latitude);
236275
}
237276
else {
238277
LOGV1(DEBUG_INFO,F("Mount: EEPROM: No stored value for latitude"));
239278
}
240279

241-
if ((marker & 0xFE20) == 0xBE20) {
280+
if ((marker & EEPROM_MAGIC_MASK_LONGITUDE) == EEPROM_LONGITUDE_MARKER_BIT) {
242281
_longitude = 1.0f * EPROMStore::readInt16(14, 15) / 100.0f;
243282
LOGV2(DEBUG_INFO,F("Mount: EEPROM: Longitude Marker OK! Longitude is %f"), _longitude);
244283
}
@@ -247,7 +286,7 @@ void Mount::readPersistentData()
247286
}
248287

249288
#if USE_GYRO_LEVEL == 1
250-
if ((marker & 0xFE40) == 0xBE40) {
289+
if ((marker & EEPROM_MAGIC_MASK_PITCH_OFFSET) == EEPROM_PITCH_OFFSET_MARKER_BIT) {
251290
uint16_t angleValue = EPROMStore::readInt16(17, 18);
252291
_pitchCalibrationAngle = (((long)angleValue) - 16384) / 100.0;
253292
LOGV3(DEBUG_INFO,F("Mount: EEPROM: Pitch Offset Marker OK! Pitch Offset is %x (%f)"), angleValue, _pitchCalibrationAngle);
@@ -256,7 +295,7 @@ void Mount::readPersistentData()
256295
LOGV1(DEBUG_INFO,F("Mount: EEPROM: No stored value for Pitch Offset"));
257296
}
258297

259-
if ((marker & 0xFE80) == 0xBE80) {
298+
if ((marker & EEPROM_MAGIC_MASK_ROLL_OFFSET) == EEPROM_ROLL_OFFSET_MARKER_BIT) {
260299
uint16_t angleValue = EPROMStore::readInt16(19,20);
261300
_rollCalibrationAngle = (((long)angleValue) - 16384) / 100.0;
262301
LOGV3(DEBUG_INFO,F("Mount: EEPROM: Roll Offset Marker OK! Roll Offset is %x (%f)"), angleValue, _rollCalibrationAngle);
@@ -266,11 +305,11 @@ void Mount::readPersistentData()
266305
}
267306
#endif
268307

269-
if ((marker & 0xFF00) == 0xBF00) {
308+
if ((marker & EEPROM_MAGIC_EXTENDED_MASK) == EEPROM_MAGIC_EXTENDED_MARKER) {
270309
LOGV2(DEBUG_INFO,F("Mount: EEPROM: Magic Marker is %x, reading extended"), marker);
271310
int16_t nextMarker = EPROMStore::readInt16(21,22);
272311
LOGV2(DEBUG_INFO,F("Mount: EEPROM: ExtendedMarker is %x"), nextMarker);
273-
if (nextMarker & 0x0001){
312+
if (nextMarker & EEPROM_PARKING_POS_MARKER_BIT){
274313
_raParkingPos = EPROMStore::readInt32(23); // 23-26
275314
_decParkingPos = EPROMStore::readInt32(27); // 27-30
276315
LOGV3(DEBUG_INFO,F("Mount: EEPROM: Parking position read as R:%l, D:%l"), _raParkingPos, _decParkingPos);
@@ -297,12 +336,12 @@ void Mount::writePersistentData(int which, long val)
297336
bool writeExtended = false;
298337

299338
// If we're written something before...
300-
uint8_t magicMarker = EPROMStore::read(5);
301-
LOGV5(DEBUG_INFO,F("Mount: EEPROM Write(%d): Marker is %x, flag is %x (%d)"), which, magicMarker, flag, flag);
302-
if ((magicMarker & 0xFE) == 0xBE) {
339+
uint16_t magicMarker = EPROMStore::read(5) * 256 + EPROMStore::read(4);
340+
LOGV3(DEBUG_INFO,F("Mount: EEPROM Write(%d): Marker is %x"), which, magicMarker);
341+
if ((magicMarker & EEPROM_MAGIC_MASK) == EEPROM_MAGIC_MARKER) {
303342
// ... read the current state ...
304343
flag = EPROMStore::read(4);
305-
if ((magicMarker & 0xFF) == 0xBF) {
344+
if ((magicMarker & EEPROM_MAGIC_EXTENDED_MASK) == EEPROM_MAGIC_EXTENDED_MARKER) {
306345
extendedFlag = EPROMStore::readInt16(21, 22);
307346
LOGV3(DEBUG_INFO,F("Mount: EEPROM Write: Marker is 0xBF, extended flag is %x (%d)"), extendedFlag, extendedFlag);
308347
}
@@ -314,7 +353,7 @@ void Mount::writePersistentData(int which, long val)
314353
case EEPROM_RA:
315354
{
316355
// ... set bit 0 to indicate RA value has been written to 6/7
317-
flag |= 0x01;
356+
flag |= EEPROM_RA_STEPS_BIT;
318357
loByteLocation = 6;
319358
hiByteLocation = 7;
320359
LOGV2(DEBUG_INFO,F("Mount: EEPROM Write: Updating RA steps to %d"), val);
@@ -324,7 +363,7 @@ void Mount::writePersistentData(int which, long val)
324363
case EEPROM_DEC:
325364
{
326365
// ... set bit 1 to indicate DEC value has been written to 8/9
327-
flag |= 0x02;
366+
flag |= EEPROM_DEC_STEPS_BIT;
328367
loByteLocation = 8;
329368
hiByteLocation = 9;
330369
LOGV2(DEBUG_INFO,F("Mount: EEPROM Write: Updating DEC steps to %d"), val);
@@ -334,7 +373,7 @@ void Mount::writePersistentData(int which, long val)
334373
case EEPROM_SPEED:
335374
{
336375
// ... set bit 3 to indicate speed factor value has been written to 0/3
337-
flag |= 0x04;
376+
flag |= EEPROM_SPEED_FACTOR_BIT;
338377
loByteLocation = 0;
339378
hiByteLocation = 3;
340379
LOGV2(DEBUG_INFO,F("Mount: EEPROM Write: Updating Speed factor to %d"), val);
@@ -344,7 +383,7 @@ void Mount::writePersistentData(int which, long val)
344383
case EEPROM_BACKLASH:
345384
{
346385
// ... set bit 4 to indicate backlash has been written to 10/11
347-
flag |= 0x08;
386+
flag |= EEPROM_BACKLASH_STEPS_BIT;
348387
loByteLocation = 10;
349388
hiByteLocation = 11;
350389
LOGV2(DEBUG_INFO,F("Mount: EEPROM Write: Updating Backlash to %d"), val);
@@ -354,7 +393,7 @@ void Mount::writePersistentData(int which, long val)
354393
case EEPROM_LATITUDE:
355394
{
356395
// ... set bit 5 to indicate Latitude x100 has been written to 12/13
357-
flag |= 0x10;
396+
flag |= EEPROM_LATITUDE_BIT;
358397
loByteLocation = 12;
359398
hiByteLocation = 13;
360399
LOGV2(DEBUG_INFO,F("Mount: EEPROM Write: Updating Latitude to %d"), val);
@@ -364,7 +403,7 @@ void Mount::writePersistentData(int which, long val)
364403
case EEPROM_LONGITUDE:
365404
{
366405
// ... set bit 6 to indicate Longitude x100 has been written to 14/15
367-
flag |= 0x20;
406+
flag |= EEPROM_LONGITUDE_BIT;
368407
loByteLocation = 14;
369408
hiByteLocation = 15;
370409
LOGV2(DEBUG_INFO,F("Mount: EEPROM Write: Updating Longitude to %d"), val);
@@ -374,7 +413,7 @@ void Mount::writePersistentData(int which, long val)
374413
case EEPROM_PITCH_OFFSET:
375414
{
376415
// ... set bit 7 to indicate pitch offset angle value has been written to 17/18
377-
flag |= 0x40;
416+
flag |= EEPROM_PITCH_OFFSET_BIT;
378417
loByteLocation = 17;
379418
hiByteLocation = 18;
380419
LOGV2(DEBUG_INFO,F("Mount: EEPROM Write: Updating Pitch Offset to %d"), val);
@@ -384,7 +423,7 @@ void Mount::writePersistentData(int which, long val)
384423
case EEPROM_ROLL_OFFSET:
385424
{
386425
// ... set bit 8 to indicate pitch offset angle value has been written to 19/20
387-
flag |= 0x80;
426+
flag |= EEPROM_ROLL_OFFSET_BIT;
388427
loByteLocation = 19;
389428
hiByteLocation = 20;
390429
LOGV2(DEBUG_INFO,F("Mount: EEPROM Write: Updating Roll Offset to %d"), val);
@@ -396,7 +435,7 @@ void Mount::writePersistentData(int which, long val)
396435
{
397436
// ... set bit 8 to indicate pitch offset angle value has been written to 19/20
398437
writeExtended = true;
399-
extendedFlag |= 0x0001;
438+
extendedFlag |= EEPROM_PARKING_POS_MARKER_BIT;
400439
if (which == EEPROM_RA_PARKING_POS ){
401440
EPROMStore::updateInt32(23, val);
402441
LOGV2(DEBUG_INFO,F("Mount: EEPROM Write: Updating RA Parking Pos to %l at 23-26"), val);
@@ -412,13 +451,13 @@ void Mount::writePersistentData(int which, long val)
412451

413452
if (writeExtended) {
414453
LOGV3(DEBUG_INFO,F("Mount: EEPROM Write: New Marker is 0xBF, extended flag is %x (%d)"), extendedFlag, extendedFlag);
415-
EPROMStore::update(5, 0xBF);
454+
EPROMStore::update(5, EEPROM_MAGIC_EXTENDED_MARKER >> 8);
416455
EPROMStore::updateInt16(21, 22, extendedFlag);
417456
}
418457
else {
419458
LOGV4(DEBUG_INFO,F("Mount: EEPROM Write: New Marker is %d, flag is %x (%d)"), magicMarker, flag, flag);
420459
EPROMStore::update(4, flag);
421-
EPROMStore::update(5, magicMarker);
460+
EPROMStore::update(5, magicMarker >> 8);
422461

423462
EPROMStore::update(loByteLocation, val & 0x00FF);
424463
EPROMStore::update(hiByteLocation, (val >> 8) & 0x00FF);

Software/Arduino code/OpenAstroTracker/src/c72_menuHA_GPS.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ void printHASubmenu()
183183
}
184184
else if (haState == STARTING_GPS)
185185
{
186-
sprintf(satBuffer, " Found %u sats", gps.satellites.value());
186+
sprintf(satBuffer, " Found %lu sats", gps.satellites.value());
187187
satBuffer[0] = ind[indicator];
188188
}
189189
else if (haState == ENTER_HA_MANUALLY)

0 commit comments

Comments
 (0)