bool FocuserInterface::processSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) { INDI_UNUSED(dev); // This one is for us if (strcmp(name, "FOCUS_MOTION") == 0) { // Record last direction and state. FocusDirection prevDirection = FocusMotionS[FOCUS_INWARD].s == ISS_ON ? FOCUS_INWARD : FOCUS_OUTWARD; IPState prevState = FocusMotionSP.s; IUUpdateSwitch(&FocusMotionSP, states, names, n); FocusDirection targetDirection = FocusMotionS[FOCUS_INWARD].s == ISS_ON ? FOCUS_INWARD : FOCUS_OUTWARD; if (CanRelMove() || CanAbsMove() || HasVariableSpeed()) { FocusMotionSP.s = IPS_OK; } // If we are dealing with a simple dumb DC focuser, we move in a specific direction in an open-loop fashion until stopped. else { // If we are reversing direction let's issue abort first. if (prevDirection != targetDirection && prevState == IPS_BUSY) AbortFocuser(); FocusMotionSP.s = MoveFocuser(targetDirection, 0, 0); } IDSetSwitch(&FocusMotionSP, nullptr); return true; } if (strcmp(name, "FOCUS_ABORT_MOTION") == 0) { IUResetSwitch(&AbortSP); if (AbortFocuser()) { AbortSP.s = IPS_OK; if (CanAbsMove() && FocusAbsPosNP.s != IPS_IDLE) { FocusAbsPosNP.s = IPS_IDLE; IDSetNumber(&FocusAbsPosNP, nullptr); } if (CanRelMove() && FocusRelPosNP.s != IPS_IDLE) { FocusRelPosNP.s = IPS_IDLE; IDSetNumber(&FocusRelPosNP, nullptr); } } else AbortSP.s = IPS_ALERT; IDSetSwitch(&AbortSP, nullptr); return true; } return false; }
IPState FocusMaster::MoveFocuser(FocusDirection dir, int speed, uint16_t duration) { INDI_UNUSED(speed); uint8_t command[MAX_FM_BUF] = {0}; if (dir == FOCUS_INWARD) { command[0] = 0x31; command[1] = 0x21; } else { command[0] = 0x32; command[1] = 0x22; } sendCommand(command); gettimeofday(&focusMoveStart, nullptr); focusMoveRequest = duration / 1000.0; if (duration > 0 && duration <= POLLMS) { usleep(duration * 1000); AbortFocuser(); return IPS_OK; } return IPS_BUSY; }
void FocusMaster::TimerHit() { if (!isConnected()) return; //uint32_t currentTicks = 0; if (FocusTimerNP.s == IPS_BUSY) { float remaining = CalcTimeLeft(focusMoveStart, focusMoveRequest); if (remaining <= 0) { FocusTimerNP.s = IPS_OK; FocusTimerN[0].value = 0; AbortFocuser(); } else FocusTimerN[0].value = remaining * 1000.0; IDSetNumber(&FocusTimerNP, nullptr); } #if 0 bool rc = getPosition(¤tTicks); if (rc) FocusAbsPosN[0].value = currentTicks; if (FocusAbsPosNP.s == IPS_BUSY || FocusRelPosNP.s == IPS_BUSY) { if (targetPosition == FocusAbsPosN[0].value) { if (FocusRelPosNP.s == IPS_BUSY) { FocusRelPosNP.s = IPS_OK; IDSetNumber(&FocusRelPosNP, nullptr); } FocusAbsPosNP.s = IPS_OK; LOG_DEBUG("Focuser reached target position."); } } IDSetNumber(&FocusAbsPosNP, nullptr); #endif SetTimer(POLLMS); }
void INDI::Focuser::processButton(const char * button_n, ISState state) { //ignore OFF if (state == ISS_OFF) return; FocusTimerN[0].value = lastTimerValue; IPState rc= IPS_IDLE; // Abort if (!strcmp(button_n, "Abort Focus")) { if (AbortFocuser()) { AbortSP.s = IPS_OK; DEBUG(INDI::Logger::DBG_SESSION, "Focuser aborted."); if (CanAbsMove() && FocusAbsPosNP.s != IPS_IDLE) { FocusAbsPosNP.s = IPS_IDLE; IDSetNumber(&FocusAbsPosNP, NULL); } if (CanRelMove() && FocusRelPosNP.s != IPS_IDLE) { FocusRelPosNP.s = IPS_IDLE; IDSetNumber(&FocusRelPosNP, NULL); } } else { AbortSP.s = IPS_ALERT; DEBUG(INDI::Logger::DBG_ERROR, "Aborting focuser failed."); } IDSetSwitch(&AbortSP, NULL); } // Focus In else if (!strcmp(button_n, "Focus In")) { if (FocusMotionS[FOCUS_INWARD].s != ISS_ON) { FocusMotionS[FOCUS_INWARD].s = ISS_ON; FocusMotionS[FOCUS_OUTWARD].s = ISS_OFF; IDSetSwitch(&FocusMotionSP, NULL); } if (HasVariableSpeed()) { rc = MoveFocuser(FOCUS_INWARD, FocusSpeedN[0].value, FocusTimerN[0].value); FocusTimerNP.s = rc; IDSetNumber(&FocusTimerNP,NULL); } else if (CanRelMove()) { rc=MoveRelFocuser(FOCUS_INWARD, FocusRelPosN[0].value); if (rc == IPS_OK) { FocusRelPosNP.s=IPS_OK; IDSetNumber(&FocusRelPosNP, "Focuser moved %d steps inward", (int) FocusRelPosN[0].value); IDSetNumber(&FocusAbsPosNP, NULL); } else if (rc == IPS_BUSY) { FocusRelPosNP.s=IPS_BUSY; IDSetNumber(&FocusAbsPosNP, "Focuser is moving %d steps inward...", (int) FocusRelPosN[0].value); } } } else if (!strcmp(button_n, "Focus Out")) { if (FocusMotionS[FOCUS_OUTWARD].s != ISS_ON) { FocusMotionS[FOCUS_INWARD].s = ISS_OFF; FocusMotionS[FOCUS_OUTWARD].s = ISS_ON; IDSetSwitch(&FocusMotionSP, NULL); } if (HasVariableSpeed()) { rc = MoveFocuser(FOCUS_OUTWARD, FocusSpeedN[0].value, FocusTimerN[0].value); FocusTimerNP.s = rc; IDSetNumber(&FocusTimerNP,NULL); } else if (CanRelMove()) { rc=MoveRelFocuser(FOCUS_OUTWARD, FocusRelPosN[0].value); if (rc == IPS_OK) { FocusRelPosNP.s=IPS_OK; IDSetNumber(&FocusRelPosNP, "Focuser moved %d steps outward", (int) FocusRelPosN[0].value); IDSetNumber(&FocusAbsPosNP, NULL); } else if (rc == IPS_BUSY) { FocusRelPosNP.s=IPS_BUSY; IDSetNumber(&FocusAbsPosNP, "Focuser is moving %d steps outward...", (int) FocusRelPosN[0].value); } } } }