Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added TELESCOPE_CAN_FLIP to capabilities #1964

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 105 additions & 2 deletions drivers/telescope/lx200_pegasus_nyx101.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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<int> (*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++)
Expand Down
5 changes: 4 additions & 1 deletion drivers/telescope/lx200_pegasus_nyx101.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -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<std::string> split(const std::string &input, const std::string &regex);
Expand Down
Loading