bool FocuserInterface::processNumber(const char * dev, const char * name, double values[], char * names[], int n) { // Move focuser based on requested timeout if (!strcmp(name, FocusTimerNP.name)) { FocusDirection dir; int speed; int t; // first we get all the numbers just sent to us IUUpdateNumber(&FocusTimerNP, values, names, n); // Now lets find what we need for this move speed = FocusSpeedN[0].value; if (FocusMotionS[0].s == ISS_ON) dir = FOCUS_INWARD; else dir = FOCUS_OUTWARD; t = FocusTimerN[0].value; lastTimerValue = t; FocusTimerNP.s = MoveFocuser(dir, speed, t); IDSetNumber(&FocusTimerNP, nullptr); return true; } // Set variable focus speed if (!strcmp(name, FocusSpeedNP.name)) { FocusSpeedNP.s = IPS_OK; int current_speed = FocusSpeedN[0].value; IUUpdateNumber(&FocusSpeedNP, values, names, n); if (SetFocuserSpeed(FocusSpeedN[0].value) == false) { FocusSpeedN[0].value = current_speed; FocusSpeedNP.s = IPS_ALERT; } // Update client display IDSetNumber(&FocusSpeedNP, nullptr); return true; } // Update Maximum Position allowed if (!strcmp(name, FocusMaxPosNP.name)) { uint32_t maxTravel = rint(values[0]); if (SetFocuserMaxPosition(maxTravel)) { IUUpdateNumber(&FocusMaxPosNP, values, names, n); FocusAbsPosN[0].max = FocusSyncN[0].max = FocusMaxPosN[0].value; FocusAbsPosN[0].step = FocusSyncN[0].step = FocusMaxPosN[0].value / 50.0; FocusAbsPosN[0].min = FocusSyncN[0].min = 0; FocusRelPosN[0].max = FocusMaxPosN[0].value / 2; FocusRelPosN[0].step = FocusMaxPosN[0].value / 100.0; FocusRelPosN[0].min = 0; IUUpdateMinMax(&FocusAbsPosNP); IUUpdateMinMax(&FocusRelPosNP); IUUpdateMinMax(&FocusSyncNP); FocusMaxPosNP.s = IPS_OK; } else FocusMaxPosNP.s = IPS_ALERT; IDSetNumber(&FocusMaxPosNP, nullptr); return true; } // Sync if (!strcmp(name, FocusSyncNP.name)) { if (SyncFocuser(rint(values[0]))) { FocusSyncN[0].value = FocusAbsPosN[0].value = rint(values[0]); FocusSyncNP.s = IPS_OK; IDSetNumber(&FocusSyncNP, nullptr); IDSetNumber(&FocusAbsPosNP, nullptr); } else { FocusSyncNP.s = IPS_ALERT; IDSetNumber(&FocusSyncNP, nullptr); } return true; } // Update Absolute Focuser Position if (!strcmp(name, FocusAbsPosNP.name)) { int newPos = rint(values[0]); if (newPos < FocusAbsPosN[0].min) { FocusAbsPosNP.s = IPS_ALERT; IDSetNumber(&FocusAbsPosNP, nullptr); DEBUGFDEVICE(dev, Logger::DBG_ERROR, "Requested position out of bound. Focus minimum position is %g", FocusAbsPosN[0].min); return false; } else if (newPos > FocusAbsPosN[0].max) { FocusAbsPosNP.s = IPS_ALERT; IDSetNumber(&FocusAbsPosNP, nullptr); DEBUGFDEVICE(dev, Logger::DBG_ERROR, "Requested position out of bound. Focus maximum position is %g", FocusAbsPosN[0].max); return false; } IPState ret; if ((ret = MoveAbsFocuser(newPos)) == IPS_OK) { FocusAbsPosNP.s = IPS_OK; IUUpdateNumber(&FocusAbsPosNP, values, names, n); DEBUGFDEVICE(dev, Logger::DBG_SESSION, "Focuser moved to position %d", newPos); IDSetNumber(&FocusAbsPosNP, nullptr); return true; } else if (ret == IPS_BUSY) { FocusAbsPosNP.s = IPS_BUSY; DEBUGFDEVICE(dev, Logger::DBG_SESSION, "Focuser is moving to position %d", newPos); IDSetNumber(&FocusAbsPosNP, nullptr); return true; } FocusAbsPosNP.s = IPS_ALERT; DEBUGDEVICE(dev, Logger::DBG_ERROR, "Focuser failed to move to new requested position."); IDSetNumber(&FocusAbsPosNP, nullptr); return false; } // Update Relative focuser steps. This moves the focuser CW/CCW by this number of steps. if (!strcmp(name, FocusRelPosNP.name)) { int newPos = rint(values[0]); if (newPos <= 0) { DEBUGDEVICE(dev, Logger::DBG_ERROR, "Relative ticks value must be greater than zero."); FocusRelPosNP.s = IPS_ALERT; IDSetNumber(&FocusRelPosNP, nullptr); return false; } IPState ret; if (CanAbsMove()) { if (FocusMotionS[0].s == ISS_ON) { if (FocusAbsPosN[0].value - newPos < FocusAbsPosN[0].min) { FocusRelPosNP.s = IPS_ALERT; IDSetNumber(&FocusRelPosNP, nullptr); DEBUGFDEVICE(dev, Logger::DBG_ERROR, "Requested position out of bound. Focus minimum position is %g", FocusAbsPosN[0].min); return false; } } else { if (FocusAbsPosN[0].value + newPos > FocusAbsPosN[0].max) { FocusRelPosNP.s = IPS_ALERT; IDSetNumber(&FocusRelPosNP, nullptr); DEBUGFDEVICE(dev, Logger::DBG_ERROR, "Requested position out of bound. Focus maximum position is %g", FocusAbsPosN[0].max); return false; } } } if ((ret = MoveRelFocuser((FocusMotionS[0].s == ISS_ON ? FOCUS_INWARD : FOCUS_OUTWARD), newPos)) == IPS_OK) { FocusRelPosNP.s = FocusAbsPosNP.s = IPS_OK; IUUpdateNumber(&FocusRelPosNP, values, names, n); IDSetNumber(&FocusRelPosNP, "Focuser moved %d steps %s", newPos, FocusMotionS[0].s == ISS_ON ? "inward" : "outward"); IDSetNumber(&FocusAbsPosNP, nullptr); return true; } else if (ret == IPS_BUSY) { IUUpdateNumber(&FocusRelPosNP, values, names, n); FocusRelPosNP.s = FocusAbsPosNP.s = IPS_BUSY; IDSetNumber(&FocusAbsPosNP, "Focuser is moving %d steps %s...", newPos, FocusMotionS[0].s == ISS_ON ? "inward" : "outward"); IDSetNumber(&FocusAbsPosNP, nullptr); return true; } FocusRelPosNP.s = IPS_ALERT; DEBUGDEVICE(dev, Logger::DBG_ERROR, "Focuser failed to move to new requested position."); IDSetNumber(&FocusRelPosNP, nullptr); return false; } return false; }
bool FocuserInterface::processNumber(const char *dev, const char *name, double values[], char *names[], int n) { // This is for our device // Now lets see if it's something we process here if (strcmp(name, "FOCUS_TIMER") == 0) { FocusDirection dir; int speed; int t; // first we get all the numbers just sent to us IUUpdateNumber(&FocusTimerNP, values, names, n); // Now lets find what we need for this move speed = FocusSpeedN[0].value; if (FocusMotionS[0].s == ISS_ON) dir = FOCUS_INWARD; else dir = FOCUS_OUTWARD; t = FocusTimerN[0].value; lastTimerValue = t; FocusTimerNP.s = MoveFocuser(dir, speed, t); IDSetNumber(&FocusTimerNP, nullptr); return true; } if (strcmp(name, "FOCUS_SPEED") == 0) { FocusSpeedNP.s = IPS_OK; int current_speed = FocusSpeedN[0].value; IUUpdateNumber(&FocusSpeedNP, values, names, n); if (SetFocuserSpeed(FocusSpeedN[0].value) == false) { FocusSpeedN[0].value = current_speed; FocusSpeedNP.s = IPS_ALERT; } // Update client display IDSetNumber(&FocusSpeedNP, nullptr); return true; } if (strcmp(name, "ABS_FOCUS_POSITION") == 0) { int newPos = (int)values[0]; if (newPos < FocusAbsPosN[0].min) { FocusAbsPosNP.s = IPS_ALERT; IDSetNumber(&FocusAbsPosNP, nullptr); DEBUGFDEVICE(dev, Logger::DBG_ERROR, "Requested position out of bound. Focus minimum position is %g", FocusAbsPosN[0].min); return false; } else if (newPos > FocusAbsPosN[0].max) { FocusAbsPosNP.s = IPS_ALERT; IDSetNumber(&FocusAbsPosNP, nullptr); DEBUGFDEVICE(dev, Logger::DBG_ERROR, "Requested position out of bound. Focus maximum position is %g", FocusAbsPosN[0].max); return false; } IPState ret; if ((ret = MoveAbsFocuser(newPos)) == IPS_OK) { FocusAbsPosNP.s = IPS_OK; IUUpdateNumber(&FocusAbsPosNP, values, names, n); DEBUGFDEVICE(dev, Logger::DBG_SESSION, "Focuser moved to position %d", newPos); IDSetNumber(&FocusAbsPosNP, nullptr); return true; } else if (ret == IPS_BUSY) { FocusAbsPosNP.s = IPS_BUSY; DEBUGFDEVICE(dev, Logger::DBG_SESSION, "Focuser is moving to position %d", newPos); IDSetNumber(&FocusAbsPosNP, nullptr); return true; } FocusAbsPosNP.s = IPS_ALERT; DEBUGDEVICE(dev, Logger::DBG_ERROR, "Focuser failed to move to new requested position."); IDSetNumber(&FocusAbsPosNP, nullptr); return false; } if (strcmp(name, "REL_FOCUS_POSITION") == 0) { int newPos = (int)values[0]; if (newPos <= 0) { DEBUGDEVICE(dev, Logger::DBG_ERROR, "Relative ticks value must be greater than zero."); FocusRelPosNP.s = IPS_ALERT; IDSetNumber(&FocusRelPosNP, nullptr); return false; } IPState ret; if (CanAbsMove()) { if (FocusMotionS[0].s == ISS_ON) { if (FocusAbsPosN[0].value - newPos < FocusAbsPosN[0].min) { FocusRelPosNP.s = IPS_ALERT; IDSetNumber(&FocusRelPosNP, nullptr); DEBUGFDEVICE(dev, Logger::DBG_ERROR, "Requested position out of bound. Focus minimum position is %g", FocusAbsPosN[0].min); return false; } } else { if (FocusAbsPosN[0].value + newPos > FocusAbsPosN[0].max) { FocusRelPosNP.s = IPS_ALERT; IDSetNumber(&FocusRelPosNP, nullptr); DEBUGFDEVICE(dev, Logger::DBG_ERROR, "Requested position out of bound. Focus maximum position is %g", FocusAbsPosN[0].max); return false; } } } if ((ret = MoveRelFocuser((FocusMotionS[0].s == ISS_ON ? FOCUS_INWARD : FOCUS_OUTWARD), newPos)) == IPS_OK) { FocusRelPosNP.s = FocusAbsPosNP.s = IPS_OK; IUUpdateNumber(&FocusRelPosNP, values, names, n); IDSetNumber(&FocusRelPosNP, "Focuser moved %d steps %s", newPos, FocusMotionS[0].s == ISS_ON ? "inward" : "outward"); IDSetNumber(&FocusAbsPosNP, nullptr); return true; } else if (ret == IPS_BUSY) { IUUpdateNumber(&FocusRelPosNP, values, names, n); FocusRelPosNP.s = FocusAbsPosNP.s = IPS_BUSY; IDSetNumber(&FocusAbsPosNP, "Focuser is moving %d steps %s...", newPos, FocusMotionS[0].s == ISS_ON ? "inward" : "outward"); IDSetNumber(&FocusAbsPosNP, nullptr); return true; } FocusRelPosNP.s = IPS_ALERT; DEBUGDEVICE(dev, Logger::DBG_ERROR, "Focuser failed to move to new requested position."); IDSetNumber(&FocusRelPosNP, nullptr); return false; } return false; }