Exemple #1
0
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;
}
Exemple #2
0
bool FocuserInterface::updateProperties()
{
    if (m_defaultDevice->isConnected())
    {
        //  Now we add our focusser specific stuff
        m_defaultDevice->defineSwitch(&FocusMotionSP);

        if (HasVariableSpeed())
        {
            m_defaultDevice->defineNumber(&FocusSpeedNP);

            // We only define Focus Timer if we can not absolute move
            if (CanAbsMove() == false)
                m_defaultDevice->defineNumber(&FocusTimerNP);
        }
        if (CanRelMove())
            m_defaultDevice->defineNumber(&FocusRelPosNP);
        if (CanAbsMove())
        {
            m_defaultDevice->defineNumber(&FocusAbsPosNP);
            m_defaultDevice->defineNumber(&FocusMaxPosNP);
        }
        if (CanAbort())
            m_defaultDevice->defineSwitch(&FocusAbortSP);
        if (CanSync())
            m_defaultDevice->defineNumber(&FocusSyncNP);
        if (CanReverse())
            m_defaultDevice->defineSwitch(&FocusReverseSP);
    }
    else
    {
        m_defaultDevice->deleteProperty(FocusMotionSP.name);
        if (HasVariableSpeed())
        {
            m_defaultDevice->deleteProperty(FocusSpeedNP.name);

            if (CanAbsMove() == false)
                m_defaultDevice->deleteProperty(FocusTimerNP.name);
        }
        if (CanRelMove())
            m_defaultDevice->deleteProperty(FocusRelPosNP.name);
        if (CanAbsMove())
        {
            m_defaultDevice->deleteProperty(FocusAbsPosNP.name);
            m_defaultDevice->deleteProperty(FocusMaxPosNP.name);
        }
        if (CanAbort())
            m_defaultDevice->deleteProperty(FocusAbortSP.name);
        if (CanSync())
            m_defaultDevice->deleteProperty(FocusSyncNP.name);
        if (CanReverse())
            m_defaultDevice->deleteProperty(FocusReverseSP.name);
    }

    return true;
}
Exemple #3
0
bool INDI::Focuser::updateProperties()
{
    if(isConnected())
    {
        //  Now we add our focusser specific stuff
        defineSwitch(&FocusMotionSP);

        if (HasVariableSpeed())
        {
            defineNumber(&FocusSpeedNP);
            defineNumber(&FocusTimerNP);
        }
        if (CanRelMove())
            defineNumber(&FocusRelPosNP);
        if (CanAbsMove())
            defineNumber(&FocusAbsPosNP);
        if (CanAbort())
            defineSwitch(&AbortSP);
        if (CanAbsMove())
        {
            defineNumber(&PresetNP);
            defineSwitch(&PresetGotoSP);
        }
    } else
    {
        deleteProperty(FocusMotionSP.name);
        if (HasVariableSpeed())
        {
            deleteProperty(FocusSpeedNP.name);
            deleteProperty(FocusTimerNP.name);
        }
        if (CanRelMove())
            deleteProperty(FocusRelPosNP.name);
        if (CanAbsMove())
            deleteProperty(FocusAbsPosNP.name);
        if (CanAbort())
            deleteProperty(AbortSP.name);
        if (CanAbsMove())
        {
            deleteProperty(PresetNP.name);
            deleteProperty(PresetGotoSP.name);
        }
    }

    controller->updateProperties();
    return true;
}
Exemple #4
0
bool FocuserInterface::saveConfigItems(FILE * fp)
{
    if (CanAbsMove())
        IUSaveConfigNumber(fp, &FocusMaxPosNP);
    if (CanReverse())
        IUSaveConfigSwitch(fp, &FocusReverseSP);

    return true;
}
Exemple #5
0
bool FocuserInterface::updateProperties()
{
    if (m_defaultDevice->isConnected())
    {
        //  Now we add our focusser specific stuff
        m_defaultDevice->defineSwitch(&FocusMotionSP);

        if (HasVariableSpeed())
        {
            m_defaultDevice->defineNumber(&FocusSpeedNP);
            m_defaultDevice->defineNumber(&FocusTimerNP);
        }
        if (CanRelMove())
            m_defaultDevice->defineNumber(&FocusRelPosNP);
        if (CanAbsMove())
            m_defaultDevice->defineNumber(&FocusAbsPosNP);
        if (CanAbort())
            m_defaultDevice->defineSwitch(&AbortSP);
    }
    else
    {
        m_defaultDevice->deleteProperty(FocusMotionSP.name);
        if (HasVariableSpeed())
        {
            m_defaultDevice->deleteProperty(FocusSpeedNP.name);
            m_defaultDevice->deleteProperty(FocusTimerNP.name);
        }
        if (CanRelMove())
            m_defaultDevice->deleteProperty(FocusRelPosNP.name);
        if (CanAbsMove())
            m_defaultDevice->deleteProperty(FocusAbsPosNP.name);
        if (CanAbort())
            m_defaultDevice->deleteProperty(AbortSP.name);
    }

    return true;
}
Exemple #6
0
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;
}
Exemple #7
0
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;
}
Exemple #8
0
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);
            }
        }
    }
}