bool NFocus::GetFocusParams() { int ret = -1; currentInOutScalar = INOUTSCALAR_READOUT; if ((ret = updateNFInOutScalar(¤tInOutScalar)) < 0) { InOutScalarNP.s = IPS_ALERT; IDSetNumber(&InOutScalarNP, "Unknown error while reading Nfocus direction tick scalar"); return false; } InOutScalarNP.s = IPS_OK; IDSetNumber(&InOutScalarNP, nullptr); if ((ret = updateNFTemperature(¤tTemperature)) < 0) { TemperatureNP.s = IPS_ALERT; IDSetNumber(&TemperatureNP, "Unknown error while reading Nfocus temperature"); return false; } TemperatureNP.s = IPS_OK; IDSetNumber(&TemperatureNP, nullptr); currentOnTime = currentOffTime = currentFastDelay = 0; if ((ret = updateNFMotorSettings(¤tOnTime, ¤tOffTime, ¤tFastDelay)) < 0) { SettingsNP.s = IPS_ALERT; IDSetNumber(&SettingsNP, "Unknown error while reading Nfocus motor settings"); return false; } SettingsNP.s = IPS_OK; IDSetNumber(&SettingsNP, nullptr); currentMaxTravel = MAXTRAVEL_READOUT; if ((ret = setNFMaxPosition(¤tMaxTravel)) < 0) { MaxTravelNP.s = IPS_ALERT; IDSetNumber(&MaxTravelNP, "Unknown error while reading Nfocus maximum travel"); return false; } MaxTravelNP.s = IPS_OK; IDSetNumber(&MaxTravelNP, nullptr); return true; }
bool NFocus::ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n) { int nset=0,i=0; if(strcmp(dev,getDeviceName())==0) { if (!strcmp (name, SettingsNP.name)) { /* new speed */ double new_onTime = 0 ; double new_offTime = 0 ; double new_fastDelay = 0 ; int ret = -1 ; for (nset = i = 0; i < n; i++) { /* Find numbers with the passed names in the SettingsNP property */ INumber *eqp = IUFindNumber (&SettingsNP, names[i]); /* If the number found is (SettingsN[0]) then process it */ if (eqp == &SettingsN[0]) { new_onTime = (values[i]); nset += new_onTime >= 10 && new_onTime <= 250; } else if (eqp == &SettingsN[1]) { new_offTime = (values[i]); nset += new_offTime >= 1 && new_offTime <= 250; } else if (eqp == &SettingsN[2]) { new_fastDelay = (values[i]); nset += new_fastDelay >= 1 && new_fastDelay <= 9; } } /* Did we process the three numbers? */ if (nset == 3) { /* Set the nfocus state to BUSY */ SettingsNP.s = IPS_BUSY; IDSetNumber(&SettingsNP, NULL); if(( ret= updateNFMotorSettings(&new_onTime, &new_offTime, &new_fastDelay))< 0) { IDSetNumber(&SettingsNP, "Changing to new settings failed"); return false; } currentOnTime = new_onTime ; currentOffTime= new_offTime ; currentFastDelay= new_fastDelay ; SettingsNP.s = IPS_OK; IDSetNumber(&SettingsNP, "Motor settings are now %3.0f %3.0f %3.0f", currentOnTime, currentOffTime, currentFastDelay); return true; } else { /* Set property state to idle */ SettingsNP.s = IPS_IDLE; IDSetNumber(&SettingsNP, "Settings absent or bogus."); return false ; } } if (!strcmp (name, SetBacklashNP.name)) { double new_back = 0 ; int nset = 0; int ret= -1 ; for (nset = i = 0; i < n; i++) { /* Find numbers with the passed names in the SetBacklashNP property */ INumber *eqp = IUFindNumber (&SetBacklashNP, names[i]); /* If the number found is SetBacklash (SetBacklashN[0]) then process it */ if (eqp == &SetBacklashN[0]){ new_back = (values[i]); /* limits */ nset += new_back >= -0xff && new_back <= 0xff; } if (nset == 1) { /* Set the nfocus state to BUSY */ SetBacklashNP.s = IPS_BUSY; IDSetNumber(&SetBacklashNP, NULL); if(( ret= updateNFBacklash(&new_back)) < 0) { SetBacklashNP.s = IPS_IDLE; IDSetNumber(&SetBacklashNP, "Setting new backlash failed."); return false ; } currentSetBacklash= new_back ; SetBacklashNP.s = IPS_OK; IDSetNumber(&SetBacklashNP, "Backlash is now %3.0f", currentSetBacklash) ; return true; } else { SetBacklashNP.s = IPS_IDLE; IDSetNumber(&SetBacklashNP, "Need exactly one parameter."); return false ; } } } if (!strcmp (name, InOutScalarNP.name)) { double new_ioscalar = 0 ; for (nset = i = 0; i < n; i++) { /* Find numbers with the passed names in the InOutScalarNP property */ INumber *eqp = IUFindNumber (&InOutScalarNP, names[i]); /* If the number found is SetBacklash (SetBacklashN[0]) then process it */ if (eqp == &InOutScalarN[0]){ new_ioscalar = (values[i]); /* limits */ nset += new_ioscalar >= 0 && new_ioscalar <= 2; } if (nset == 1) { /* Set the nfocus state to BUSY */ InOutScalarNP.s = IPS_BUSY; /* kraemerf IDSetNumber(&InOutScalarNP, NULL); if(( ret= updateNFInOutScalar(&new_ioscalar)) < 0) { InOutScalarNP.s = IPS_IDLE; IDSetNumber(&InOutScalarNP, "Setting new in/out scalar failed."); return false ; } */ currentInOutScalar= new_ioscalar ; InOutScalarNP.s = IPS_OK; IDSetNumber(&InOutScalarNP, "Direction Scalar is now %1.2f", currentInOutScalar) ; return true; } else { InOutScalarNP.s = IPS_IDLE; IDSetNumber(&InOutScalarNP, "Need exactly one parameter."); return false ; } } } if (!strcmp (name, MinMaxPositionNP.name)) { /* new positions */ double new_min = 0 ; double new_max = 0 ; for (nset = i = 0; i < n; i++) { /* Find numbers with the passed names in the MinMaxPositionNP property */ INumber *mmpp = IUFindNumber (&MinMaxPositionNP, names[i]); /* If the number found is (MinMaxPositionN[0]) then process it */ if (mmpp == &MinMaxPositionN[0]) { new_min = (values[i]); nset += new_min >= 1 && new_min <= 65000; } else if (mmpp == &MinMaxPositionN[1]) { new_max = (values[i]); nset += new_max >= 1 && new_max <= 65000; } } /* Did we process the two numbers? */ if (nset == 2) { /* Set the nfocus state to BUSY */ MinMaxPositionNP.s = IPS_BUSY; currentMinPosition = new_min ; currentMaxPosition= new_max ; MinMaxPositionNP.s = IPS_OK; IDSetNumber(&MinMaxPositionNP, "Minimum and Maximum settings are now %3.0f %3.0f", currentMinPosition, currentMaxPosition); return true; } else { /* Set property state to idle */ MinMaxPositionNP.s = IPS_IDLE; IDSetNumber(&MinMaxPositionNP, "Minimum and maximum limits absent or bogus."); return false; } } if (!strcmp (name, MaxTravelNP.name)) { double new_maxt = 0 ; int ret = -1 ; for (nset = i = 0; i < n; i++) { /* Find numbers with the passed names in the MinMaxPositionNP property */ INumber *mmpp = IUFindNumber (&MaxTravelNP, names[i]); /* If the number found is (MaxTravelN[0]) then process it */ if (mmpp == &MaxTravelN[0]) { new_maxt = (values[i]); nset += new_maxt >= 1 && new_maxt <= 64000; } } /* Did we process the one number? */ if (nset == 1) { IDSetNumber(&MinMaxPositionNP, NULL); if(( ret= updateNFMaxPosition(&new_maxt))< 0 ) { MaxTravelNP.s = IPS_IDLE; IDSetNumber(&MaxTravelNP, "Changing to new maximum travel failed"); return false ; } currentMaxTravel= new_maxt ; MaxTravelNP.s = IPS_OK; IDSetNumber(&MaxTravelNP, "Maximum travel is now %3.0f", currentMaxTravel) ; return true; } else { /* Set property state to idle */ MaxTravelNP.s = IPS_IDLE; IDSetNumber(&MaxTravelNP, "Maximum travel absent or bogus."); return false ; } } if (!strcmp (name, SetRegisterPositionNP.name)) { double new_apos = 0 ; int nset = 0; int ret= -1 ; for (nset = i = 0; i < n; i++) { /* Find numbers with the passed names in the SetRegisterPositionNP property */ INumber *srpp = IUFindNumber (&SetRegisterPositionNP, names[i]); /* If the number found is SetRegisterPosition (SetRegisterPositionN[0]) then process it */ if (srpp == &SetRegisterPositionN[0]) { new_apos = (values[i]); /* limits are absolute */ nset += new_apos >= 0 && new_apos <= 64000; } if (nset == 1) { if((new_apos < currentMinPosition) || (new_apos > currentMaxPosition)) { SetRegisterPositionNP.s = IPS_ALERT ; IDSetNumber(&SetRegisterPositionNP, "Value out of limits %5.0f", new_apos); return false ; } /* Set the nfocus state to BUSY */ SetRegisterPositionNP.s = IPS_BUSY; IDSetNumber(&SetRegisterPositionNP, NULL); if(( ret= updateNFSetPosition(&new_apos)) < 0) { SetRegisterPositionNP.s = IPS_OK; IDSetNumber(&SetRegisterPositionNP, "Read out of the set position to %3d failed. Trying to recover the position", ret); if((ret= updateNFPosition( ¤tPosition)) < 0) { FocusAbsPosNP.s = IPS_ALERT; IDSetNumber(&FocusAbsPosNP, "Unknown error while reading Nfocus position: %d", ret); SetRegisterPositionNP.s = IPS_IDLE; IDSetNumber(&SetRegisterPositionNP, "Relative movement failed."); } SetRegisterPositionNP.s = IPS_OK; IDSetNumber(&SetRegisterPositionNP, NULL); FocusAbsPosNP.s = IPS_OK; IDSetNumber(&FocusAbsPosNP, "Nfocus position recovered %5.0f", currentPosition); IDMessage( getDeviceName(), "Nfocus position recovered resuming normal operation"); /* We have to leave here, because new_apos is not set */ return true ; } currentPosition= new_apos ; SetRegisterPositionNP.s = IPS_OK; IDSetNumber(&SetRegisterPositionNP, "Nfocus register set to %5.0f", currentPosition); FocusAbsPosNP.s = IPS_OK; IDSetNumber(&FocusAbsPosNP, "Nfocus position is now %5.0f", currentPosition); return true ; } else { SetRegisterPositionNP.s = IPS_IDLE; IDSetNumber(&SetRegisterPositionNP, "Need exactly one parameter."); return false; } if((ret= updateNFPosition(¤tPosition)) < 0) { FocusAbsPosNP.s = IPS_ALERT; IDSetNumber(&FocusAbsPosNP, "Unknown error while reading Nfocus position: %d", ret); return false ; } SetRegisterPositionNP.s = IPS_OK; IDSetNumber(&SetRegisterPositionNP, "Nfocus has accepted new register setting" ) ; FocusAbsPosNP.s = IPS_OK; IDSetNumber(&FocusAbsPosNP, "Nfocus new position %5.0f", currentPosition); return true; } } } return INDI::Focuser::ISNewNumber(dev, name, values, names, n); }
bool NFocus::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) { int nset = 0, i = 0; if (dev != nullptr && strcmp(dev, getDeviceName()) == 0) { if (strcmp(name, SettingsNP.name) == 0) { /* new speed */ double new_onTime = 0; double new_offTime = 0; double new_fastDelay = 0; int ret = -1; for (nset = i = 0; i < n; i++) { /* Find numbers with the passed names in the SettingsNP property */ INumber *eqp = IUFindNumber(&SettingsNP, names[i]); /* If the number found is (SettingsN[0]) then process it */ if (eqp == &SettingsN[0]) { new_onTime = (values[i]); nset += static_cast<int>(new_onTime >= 10 && new_onTime <= 250); } else if (eqp == &SettingsN[1]) { new_offTime = (values[i]); nset += static_cast<int>(new_offTime >= 1 && new_offTime <= 250); } else if (eqp == &SettingsN[2]) { new_fastDelay = (values[i]); nset += static_cast<int>(new_fastDelay >= 1 && new_fastDelay <= 9); } } /* Did we process the three numbers? */ if (nset == 3) { if ((ret = updateNFMotorSettings(&new_onTime, &new_offTime, &new_fastDelay)) < 0) { IDSetNumber(&SettingsNP, "Changing to new settings failed"); return false; } currentOnTime = new_onTime; currentOffTime = new_offTime; currentFastDelay = new_fastDelay; SettingsNP.s = IPS_OK; IDSetNumber(&SettingsNP, "Motor settings are now %3.0f %3.0f %3.0f", currentOnTime, currentOffTime, currentFastDelay); return true; } else { /* Set property state to idle */ SettingsNP.s = IPS_IDLE; IDSetNumber(&SettingsNP, "Settings absent or bogus."); return false; } } if (strcmp(name, InOutScalarNP.name) == 0) { double new_ioscalar = 0; for (nset = i = 0; i < n; i++) { /* Find numbers with the passed names in the InOutScalarNP property */ INumber *eqp = IUFindNumber(&InOutScalarNP, names[i]); /* If the number found is SetBacklash (SetBacklashN[0]) then process it */ if (eqp == &InOutScalarN[0]) { new_ioscalar = (values[i]); /* limits */ nset += static_cast<int>(new_ioscalar >= 0 && new_ioscalar <= 2); } if (nset == 1) { /* Set the nfocus state to BUSY */ InOutScalarNP.s = IPS_BUSY; /* kraemerf IDSetNumber(&InOutScalarNP, nullptr); if(( ret= updateNFInOutScalar(&new_ioscalar)) < 0) { InOutScalarNP.s = IPS_IDLE; IDSetNumber(&InOutScalarNP, "Setting new in/out scalar failed."); return false ; } */ currentInOutScalar = new_ioscalar; InOutScalarNP.s = IPS_OK; IDSetNumber(&InOutScalarNP, "Direction Scalar is now %1.2f", currentInOutScalar); return true; } else { InOutScalarNP.s = IPS_IDLE; IDSetNumber(&InOutScalarNP, "Need exactly one parameter."); return false; } } } if (strcmp(name, MinMaxPositionNP.name) == 0) { /* new positions */ double new_min = 0; double new_max = 0; for (nset = i = 0; i < n; i++) { /* Find numbers with the passed names in the MinMaxPositionNP property */ INumber *mmpp = IUFindNumber(&MinMaxPositionNP, names[i]); /* If the number found is (MinMaxPositionN[0]) then process it */ if (mmpp == &MinMaxPositionN[0]) { new_min = (values[i]); nset += static_cast<int>(new_min >= 1 && new_min <= 65000); } else if (mmpp == &MinMaxPositionN[1]) { new_max = (values[i]); nset += static_cast<int>(new_max >= 1 && new_max <= 65000); } } /* Did we process the two numbers? */ if (nset == 2) { /* Set the nfocus state to BUSY */ MinMaxPositionNP.s = IPS_BUSY; currentMinPosition = new_min; currentMaxPosition = new_max; MinMaxPositionNP.s = IPS_OK; IDSetNumber(&MinMaxPositionNP, "Minimum and Maximum settings are now %3.0f %3.0f", currentMinPosition, currentMaxPosition); return true; } else { /* Set property state to idle */ MinMaxPositionNP.s = IPS_IDLE; IDSetNumber(&MinMaxPositionNP, "Minimum and maximum limits absent or bogus."); return false; } } if (strcmp(name, MaxTravelNP.name) == 0) { double new_maxt = 0; int ret = -1; for (nset = i = 0; i < n; i++) { /* Find numbers with the passed names in the MinMaxPositionNP property */ INumber *mmpp = IUFindNumber(&MaxTravelNP, names[i]); /* If the number found is (MaxTravelN[0]) then process it */ if (mmpp == &MaxTravelN[0]) { new_maxt = (values[i]); nset += static_cast<int>(new_maxt >= 1 && new_maxt <= 64000); } } /* Did we process the one number? */ if (nset == 1) { IDSetNumber(&MinMaxPositionNP, nullptr); if ((ret = setNFMaxPosition(&new_maxt)) < 0) { MaxTravelNP.s = IPS_IDLE; IDSetNumber(&MaxTravelNP, "Changing to new maximum travel failed"); return false; } currentMaxTravel = new_maxt; MaxTravelNP.s = IPS_OK; FocusAbsPosN[0].max = currentMaxTravel; IUUpdateMinMax(&FocusAbsPosNP); IDSetNumber(&MaxTravelNP, "Maximum travel is now %3.0f", currentMaxTravel); return true; } else { /* Set property state to idle */ MaxTravelNP.s = IPS_IDLE; IDSetNumber(&MaxTravelNP, "Maximum travel absent or bogus."); return false; } } // Sync if (strcmp(name, SyncNP.name) == 0) { double new_apos = values[0]; int rc = 0; if ((new_apos < currentMinPosition) || (new_apos > currentMaxPosition)) { SyncNP.s = IPS_ALERT; IDSetNumber(&SyncNP, "Value out of limits %5.0f", new_apos); return false; } if ((rc = syncNF(&new_apos)) < 0) { SyncNP.s = IPS_ALERT; IDSetNumber(&SyncNP, "Read out of the set position to %3d failed.", rc); return false; } DEBUGF(INDI::Logger::DBG_DEBUG, "Focuser sycned to %g ticks", new_apos); SyncN[0].value = new_apos; SyncNP.s = IPS_OK; IDSetNumber(&SyncNP, nullptr); IDSetNumber(&FocusAbsPosNP, nullptr); return true; } } return INDI::Focuser::ISNewNumber(dev, name, values, names, n); }
void NFocus::GetFocusParams () { int ret = -1 ; int cur_s1LL=0 ; int cur_s2LR=0 ; int cur_s3RL=0 ; int cur_s4RR=0 ; if((ret= updateNFPosition(¤tPosition)) < 0) { FocusAbsPosNP.s = IPS_ALERT; IDSetNumber(&FocusAbsPosNP, "Unknown error while reading Nfocus position: %d", ret); return; } FocusAbsPosNP.s = IPS_OK; IDSetNumber(&FocusAbsPosNP, NULL); FocusAbsPosN[0].value = currentPosition; IDSetNumber(&FocusAbsPosNP, NULL); currentInOutScalar= INOUTSCALAR_READOUT ; if(( ret= updateNFInOutScalar(¤tInOutScalar)) < 0) { InOutScalarNP.s = IPS_ALERT; IDSetNumber(&InOutScalarNP, "Unknown error while reading Nfocus direction tick scalar"); return; } InOutScalarNP.s = IPS_OK; IDSetNumber(&InOutScalarNP, NULL); if(( ret= updateNFTemperature(¤tTemperature)) < 0) { TemperatureNP.s = IPS_ALERT; IDSetNumber(&TemperatureNP, "Unknown error while reading Nfocus temperature"); return; } TemperatureNP.s = IPS_OK; IDSetNumber(&TemperatureNP, NULL); currentBacklash= BACKLASH_READOUT ; if(( ret= updateNFBacklash(¤tBacklash)) < 0) { SetBacklashNP.s = IPS_ALERT; IDSetNumber(&SetBacklashNP, "Unknown error while reading Nfocus backlash"); return; } SetBacklashNP.s = IPS_OK; IDSetNumber(&SetBacklashNP, NULL); currentOnTime= currentOffTime= currentFastDelay=0 ; if(( ret= updateNFMotorSettings(¤tOnTime, ¤tOffTime, ¤tFastDelay )) < 0) { SettingsNP.s = IPS_ALERT; IDSetNumber(&SettingsNP, "Unknown error while reading Nfocus motor settings"); return; } SettingsNP.s = IPS_OK; IDSetNumber(&SettingsNP, NULL); currentMaxTravel= MAXTRAVEL_READOUT ; if(( ret= updateNFMaxPosition(¤tMaxTravel)) < 0) { MaxTravelNP.s = IPS_ALERT; IDSetNumber(&MaxTravelNP, "Unknown error while reading Nfocus maximum travel"); return; } MaxTravelNP.s = IPS_OK; IDSetNumber(&MaxTravelNP, NULL); }