Skip to content

Commit

Permalink
Clamp guide ms to [1,999] range. Fixes #2111
Browse files Browse the repository at this point in the history
  • Loading branch information
knro committed Sep 10, 2024
1 parent 81343c6 commit 45cbc79
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions drivers/telescope/lx200ap_v2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ enum APPECRecordingState
};

// maximum guide pulse request to send to controller
#define MAX_LX200AP_PULSE_LEN 999
#define MAX_LX200AP_PULSE_LEN 999u

// The workaround for long pulses doesn't work!
// #define DONT_SIMULATE_LONG_PULSES true
Expand Down Expand Up @@ -1267,11 +1267,8 @@ IPState LX200AstroPhysicsV2::GuideNorth(uint32_t ms)
GuideNSTID = 0;
}

if (ms > MAX_LX200AP_PULSE_LEN)
{
LOGF_DEBUG("GuideNorth truncating %dms pulse to %dms", ms, MAX_LX200AP_PULSE_LEN);
ms = MAX_LX200AP_PULSE_LEN;
}
ms = std::clamp(ms, 1u, MAX_LX200AP_PULSE_LEN);

if (usePulseCommand)
{
APSendPulseCmd(PortFD, LX200_NORTH, ms);
Expand Down Expand Up @@ -1299,11 +1296,9 @@ IPState LX200AstroPhysicsV2::GuideSouth(uint32_t ms)
GuideNSTID = 0;
}

if (ms > MAX_LX200AP_PULSE_LEN)
{
LOGF_DEBUG("GuideSouth truncating %dms pulse to %dms", ms, MAX_LX200AP_PULSE_LEN);
ms = MAX_LX200AP_PULSE_LEN;
}
// Clamp to within 1 to 9999
ms = std::clamp(ms, 1u, MAX_LX200AP_PULSE_LEN);

if (usePulseCommand)
{
APSendPulseCmd(PortFD, LX200_SOUTH, ms);
Expand Down Expand Up @@ -1331,11 +1326,9 @@ IPState LX200AstroPhysicsV2::GuideEast(uint32_t ms)
GuideWETID = 0;
}

if (ms > MAX_LX200AP_PULSE_LEN)
{
LOGF_DEBUG("GuideEast truncating %dms pulse to %dms", ms, MAX_LX200AP_PULSE_LEN);
ms = MAX_LX200AP_PULSE_LEN;
}
// Clamp to within 1 to 9999
ms = std::clamp(ms, 1u, MAX_LX200AP_PULSE_LEN);

if (usePulseCommand)
{
APSendPulseCmd(PortFD, LX200_EAST, ms);
Expand Down Expand Up @@ -1363,11 +1356,9 @@ IPState LX200AstroPhysicsV2::GuideWest(uint32_t ms)
GuideWETID = 0;
}

if (ms > MAX_LX200AP_PULSE_LEN)
{
LOGF_DEBUG("GuideWest truncating %dms pulse to %dms", ms, MAX_LX200AP_PULSE_LEN);
ms = MAX_LX200AP_PULSE_LEN;
}
// Clamp to within 1 to 9999
ms = std::clamp(ms, 1u, MAX_LX200AP_PULSE_LEN);

if (usePulseCommand)
{
APSendPulseCmd(PortFD, LX200_WEST, ms);
Expand Down

0 comments on commit 45cbc79

Please sign in to comment.