Skip to content

Commit 95decf1

Browse files
PR feedback
- Removed votatile from variables that aren't accessed in other threads - Extracted common function that calculates elapsed tracking time - Created function to set status to a specific value in a thread-safe way
1 parent 246d2d9 commit 95decf1

2 files changed

Lines changed: 25 additions & 12 deletions

File tree

src/Mount.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2279,6 +2279,13 @@ void Mount::setTrackingStepperPos(long stepPos)
22792279
_stepperTRK->setCurrentPosition(stepPos);
22802280
}
22812281

2282+
void Mount::setStatus(int state)
2283+
{
2284+
noInterrupts();
2285+
_mountStatus = state;
2286+
interrupts();
2287+
}
2288+
22822289
void Mount::setStatusFlag(int flag)
22832290
{
22842291
noInterrupts();
@@ -2590,8 +2597,7 @@ void Mount::startSlewing(int direction)
25902597
setStatusFlag(STATUS_SLEWING);
25912598
}
25922599

2593-
const float trackedHours = (_trackingSpeed > 0) ? ((_stepperTRK->currentPosition() / _trackingSpeed) / 3600.0F)
2594-
: 0.0F; // steps / steps/s / 3600 = hours
2600+
const float trackedHours = getTrackedHours();
25952601
if (direction & EAST)
25962602
{
25972603
// We need to subtract the distance tracked from the physical RA home coordinate
@@ -3279,7 +3285,7 @@ void Mount::loop()
32793285
{
32803286
LOG(DEBUG_MOUNT | DEBUG_STEPPERS, "[MOUNT]: Loop: Already at Parking pos, so done.");
32813287
noInterrupts();
3282-
_mountStatus = STATUS_PARKED;
3288+
setStatus(STATUS_PARKED);
32833289
interrupts();
32843290
}
32853291
}
@@ -3299,7 +3305,7 @@ void Mount::loop()
32993305
{
33003306
LOG(DEBUG_MOUNT | DEBUG_STEPPERS, "[MOUNT]: Loop: Arrived at park position...");
33013307
noInterrupts();
3302-
_mountStatus = STATUS_PARKED;
3308+
setStatus(STATUS_PARKED);
33033309
interrupts();
33043310
_slewingToPark = false;
33053311
}
@@ -3590,8 +3596,7 @@ void Mount::calculateRAandDECSteppers(long &targetRASteps, long &targetDECSteps,
35903596
LOG(DEBUG_COORD_CALC, "[MOUNT]: CalcSteppersIn: moveRA (target) is %f", moveRA);
35913597

35923598
// Total hours of tracking-to-date
3593-
float trackedHours
3594-
= (_trackingSpeed > 0) ? ((_stepperTRK->currentPosition() / _trackingSpeed) / 3600.0F) : 0.0F; // steps / steps/s / 3600 = hours
3599+
float trackedHours = getTrackedHours();
35953600
LOG(DEBUG_COORD_CALC, "[MOUNT]: CalcSteppersIn: Tracked time is %l steps (%f h).", _stepperTRK->currentPosition(), trackedHours);
35963601

35973602
// The current RA of the home position, taking tracking-to-date into account
@@ -4279,15 +4284,19 @@ void Mount::testUART_vactual(TMC2209Stepper *driver, int _speed, int _duration)
42794284
#endif
42804285
#endif
42814286

4287+
float Mount::getTrackedHours()
4288+
{
4289+
return (_trackingSpeed > 0) ? ((_stepperTRK->currentPosition() / _trackingSpeed) / 3600.0F) : 0.0F; // steps / steps/s / 3600 = hours
4290+
}
4291+
42824292
/////////////////////////////////
42834293
//
42844294
// checkRALimit
42854295
//
42864296
/////////////////////////////////
42874297
float Mount::checkRALimit()
42884298
{
4289-
const float trackedHours
4290-
= (_trackingSpeed > 0) ? ((_stepperTRK->currentPosition() / _trackingSpeed) / 3600.0F) : 0.0F; // steps / steps/s / 3600 = hours
4299+
const float trackedHours = getTrackedHours();
42914300
const float homeRA = _zeroPosRA.getTotalHours() + trackedHours;
42924301
const float RALimit = RA_TRACKING_LIMIT;
42934302
LOG(DEBUG_MOUNT_VERBOSE,

src/Mount.hpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,9 @@ class Mount
264264
void setSlewRate(int rate);
265265
int getSlewRate();
266266

267+
// Get the number of hours we've been tracking
268+
float getTrackedHours();
269+
267270
// Set the HA time (HA is derived from LST, the setter calculates and sets LST)
268271
void setHA(const DayTime &haTime);
269272
const DayTime HA() const;
@@ -391,6 +394,7 @@ class Mount
391394
// Returns a comma-delimited string with all the mounts' information
392395
String getStatusString();
393396

397+
void setStatus(int state);
394398
void setStatusFlag(int flag);
395399
void clearStatusFlag(int flag);
396400

@@ -656,14 +660,14 @@ class Mount
656660
EndSwitch *_decEndSwitch;
657661
#endif
658662

659-
volatile unsigned long _guideRaEndTime;
660-
volatile unsigned long _guideDecEndTime;
663+
unsigned long _guideRaEndTime;
664+
unsigned long _guideDecEndTime;
661665
unsigned long _lastMountPrint = 0;
662666
float _trackingSpeed; // RA u-steps/sec when in tracking mode
663667
float _trackingSpeedCalibration; // Dimensionless, very close to 1.0
664668
unsigned long _lastDisplayUpdate;
665-
volatile unsigned long _trackerStoppedAt;
666-
volatile bool _compensateForTrackerOff;
669+
unsigned long _trackerStoppedAt;
670+
bool _compensateForTrackerOff;
667671
volatile int _mountStatus;
668672

669673
char scratchBuffer[24];

0 commit comments

Comments
 (0)