From 45cbc790170941b48a867d87b667f506c70b00c2 Mon Sep 17 00:00:00 2001 From: Jasem Mutlaq Date: Tue, 10 Sep 2024 07:16:46 +0300 Subject: [PATCH 1/2] Clamp guide ms to [1,999] range. Fixes #2111 --- drivers/telescope/lx200ap_v2.cpp | 33 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/drivers/telescope/lx200ap_v2.cpp b/drivers/telescope/lx200ap_v2.cpp index 7b3ce6b882..c9564fa8e1 100644 --- a/drivers/telescope/lx200ap_v2.cpp +++ b/drivers/telescope/lx200ap_v2.cpp @@ -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 @@ -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); @@ -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); @@ -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); @@ -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); From 7c65e203de3ce42aedc473d427fff5c036181558 Mon Sep 17 00:00:00 2001 From: Jasem Mutlaq Date: Tue, 10 Sep 2024 07:26:45 +0300 Subject: [PATCH 2/2] usePulseCommand should be intialized to true by default. Fixes #2110 --- drivers/telescope/lx200telescope.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/telescope/lx200telescope.h b/drivers/telescope/lx200telescope.h index 0ab70a5223..bfe408b8fc 100644 --- a/drivers/telescope/lx200telescope.h +++ b/drivers/telescope/lx200telescope.h @@ -189,7 +189,7 @@ class LX200Telescope : public INDI::Telescope, public INDI::GuiderInterface, pub /* Use pulse-guide commands */ ISwitchVectorProperty UsePulseCmdSP; ISwitch UsePulseCmdS[2]; - bool usePulseCommand { false }; + bool usePulseCommand { true }; /* Site Management */ ISwitchVectorProperty SiteSP;