diff --git a/drivers/telescope/lx200_pegasus_nyx101.cpp b/drivers/telescope/lx200_pegasus_nyx101.cpp index 24656d735e..a275561fcd 100644 --- a/drivers/telescope/lx200_pegasus_nyx101.cpp +++ b/drivers/telescope/lx200_pegasus_nyx101.cpp @@ -51,6 +51,7 @@ LX200NYX101::LX200NYX101() TELESCOPE_CAN_CONTROL_TRACK | TELESCOPE_HAS_TIME | TELESCOPE_HAS_LOCATION | + TELESCOPE_CAN_FLIP | TELESCOPE_HAS_TRACK_MODE, SLEW_MODES); } @@ -672,8 +673,12 @@ bool LX200NYX101::ISNewSwitch(const char *dev, const char *name, ISState *states IPState state = IPS_OK; if (isConnected()) { + char status[1] = {0}; FlipSP[0].setState(ISS_OFF); - sendCommand(":MN#"); + sendCommand(":MN#", status, -1, sizeof(status)); + if(*status != '0'){ + state = IPS_ALERT; + } } FlipSP.setState(state); FlipSP.apply(); @@ -788,7 +793,6 @@ bool LX200NYX101::ISNewText(const char *dev, const char *name, char *texts[], ch { if(DebugCommandTP[0].isNameMatch(names[i])) { - char status[DRIVER_LEN] = {0}; sendCommand(texts[i]); i=n; } @@ -1027,6 +1031,105 @@ bool LX200NYX101::sendCommand(const char * cmd, char * res, int cmd_len, int res return true; } +bool LX200NYX101::Flip(double ra, double dec) +{ + return GotoInternal(ra, dec, true); +} + +bool LX200NYX101::Goto(double ra, double dec) +{ + return GotoInternal(ra, dec, false); +} + +int LX200NYX101::Flip(int ) +{ + char status[1] = {0}; + sendCommand(":MN#", status, -1, sizeof(status)); + return static_cast (*status - '0'); +} + +bool LX200NYX101::GotoInternal(double ra, double dec, bool flip) +{ + const struct timespec timeout = {0, 100000000L}; + + targetRA = ra; + targetDEC = dec; + char RAStr[64] = {0}, DecStr[64] = {0}; + int fracbase = 0; + + switch (getLX200EquatorialFormat()) + { + case LX200_EQ_LONGER_FORMAT: + fracbase = 360000; + break; + case LX200_EQ_LONG_FORMAT: + case LX200_EQ_SHORT_FORMAT: + default: + fracbase = 3600; + break; + } + + fs_sexa(RAStr, targetRA, 2, fracbase); + fs_sexa(DecStr, targetDEC, 2, fracbase); + + // If moving, let's stop it first. + if (EqNP.s == IPS_BUSY) + { + if (!isSimulation() && abortSlew(PortFD) < 0) + { + AbortSP.s = IPS_ALERT; + IDSetSwitch(&AbortSP, "Abort slew failed."); + return false; + } + + AbortSP.s = IPS_OK; + EqNP.s = IPS_IDLE; + IDSetSwitch(&AbortSP, "Slew aborted."); + IDSetNumber(&EqNP, nullptr); + + if (MovementNSSP.s == IPS_BUSY || MovementWESP.s == IPS_BUSY) + { + MovementNSSP.s = IPS_IDLE; + MovementWESP.s = IPS_IDLE; + EqNP.s = IPS_IDLE; + IUResetSwitch(&MovementNSSP); + IUResetSwitch(&MovementWESP); + IDSetSwitch(&MovementNSSP, nullptr); + IDSetSwitch(&MovementWESP, nullptr); + } + + // sleep for 100 mseconds + nanosleep(&timeout, nullptr); + } + + if (!isSimulation()) + { + if (setObjectRA(PortFD, targetRA) < 0 || (setObjectDEC(PortFD, targetDEC)) < 0) + { + EqNP.s = IPS_ALERT; + IDSetNumber(&EqNP, "Error setting RA/DEC."); + return false; + } + + int err = 0; + + /* Slew reads the '0', that is not the end of the slew */ + if ((err = flip ? Flip(PortFD) : Slew(PortFD))) + { + LOGF_ERROR("Error %s to JNow RA %s - DEC %s", flip ? "Flipping" : "Slewing", RAStr, DecStr); + slewError(err); + return false; + } + } + + TrackState = SCOPE_SLEWING; + //EqNP.s = IPS_BUSY; + + LOGF_INFO("%s to RA: %s - DEC: %s", flip ? "Flipping" : "Slewing", RAStr, DecStr); + + return true; +} + void LX200NYX101::hexDump(char * buf, const char * data, int size) { for (int i = 0; i < size; i++) diff --git a/drivers/telescope/lx200_pegasus_nyx101.h b/drivers/telescope/lx200_pegasus_nyx101.h index 9325e3e846..90fdfc9371 100644 --- a/drivers/telescope/lx200_pegasus_nyx101.h +++ b/drivers/telescope/lx200_pegasus_nyx101.h @@ -52,8 +52,12 @@ class LX200NYX101 : public LX200Generic virtual bool SetTrackEnabled(bool enabled) override; virtual bool SetTrackMode(uint8_t mode) override; virtual bool SetSlewRate(int index) override; + virtual bool Flip(double ra, double dec) override; + virtual bool Goto(double ra, double dec) override; private: + bool GotoInternal(double ra, double dec, bool flip); + int Flip(int fd); static constexpr const uint8_t SLEW_MODES {10}; static constexpr const uint8_t DRIVER_LEN {64}; static const char DRIVER_STOP_CHAR { 0x23 }; @@ -119,7 +123,6 @@ class LX200NYX101 : public LX200Generic INDI::PropertyNumber MeridianLimitNP {1}; INDI::PropertySwitch SafetyLimitSP {2}; - bool sendCommand(const char * cmd, char * res = nullptr, int cmd_len = -1, int res_len = -1); void hexDump(char * buf, const char * data, int size); std::vector split(const std::string &input, const std::string ®ex);