diff --git a/3rdparty/indi-asi/asi_focuser.cpp b/3rdparty/indi-asi/asi_focuser.cpp index c3807f14..d401d32b 100644 --- a/3rdparty/indi-asi/asi_focuser.cpp +++ b/3rdparty/indi-asi/asi_focuser.cpp @@ -30,6 +30,7 @@ #include #define MAX_DEVICES 4 +#define FOCUS_SETTINGS_TAB "Settings" static int iAvailableFocusersCount; static ASIEAF * focusers[MAX_DEVICES]; @@ -202,6 +203,16 @@ bool ASIEAF::initProperties() IUFillSwitch(&BeepS[BEEL_OFF], "OFF", "Off", ISS_OFF); IUFillSwitchVector(&BeepSP, BeepS, 2, getDeviceName(), "FOCUS_BEEP", "Beep", OPTIONS_TAB, IP_RW, ISR_1OFMANY, 0, IPS_IDLE); + // Enable/Disable backlash + IUFillSwitch(&BacklashCompensationS[BACKLASH_ENABLED], "Enable", "", ISS_OFF); + IUFillSwitch(&BacklashCompensationS[BACKLASH_DISABLED], "Disable", "", ISS_ON); + IUFillSwitchVector(&BacklashCompensationSP, BacklashCompensationS, 2, getDeviceName(), "Backlash Compensation", "", + FOCUS_SETTINGS_TAB, IP_RW, ISR_1OFMANY, 0, IPS_IDLE); + + // Backlash Value + IUFillNumber(&BacklashN[0], "Value", "", "%.f", 0, 9999, 100., 0.); + IUFillNumberVector(&BacklashNP, BacklashN, 1, getDeviceName(), "Backlash", "", FOCUS_SETTINGS_TAB, IP_RW, 0, IPS_IDLE); + FocusRelPosN[0].min = 0.; FocusRelPosN[0].max = m_MaxSteps / 2.0; FocusRelPosN[0].value = 0; @@ -236,10 +247,12 @@ bool ASIEAF::updateProperties() } defineSwitch(&BeepSP); + defineSwitch(&BacklashCompensationSP); + defineNumber(&BacklashNP); GetFocusParams(); - LOG_INFO("ASI EAF paramaters updated, focuser ready for use."); + LOG_INFO("ASI EAF parameters updated, focuser ready for use."); SetTimer(POLLMS); } @@ -248,6 +261,8 @@ bool ASIEAF::updateProperties() if (TemperatureNP.s != IPS_IDLE) deleteProperty(TemperatureNP.name); deleteProperty(BeepSP.name); + deleteProperty(BacklashCompensationSP.name); + deleteProperty(BacklashNP.name); } return true; @@ -267,7 +282,7 @@ bool ASIEAF::Connect() LOGF_ERROR("Failed to connect to ASI EAF focuser ID: %d (%d)", m_ID, rc); return false; } - + AbortFocuser(); return readMaxPosition(); } @@ -343,6 +358,31 @@ bool ASIEAF::readReverse() return true; } +bool ASIEAF::readBacklash() +{ + int backv = 0; + EAF_ERROR_CODE rc = EAFGetBacklash(m_ID, &backv); + if (rc != EAF_SUCCESS) + { + LOGF_ERROR("Failed to read backlash. Error: %d", rc); + return false; + } + BacklashN[0].value = backv; + BacklashNP.s = IPS_OK; + return true; +} + +bool ASIEAF::setBacklash(uint32_t ticks) +{ + EAF_ERROR_CODE rc = EAFSetBacklash(m_ID, ticks); + if (rc != EAF_SUCCESS) + { + LOGF_ERROR("Failed to set backlash compensation. Error: %d", rc); + return false; + } + return true; +} + bool ASIEAF::readBeep() { bool beep = false; @@ -434,19 +474,42 @@ bool ASIEAF::ISNewSwitch(const char * dev, const char * name, ISState * states, IDSetSwitch(&BeepSP, nullptr); return true; } - } + // Backlash + else if (!strcmp(name, BacklashCompensationSP.name)) + { + IUUpdateSwitch(&BacklashCompensationSP, states, names, n); + bool rc = false; + if (IUFindOnSwitchIndex(&BacklashCompensationSP) == BACKLASH_ENABLED) + rc = setBacklash(BacklashN[0].value); + else + rc = setBacklash(0); + BacklashCompensationSP.s = rc ? IPS_OK : IPS_ALERT; + IDSetSwitch(&BacklashCompensationSP, nullptr); + return true; + } + + } return INDI::Focuser::ISNewSwitch(dev, name, states, names, n); } -//bool ASIEAF::ISNewNumber(const char * dev, const char * name, double values[], char * names[], int n) -//{ -// if (dev != nullptr && strcmp(dev, getDeviceName()) == 0) -// { -// } +bool ASIEAF::ISNewNumber(const char * dev, const char * name, double values[], char * names[], int n) +{ + if (dev != nullptr && strcmp(dev, getDeviceName()) == 0) + { + if (strcmp(name, BacklashNP.name) == 0) + { + IUUpdateNumber(&BacklashNP, values, names, n); + bool rc = setBacklash(BacklashN[0].value); + BacklashNP.s = rc ? IPS_OK : IPS_ALERT; + + IDSetNumber(&BacklashNP, nullptr); + return true; + } + } -// return INDI::Focuser::ISNewNumber(dev, name, values, names, n); -//} + return INDI::Focuser::ISNewNumber(dev, name, values, names, n); +} void ASIEAF::GetFocusParams() { @@ -458,6 +521,9 @@ void ASIEAF::GetFocusParams() if (readBeep()) IDSetSwitch(&BeepSP, nullptr); + + if (readBacklash()) + IDSetNumber(&BacklashNP, nullptr); } IPState ASIEAF::MoveAbsFocuser(uint32_t targetTicks) @@ -545,9 +611,12 @@ bool ASIEAF::AbortFocuser() return true; } -//bool ASIEAF::saveConfigItems(FILE * fp) -//{ -// Focuser::saveConfigItems(fp); +bool ASIEAF::saveConfigItems(FILE * fp) +{ + Focuser::saveConfigItems(fp); + + IUSaveConfigNumber(fp, &BacklashNP); + IUSaveConfigSwitch(fp, &BacklashCompensationSP); -// return true; -//} + return true; +} diff --git a/3rdparty/indi-asi/asi_focuser.h b/3rdparty/indi-asi/asi_focuser.h index 0f5d9934..05a51197 100644 --- a/3rdparty/indi-asi/asi_focuser.h +++ b/3rdparty/indi-asi/asi_focuser.h @@ -33,7 +33,7 @@ class ASIEAF : public INDI::Focuser const char * getDefaultName() override; virtual bool initProperties() override; virtual bool updateProperties() override; - //virtual bool ISNewNumber(const char * dev, const char * name, double values[], char * names[], int n) override; + virtual bool ISNewNumber(const char * dev, const char * name, double values[], char * names[], int n) override; virtual bool ISNewSwitch(const char * dev, const char * name, ISState * states, char * names[], int n) override; char m_Name[MAXINDINAME]; @@ -68,7 +68,7 @@ class ASIEAF : public INDI::Focuser virtual bool SetFocuserMaxPosition(uint32_t ticks) override; virtual bool AbortFocuser() override; virtual void TimerHit() override; - //virtual bool saveConfigItems(FILE * fp) override; + virtual bool saveConfigItems(FILE * fp) override; private: /** @@ -94,9 +94,13 @@ class ASIEAF : public INDI::Focuser bool readBeep(); // Are we moving? bool isMoving(); + // Read backlash + bool readBacklash(); bool gotoAbsolute(uint32_t position); - double targetPos { 0 }, lastPos { 0 }, lastTemperature { 0 }; + bool setBacklash(uint32_t ticks); + + double targetPos { 0 }, lastPos { 0 }, lastTemperature { 0 }; // Read Only Temperature Reporting INumber TemperatureN[1]; @@ -111,6 +115,15 @@ class ASIEAF : public INDI::Focuser BEEL_OFF }; + // Enable/Disable backlash + ISwitch BacklashCompensationS[2]; + ISwitchVectorProperty BacklashCompensationSP; + enum { BACKLASH_ENABLED, BACKLASH_DISABLED }; + + // Backlash Value + INumber BacklashN[1]; + INumberVectorProperty BacklashNP; + const uint8_t m_ID; const int m_MaxSteps; };