Exemplo n.º 1
0
bool ScopeSim::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
{
    if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
    {
        // Slew mode
        if (strcmp(name, SlewRateSP.name) == 0)
        {
            if (IUUpdateSwitch(&SlewRateSP, states, names, n) < 0)
                return false;

            SlewRateSP.s = IPS_OK;
            IDSetSwitch(&SlewRateSP, nullptr);
            return true;
        }

        if (strcmp(name, "PE_NS") == 0)
        {
            IUUpdateSwitch(&PEErrNSSP, states, names, n);

            PEErrNSSP.s = IPS_OK;

            if (PEErrNSS[DIRECTION_NORTH].s == ISS_ON)
            {
                EqPEN[DEC_AXIS].value += TRACKRATE_SIDEREAL/3600.0 * GuideRateN[DEC_AXIS].value;
                DEBUGF(INDI::Logger::DBG_DEBUG, "Simulating PE in NORTH direction for value of %g", TRACKRATE_SIDEREAL/3600.0);
            }
            else
            {
                EqPEN[DEC_AXIS].value -= TRACKRATE_SIDEREAL/3600.0 * GuideRateN[DEC_AXIS].value;
                DEBUGF(INDI::Logger::DBG_DEBUG, "Simulating PE in SOUTH direction for value of %g", TRACKRATE_SIDEREAL/3600.0);
            }

            IUResetSwitch(&PEErrNSSP);
            IDSetSwitch(&PEErrNSSP, nullptr);
            IDSetNumber(&EqPENV, nullptr);

            return true;
        }

        if (strcmp(name, "PE_WE") == 0)
        {
            IUUpdateSwitch(&PEErrWESP, states, names, n);

            PEErrWESP.s = IPS_OK;

            if (PEErrWES[DIRECTION_WEST].s == ISS_ON)
            {
                EqPEN[RA_AXIS].value -= TRACKRATE_SIDEREAL/3600.0 / 15. * GuideRateN[RA_AXIS].value;
                DEBUGF(INDI::Logger::DBG_DEBUG, "Simulator PE in WEST direction for value of %g", TRACKRATE_SIDEREAL/3600.0);
            }
            else
            {
                EqPEN[RA_AXIS].value += TRACKRATE_SIDEREAL/3600.0 / 15. * GuideRateN[RA_AXIS].value;
                DEBUGF(INDI::Logger::DBG_DEBUG, "Simulator PE in EAST direction for value of %g", TRACKRATE_SIDEREAL/3600.0);
            }

            IUResetSwitch(&PEErrWESP);
            IDSetSwitch(&PEErrWESP, nullptr);
            IDSetNumber(&EqPENV, nullptr);

            return true;
        }
    }

    //  Nobody has claimed this, so, ignore it
    return INDI::Telescope::ISNewSwitch(dev, name, states, names, n);
}
Exemplo n.º 2
0
bool QSICCD::ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n)
{
    if(strcmp(dev,getDeviceName())==0)
    {

        /* Readout Speed */
        if (!strcmp(name, ReadOutSP.name))
        {
            if (IUUpdateSwitch(&ReadOutSP, states, names, n) < 0) return false;

            if (ReadOutS[0].s == ISS_ON)
            {
                try
                {
                 QSICam.put_ReadoutSpeed(QSICamera::HighImageQuality);
                } catch (std::runtime_error err)
                {
                        IUResetSwitch(&ReadOutSP);
                        ReadOutSP.s = IPS_ALERT;
                        DEBUGF(INDI::Logger::DBG_ERROR, "put_ReadoutSpeed() failed. %s.", err.what());
                        IDSetSwitch(&ReadOutSP, NULL);
                        return false;
                }

            }
            else
            {
                try
                {
                 QSICam.put_ReadoutSpeed(QSICamera::FastReadout);
                } catch (std::runtime_error err)
                {
                        IUResetSwitch(&ReadOutSP);
                        ReadOutSP.s = IPS_ALERT;
                        DEBUGF(INDI::Logger::DBG_ERROR, "put_ReadoutSpeed() failed. %s.", err.what());
                        IDSetSwitch(&ReadOutSP, NULL);
                        return false;
                }

                ReadOutSP.s = IPS_OK;
                IDSetSwitch(&ReadOutSP, NULL);

            }

            ReadOutSP.s = IPS_OK;
            IDSetSwitch(&ReadOutSP, NULL);
            return true;
        }


         /* Cooler */
        if (!strcmp (name, CoolerSP.name))
        {
          if (IUUpdateSwitch(&CoolerSP, states, names, n) < 0) return false;

          if (CoolerS[0].s == ISS_ON)
            activateCooler(true);
          else
              activateCooler(false);

          return true;
        }

        /* Shutter */
        if (!strcmp (name, ShutterSP.name))
        {
            if (IUUpdateSwitch(&ShutterSP, states, names, n) < 0) return false;
            shutterControl();
            return true;
        }

        if (!strcmp(name, GainSP.name))
        {
            int prevGain = IUFindOnSwitchIndex(&GainSP);
            IUUpdateSwitch(&GainSP, states, names, n);
            int targetGain = IUFindOnSwitchIndex(&GainSP);

            if (prevGain == targetGain)
            {
                GainSP.s = IPS_OK;
                IDSetSwitch(&GainSP, NULL);
                return true;
            }

            try
            {
                QSICam.put_CameraGain( ((QSICamera::CameraGain) targetGain));

            }  catch (std::runtime_error err)
            {
                                    IUResetSwitch(&GainSP);
                                    GainS[prevGain].s = ISS_ON;
                                    GainSP.s = IPS_ALERT;
                                    DEBUGF(INDI::Logger::DBG_ERROR, "put_CameraGain failed. %s.", err.what());
                                    IDSetSwitch(&GainSP, NULL);
                                    return false;
            }

            GainSP.s = IPS_OK;
            IDSetSwitch(&GainSP, NULL);
            return true;
        }

        if (!strcmp(name, FanSP.name))
        {
            int prevFan = IUFindOnSwitchIndex(&FanSP);
            IUUpdateSwitch(&FanSP, states, names, n);
            int targetFan = IUFindOnSwitchIndex(&FanSP);

            if (prevFan == targetFan)
            {
                FanSP.s = IPS_OK;
                IDSetSwitch(&FanSP, NULL);
                return true;
            }

            try
            {
                QSICam.put_FanMode( ((QSICamera::FanMode) targetFan));

            }  catch (std::runtime_error err)
            {
                                    IUResetSwitch(&FanSP);
                                    FanS[prevFan].s = ISS_ON;
                                    FanSP.s = IPS_ALERT;
                                    DEBUGF(INDI::Logger::DBG_ERROR, "put_FanMode failed. %s.", err.what());
                                    IDSetSwitch(&FanSP, NULL);
                                    return false;
            }

            FanSP.s = IPS_OK;
            IDSetSwitch(&FanSP, NULL);
            return true;
        }

        if (!strcmp(name, ABSP.name))
        {
            int prevAB = IUFindOnSwitchIndex(&ABSP);
            IUUpdateSwitch(&ABSP, states, names, n);
            int targetAB = IUFindOnSwitchIndex(&ABSP);

            if (prevAB == targetAB)
            {
                ABSP.s = IPS_OK;
                IDSetSwitch(&ABSP, NULL);
                return true;
            }

            try
            {
                QSICam.put_AntiBlooming( ((QSICamera::AntiBloom) targetAB));

            }  catch (std::runtime_error err)
            {
                IUResetSwitch(&ABSP);
                ABS[prevAB].s = ISS_ON;
                ABSP.s = IPS_ALERT;
                DEBUGF(INDI::Logger::DBG_ERROR, "put_AntiBlooming failed. %s.", err.what());
                IDSetSwitch(&ABSP, NULL);
                return false;
            }

            ABSP.s = IPS_OK;
            IDSetSwitch(&ABSP, NULL);
            return true;
        }

        /* Filter Wheel */
        if (!strcmp (name, FilterSP.name))
        {
            if (IUUpdateSwitch(&FilterSP, states, names, n) < 0) return false;
            turnWheel();
            return true;
        }
    }

        //  Nobody has claimed this, so, ignore it
        return INDI::CCD::ISNewSwitch(dev,name,states,names,n);
}
Exemplo n.º 3
0
bool LX200_16::ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n)
{
   int index;

   if(strcmp(dev,getDeviceName())==0)
   {
       if (!strcmp(name, FanStatusSP.name))
       {
           IUResetSwitch(&FanStatusSP);
           IUUpdateSwitch(&FanStatusSP, states, names, n);
           index = IUFindOnSwitchIndex(&FanStatusSP);

          if (index == 0)
          {
            if (turnFanOn(PortFD) < 0)
            {
                FanStatusSP.s = IPS_ALERT;
                IDSetSwitch(&FanStatusSP, "Error changing fan status.");
                return false;
            }
          }
          else
          {
            if (turnFanOff(PortFD) < 0)
            {
                FanStatusSP.s = IPS_ALERT;
                IDSetSwitch(&FanStatusSP, "Error changing fan status.");
                return false;
            }
          }

          FanStatusSP.s = IPS_OK;
          IDSetSwitch (&FanStatusSP, index == 0 ? "Fan is ON" : "Fan is OFF");
          return true;
       }

       if (!strcmp(name, HomeSearchSP.name))
       {
          IUResetSwitch(&HomeSearchSP);
          IUUpdateSwitch(&HomeSearchSP, states, names, n);
          index = IUFindOnSwitchIndex(&HomeSearchSP);

          if (index == 0)
            seekHomeAndSave(PortFD);
          else
            seekHomeAndSet(PortFD);

          HomeSearchSP.s = IPS_BUSY;
          IDSetSwitch (&HomeSearchSP, index == 0 ? "Seek Home and Save" : "Seek Home and Set");
          return true;
       }

       if (!strcmp(name, FieldDeRotatorSP.name))
       {
          IUResetSwitch(&FieldDeRotatorSP);
          IUUpdateSwitch(&FieldDeRotatorSP, states, names, n);
          index = IUFindOnSwitchIndex(&FieldDeRotatorSP);

          if (index == 0)
            turnFieldDeRotatorOn(PortFD);
          else
            turnFieldDeRotatorOff(PortFD);

          FieldDeRotatorSP.s = IPS_OK;
          IDSetSwitch (&FieldDeRotatorSP, index == 0 ? "Field deRotator is ON" : "Field deRotator is OFF");
          return true;
       }
   }


    return LX200GPS::ISNewSwitch (dev, name, states, names, n);
}
Exemplo n.º 4
0
bool ioptronHC8406::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
{
    if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
    {

        // Sync type
        if (!strcmp(name, SyncCMRSP.name))
        {
            IUResetSwitch(&SyncCMRSP);
            IUUpdateSwitch(&SyncCMRSP, states, names, n);
            IUFindOnSwitchIndex(&SyncCMRSP);
            SyncCMRSP.s = IPS_OK;
            IDSetSwitch(&SyncCMRSP, nullptr);
            return true;
        }

        // Cursor move type
        if (!strcmp(name, CursorMoveSpeedSP.name))
        {
            int currentSwitch = IUFindOnSwitchIndex(&CursorMoveSpeedSP);
	    IUUpdateSwitch(&CursorMoveSpeedSP, states, names, n);
            if (setioptronHC8406CursorMoveSpeed(IUFindOnSwitchIndex(&CursorMoveSpeedSP)) == TTY_OK)
                CursorMoveSpeedSP.s = IPS_OK;
            else
            {
                IUResetSwitch(&CursorMoveSpeedSP);
                CursorMoveSpeedS[currentSwitch].s = ISS_ON;
                CursorMoveSpeedSP.s = IPS_ALERT;
            }
            return true;
        }

        // Guide Rate
        if (!strcmp(GuideRateSP.name, name))
        {
            int currentSwitch = IUFindOnSwitchIndex(&GuideRateSP);
            IUUpdateSwitch(&GuideRateSP, states, names, n);
            if (setioptronHC8406GuideRate(IUFindOnSwitchIndex(&GuideRateSP)) == TTY_OK)
            {
                GuideRateSP.s = IPS_OK;
		//Shows guide speed selected
		CursorMoveSpeedS[USE_GUIDE_SPEED].s = ISS_ON;
		CursorMoveSpeedS[USE_CENTERING_SPEED].s = ISS_OFF;
	        CursorMoveSpeedSP.s = IPS_OK;
	        IDSetSwitch(&CursorMoveSpeedSP, nullptr);
            } else {
                IUResetSwitch(&GuideRateSP);
                GuideRateS[currentSwitch].s = ISS_ON;
                GuideRateSP.s = IPS_ALERT;
            }

            IDSetSwitch(&GuideRateSP, nullptr);
            return true;
        }

        // Center Rate
        if (!strcmp(CenterRateSP.name, name))
        {
            int currentSwitch = IUFindOnSwitchIndex(&CenterRateSP);
            IUUpdateSwitch(&CenterRateSP, states, names, n);
            if (setioptronHC8406CenterRate(IUFindOnSwitchIndex(&CenterRateSP)) == TTY_OK)
	    {
                CenterRateSP.s = IPS_OK;
		//Shows centering speed selected
		CursorMoveSpeedS[USE_GUIDE_SPEED].s = ISS_OFF;
		CursorMoveSpeedS[USE_CENTERING_SPEED].s = ISS_ON;
	        CursorMoveSpeedSP.s = IPS_OK;
	        IDSetSwitch(&CursorMoveSpeedSP, nullptr);
            } else {
                IUResetSwitch(&CenterRateSP);
                CenterRateS[currentSwitch].s = ISS_ON;
                CenterRateSP.s = IPS_ALERT;
            }

            IDSetSwitch(&CenterRateSP, nullptr);
            return true;
        }

        // Slew Rate
        if (!strcmp(SlewRateSP.name, name))
        {
            int currentSwitch = IUFindOnSwitchIndex(&SlewRateSP);
            IUUpdateSwitch(&SlewRateSP, states, names, n);
            if (setioptronHC8406SlewRate(IUFindOnSwitchIndex(&SlewRateSP)) == TTY_OK)
                SlewRateSP.s = IPS_OK;
            else
            {
                IUResetSwitch(&SlewRateSP);
                SlewRateS[currentSwitch].s = ISS_ON;
                SlewRateSP.s = IPS_ALERT;
            }

            IDSetSwitch(&SlewRateSP, nullptr);
            return true;
        }

    }

    return LX200Generic::ISNewSwitch(dev, name, states, names, n);
}
Exemplo n.º 5
0
Arquivo: ieqpro.cpp Projeto: mp77/indi
bool IEQPro::ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n)
{
    if (!strcmp (getDeviceName(), dev))
    {
        if (!strcmp(name, HomeSP.name))
        {
            IUUpdateSwitch(&HomeSP, states, names, n);

            IEQ_HOME_OPERATION operation = (IEQ_HOME_OPERATION) IUFindOnSwitchIndex(&HomeSP);

            IUResetSwitch(&HomeSP);

            switch (operation)
            {
                case IEQ_FIND_HOME:
                    if (firmwareInfo.Model.find("CEM") == std::string::npos)
                    {
                        HomeSP.s = IPS_IDLE;
                        IDSetSwitch(&HomeSP, NULL);
                        DEBUG(INDI::Logger::DBG_WARNING, "Home search is not supported in this model.");
                        return true;
                    }

                    if (find_ieqpro_home(PortFD) == false)
                    {
                        HomeSP.s = IPS_ALERT;
                        IDSetSwitch(&HomeSP, NULL);
                        return false;

                    }

                    HomeSP.s = IPS_OK;
                    IDSetSwitch(&HomeSP, NULL);
                    DEBUG(INDI::Logger::DBG_SESSION, "Searching for home position...");
                    return true;

                    break;

                case IEQ_SET_HOME:
                    if (set_ieqpro_current_home(PortFD) == false)
                    {
                        HomeSP.s = IPS_ALERT;
                        IDSetSwitch(&HomeSP, NULL);
                        return false;

                    }

                    HomeSP.s = IPS_OK;
                    IDSetSwitch(&HomeSP, NULL);
                    DEBUG(INDI::Logger::DBG_SESSION, "Home position set to current coordinates.");
                    return true;

                    break;

                case IEQ_GOTO_HOME:
                    if (goto_ieqpro_home(PortFD) == false)
                    {
                        HomeSP.s = IPS_ALERT;
                        IDSetSwitch(&HomeSP, NULL);
                        return false;

                    }

                    HomeSP.s = IPS_OK;
                    IDSetSwitch(&HomeSP, NULL);
                    DEBUG(INDI::Logger::DBG_SESSION, "Slewing to home position...");
                    return true;

                    break;
            }

            return true;
        }

        if (!strcmp(name, TrackModeSP.name))
        {
            IUUpdateSwitch(&TrackModeSP, states, names, n);

            TelescopeTrackMode mode = (TelescopeTrackMode) IUFindOnSwitchIndex(&TrackModeSP);

            IEQ_TRACK_RATE rate;

            switch (mode)
            {
                case TRACK_SIDEREAL:
                    rate = TR_SIDEREAL;
                    break;
                case TRACK_SOLAR:
                    rate = TR_SOLAR;
                    break;
                case TRACK_LUNAR:
                    rate = TR_LUNAR;
                    break;
                case TRACK_CUSTOM:
                    rate = TR_CUSTOM;
                    break;
            }

            if (set_ieqpro_track_mode(PortFD, rate))
            {
                if (TrackState == SCOPE_TRACKING)
                    TrackModeSP.s = IPS_BUSY;
                else
                    TrackModeSP.s = IPS_OK;
            }
            else
                TrackModeSP.s = IPS_ALERT;

        }

    }

    return INDI::Telescope::ISNewSwitch (dev, name, states, names,  n);
}
Exemplo n.º 6
0
bool FocuserInterface::processSwitch(const char * dev, const char * name, ISState * states, char * names[], int n)
{
    INDI_UNUSED(dev);
    //  This one is for focus motion
    if (!strcmp(name, FocusMotionSP.name))
    {
        // 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;
    }

    // Abort Focuser
    if (!strcmp(name, FocusAbortSP.name))
    {
        IUResetSwitch(&FocusAbortSP);

        if (AbortFocuser())
        {
            FocusAbortSP.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
            FocusAbortSP.s = IPS_ALERT;

        IDSetSwitch(&FocusAbortSP, nullptr);
        return true;
    }

    // Reverse Motion
    if (!strcmp(name, FocusReverseSP.name))
    {
        bool enabled = !strcmp("ENABLED", IUFindOnSwitchName(states, names, n));

        if (ReverseFocuser(enabled))
        {
            IUUpdateSwitch(&FocusReverseSP, states, names, n);
            FocusReverseSP.s = IPS_OK;
        }
        else
        {
            FocusReverseSP.s = IPS_ALERT;
        }

        IDSetSwitch(&FocusReverseSP, nullptr);
        return true;
    }

    return false;
}
Exemplo n.º 7
0
bool LX200GPS::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
{
    int index = 0;
    char msg[64];

    if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
    {
        /* GPS Power */
        if (!strcmp(name, GPSPowerSP.name))
        {
            int ret = 0;

            if (IUUpdateSwitch(&GPSPowerSP, states, names, n) < 0)
                return false;

            index = IUFindOnSwitchIndex(&GPSPowerSP);
            if (index == 0)
                ret = turnGPSOn(PortFD);
            else
                ret = turnGPSOff(PortFD);

            GPSPowerSP.s = IPS_OK;
            IDSetSwitch(&GPSPowerSP, index == 0 ? "GPS System is ON" : "GPS System is OFF");
            return true;
        }

        /* GPS Status Update */
        if (!strcmp(name, GPSStatusSP.name))
        {
            int ret = 0;

            if (IUUpdateSwitch(&GPSStatusSP, states, names, n) < 0)
                return false;

            index = IUFindOnSwitchIndex(&GPSStatusSP);

            if (index == 0)
            {
                ret = gpsSleep(PortFD);
                strncpy(msg, "GPS system is in sleep mode.", 64);
            }
            else if (index == 1)
            {
                ret = gpsWakeUp(PortFD);
                strncpy(msg, "GPS system is reactivated.", 64);
            }
            else
            {
                ret = gpsRestart(PortFD);
                strncpy(msg, "GPS system is restarting...", 64);
                sendScopeTime();
                sendScopeLocation();
            }

            GPSStatusSP.s = IPS_OK;
            IDSetSwitch(&GPSStatusSP, "%s", msg);
            return true;
        }

        /* GPS Update */
        if (!strcmp(name, GPSUpdateSP.name))
        {
            if (IUUpdateSwitch(&GPSUpdateSP, states, names, n) < 0)
                return false;

            index = IUFindOnSwitchIndex(&GPSUpdateSP);

            GPSUpdateSP.s = IPS_OK;

            if (index == 0)
            {
                IDSetSwitch(&GPSUpdateSP, "Updating GPS system. This operation might take few minutes to complete...");
                if (updateGPS_System(PortFD))
                {
                    IDSetSwitch(&GPSUpdateSP, "GPS system update successful.");
                    sendScopeTime();
                    sendScopeLocation();
                }
                else
                {
                    GPSUpdateSP.s = IPS_IDLE;
                    IDSetSwitch(&GPSUpdateSP, "GPS system update failed.");
                }
            }
            else
            {
                sendScopeTime();
                sendScopeLocation();
                IDSetSwitch(&GPSUpdateSP, "Client time and location is synced to LX200 GPS Data.");
            }
            return true;
        }

        /* Alt Dec Periodic Error correction */
        if (!strcmp(name, AltDecPecSP.name))
        {
            int ret = 0;

            if (IUUpdateSwitch(&AltDecPecSP, states, names, n) < 0)
                return false;

            index = IUFindOnSwitchIndex(&AltDecPecSP);

            if (index == 0)
            {
                ret = enableDecAltPec(PortFD);
                strncpy(msg, "Alt/Dec Compensation Enabled.", 64);
            }
            else
            {
                ret = disableDecAltPec(PortFD);
                strncpy(msg, "Alt/Dec Compensation Disabled.", 64);
            }

            AltDecPecSP.s = IPS_OK;
            IDSetSwitch(&AltDecPecSP, "%s", msg);

            return true;
        }

        /* Az RA periodic error correction */
        if (!strcmp(name, AzRaPecSP.name))
        {
            int ret = 0;

            if (IUUpdateSwitch(&AzRaPecSP, states, names, n) < 0)
                return false;

            index = IUFindOnSwitchIndex(&AzRaPecSP);

            if (index == 0)
            {
                ret = enableRaAzPec(PortFD);
                strncpy(msg, "Ra/Az Compensation Enabled.", 64);
            }
            else
            {
                ret = disableRaAzPec(PortFD);
                strncpy(msg, "Ra/Az Compensation Disabled.", 64);
            }

            AzRaPecSP.s = IPS_OK;
            IDSetSwitch(&AzRaPecSP, "%s", msg);

            return true;
        }

        if (!strcmp(name, AltDecBacklashSP.name))
        {
            int ret = 0;

            ret = activateAltDecAntiBackSlash(PortFD);
            AltDecBacklashSP.s = IPS_OK;
            IDSetSwitch(&AltDecBacklashSP, "Alt/Dec Anti-backlash enabled");
            return true;
        }

        if (!strcmp(name, AzRaBacklashSP.name))
        {
            int ret = 0;

            ret = activateAzRaAntiBackSlash(PortFD);
            AzRaBacklashSP.s = IPS_OK;
            IDSetSwitch(&AzRaBacklashSP, "Az/Ra Anti-backlash enabled");
            return true;
        }

        if (!strcmp(name, OTAUpdateSP.name))
        {
            IUResetSwitch(&OTAUpdateSP);

            if (getOTATemp(PortFD, &OTATempNP.np[0].value) < 0)
            {
                OTAUpdateSP.s = IPS_ALERT;
                OTATempNP.s   = IPS_ALERT;
                IDSetNumber(&OTATempNP, "Error: OTA temperature read timed out.");
                return false;
            }
            else
            {
                OTAUpdateSP.s = IPS_OK;
                OTATempNP.s   = IPS_OK;
                IDSetNumber(&OTATempNP, nullptr);
                IDSetSwitch(&OTAUpdateSP, nullptr);
                return true;
            }
        }
    }

    return LX200Autostar::ISNewSwitch(dev, name, states, names, n);
}
Exemplo n.º 8
0
void MathPluginManagement::ProcessSwitchProperties(Telescope* pTelescope, const char *name, ISState *states, char *names[], int n)
{
    DEBUGFDEVICE(pTelescope->getDeviceName(), INDI::Logger::DBG_DEBUG, "ProcessSwitchProperties - name(%s)", name);
    if (strcmp(name, AlignmentSubsystemMathPluginsV.name) == 0)
    {
        int CurrentPlugin = IUFindOnSwitchIndex(&AlignmentSubsystemMathPluginsV);
        IUUpdateSwitch(&AlignmentSubsystemMathPluginsV, states, names, n);
        AlignmentSubsystemMathPluginsV.s = IPS_OK; // Assume OK for the time being
        int NewPlugin  = IUFindOnSwitchIndex(&AlignmentSubsystemMathPluginsV);
        if (NewPlugin != CurrentPlugin)
        {
            // New plugin requested
            // Unload old plugin if required
            if (0 != CurrentPlugin)
            {
                typedef void Destroy_t(MathPlugin *);
                Destroy_t* Destroy = (Destroy_t*)dlsym(LoadedMathPluginHandle, "Destroy");
                if (NULL != Destroy)
                {
                    Destroy(pLoadedMathPlugin);
                    pLoadedMathPlugin = NULL;
                    if (0 == dlclose(LoadedMathPluginHandle))
                    {
                        LoadedMathPluginHandle = NULL;

                    }
                    else
                    {
                        IDLog("MathPluginManagement - dlclose failed on loaded plugin - %s\n", dlerror());
                        AlignmentSubsystemMathPluginsV.s = IPS_ALERT;
                    }
                }
                else
                {
                    IDLog("MathPluginManagement - cannot get Destroy function - %s\n", dlerror());
                    AlignmentSubsystemMathPluginsV.s = IPS_ALERT;
                }
            }
            // Load the requested plugin if required
            if (0 != NewPlugin)
            {
                std::string PluginPath(MathPluginFiles[NewPlugin - 1]);
                if (NULL != (LoadedMathPluginHandle = dlopen(PluginPath.c_str(), RTLD_NOW)))
                {
                    typedef MathPlugin* Create_t();
                    Create_t* Create = (Create_t*)dlsym(LoadedMathPluginHandle, "Create");
                    if (NULL != Create)
                    {
                        pLoadedMathPlugin = Create();
                        IUSaveText(&AlignmentSubsystemCurrentMathPlugin, PluginPath.c_str());
                    }
                    else
                    {
                        IDLog("MathPluginManagement - cannot get Create function - %s\n", dlerror());
                        AlignmentSubsystemMathPluginsV.s = IPS_ALERT;
                    }
                }
                else
                {
                    IDLog("MathPluginManagement - cannot load plugin %s error %s\n", PluginPath.c_str(), dlerror());
                    AlignmentSubsystemMathPluginsV.s = IPS_ALERT;
                }
            }
            else
            {
                // It is in built plugin just set up the pointers
                pLoadedMathPlugin = &BuiltInPlugin;
            }
        }

        //  Update client
        IDSetSwitch(&AlignmentSubsystemMathPluginsV, NULL);
    }
    else if (strcmp(name, AlignmentSubsystemMathPluginInitialiseV.name) == 0)
    {
        AlignmentSubsystemMathPluginInitialiseV.s = IPS_OK;
        IUResetSwitch(&AlignmentSubsystemMathPluginInitialiseV);
        //  Update client display
        IDSetSwitch(&AlignmentSubsystemMathPluginInitialiseV, NULL);

        // Initialise or reinitialise the current math plugin
        Initialise(CurrentInMemoryDatabase);
    }
    else if (strcmp(name, AlignmentSubsystemActiveV.name) == 0)
    {
        AlignmentSubsystemActiveV.s=IPS_OK;
        if (0 == IUUpdateSwitch(&AlignmentSubsystemActiveV, states, names, n))
            //  Update client
            IDSetSwitch(&AlignmentSubsystemActiveV, NULL);
    }
}
Exemplo n.º 9
0
Arquivo: tcfs.cpp Projeto: djibb/indi
bool TCFS::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
{
//LOGF_DEBUG("%s %s",__FUNCTION__, me);
    if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
    {
        char response[TCFS_MAX_CMD] = { 0 };

        if (!strcmp(FocusPowerSP.name, name))
        {
            IUUpdateSwitch(&FocusPowerSP, states, names, n);
            bool sleep = false;

            ISwitch *sp = IUFindOnSwitch(&FocusPowerSP);

            // Sleep
            if (!strcmp(sp->name, "FOCUS_SLEEP"))
            {
                dispatch_command(FSLEEP);
                sleep = true;
            }
            // Wake Up
            else
                dispatch_command(FWAKUP);

            if (read_tcfs(response) == false)
            {
                IUResetSwitch(&FocusPowerSP);
                FocusPowerSP.s = IPS_ALERT;
                IDSetSwitch(&FocusPowerSP, "Error reading TCF-S reply.");
                return true;
            }

            if (sleep)
            {
                if (isSimulation())
                    strncpy(response, "ZZZ", TCFS_MAX_CMD);

                if (strcmp(response, "ZZZ") == 0)
                {
                    FocusPowerSP.s = IPS_OK;
                    IDSetSwitch(&FocusPowerSP, "Focuser is set into sleep mode.");
                    FocusAbsPosNP.s = IPS_IDLE;
                    IDSetNumber(&FocusAbsPosNP, nullptr);
//                    if (FocusTemperatureNP)
                    {
                        FocusTemperatureNP.s = IPS_IDLE;
                        IDSetNumber(&FocusTemperatureNP, nullptr);
                    }

                    return true;
                }
                else
                {
                    FocusPowerSP.s = IPS_ALERT;
                    IDSetSwitch(&FocusPowerSP, "Focuser sleep mode operation failed. Response: %s.", response);
                    return true;
                }
            }
            else
            {
                if (isSimulation())
                    strncpy(response, "WAKE", TCFS_MAX_CMD);

                if (strcmp(response, "WAKE") == 0)
                {
                    FocusPowerSP.s = IPS_OK;
                    IDSetSwitch(&FocusPowerSP, "Focuser is awake.");
                    FocusAbsPosNP.s = IPS_OK;
                    IDSetNumber(&FocusAbsPosNP, nullptr);
//                    if (FocusTemperatureNP)
                    {
                        FocusTemperatureNP.s = IPS_OK;
                        IDSetNumber(&FocusTemperatureNP, nullptr);
                    }

                    return true;
                }
                else
                {
                    FocusPowerSP.s = IPS_ALERT;
                    IDSetSwitch(&FocusPowerSP, "Focuser wake up operation failed. Response: %s", response);
                    return true;
                }
            }
        }

        // Do not process any command if focuser is asleep
        if (isConnected() && FocusPowerSP.sp[0].s == ISS_ON)
        {
            ISwitchVectorProperty *svp = getSwitch(name);
            if (svp)
            {
                svp->s = IPS_IDLE;
                LOG_WARN("Focuser is still in sleep mode. Wake up in order to issue commands.");
                IDSetSwitch(svp, nullptr);
            }
            return true;
        }

        if (!strcmp(FocusModeSP.name, name))
        {
            IUUpdateSwitch(&FocusModeSP, states, names, n);
            FocusModeSP.s = IPS_OK;

            ISwitch *sp = IUFindOnSwitch(&FocusModeSP);

            if (!strcmp(sp->name, "Manual"))
            {
                if (!isSimulation() && !SetManualMode())
                {
                    IUResetSwitch(&FocusModeSP);
                    FocusModeSP.s = IPS_ALERT;
                    IDSetSwitch(&FocusModeSP, "Error switching to manual mode. No reply from TCF-S. Try again.");
                    return true;
                }
            }
            else if (!strcmp(sp->name, "Auto A"))
            {
                dispatch_command(FAMODE);
                read_tcfs(response);
                if (!isSimulation() && strcmp(response, "A") != 0)
                {
                    IUResetSwitch(&FocusModeSP);
                    FocusModeSP.s = IPS_ALERT;
                    IDSetSwitch(&FocusModeSP, "Error switching to Auto Mode A. No reply from TCF-S. Try again.");
                    return true;
                }
                LOG_INFO("Entered Auto Mode A");
                currentMode = MODE_A;
            }
            else
            {
                dispatch_command(FBMODE);
                read_tcfs(response);
                if (!isSimulation() && strcmp(response, "B") != 0)
                {
                    IUResetSwitch(&FocusModeSP);
                    FocusModeSP.s = IPS_ALERT;
                    IDSetSwitch(&FocusModeSP, "Error switching to Auto Mode B. No reply from TCF-S. Try again.");
                    return true;
                }
                LOG_INFO("Entered Auto Mode B");
                currentMode = MODE_B;
            }

            IDSetSwitch(&FocusModeSP, nullptr);
            return true;
        }

        if (!strcmp(FocusGotoSP.name, name))
        {
            if (FocusModeSP.sp[0].s != ISS_ON)
            {
                FocusGotoSP.s = IPS_IDLE;
                IDSetSwitch(&FocusGotoSP, nullptr);
                LOG_WARN("The focuser can only be moved in Manual mode.");
                return false;
            }

            IUUpdateSwitch(&FocusGotoSP, states, names, n);
            FocusGotoSP.s = IPS_BUSY;

            ISwitch *sp = IUFindOnSwitch(&FocusGotoSP);

            // Min
            if (!strcmp(sp->name, "FOCUS_MIN"))
            {
                targetTicks = currentPosition;
                MoveRelFocuser(FOCUS_INWARD, currentPosition);
                IDSetSwitch(&FocusGotoSP, "Moving focuser to minimum position...");
            }
            // Center
            else if (!strcmp(sp->name, "FOCUS_CENTER"))
            {
                dispatch_command(FCENTR);
                FocusAbsPosNP.s = FocusRelPosNP.s = IPS_BUSY;
                IDSetNumber(&FocusAbsPosNP, nullptr);
                IDSetNumber(&FocusRelPosNP, nullptr);
                IDSetSwitch(&FocusGotoSP, "Moving focuser to center position %d...", isTCFS3 ? 5000 : 3500);
                return true;
            }
            // Max
            else if (!strcmp(sp->name, "FOCUS_MAX"))
            {
                unsigned int delta = 0;
                delta              = FocusAbsPosN[0].max - currentPosition;
                MoveRelFocuser(FOCUS_OUTWARD, delta);
                IDSetSwitch(&FocusGotoSP, "Moving focuser to maximum position %g...", FocusAbsPosN[0].max);
            }
            // Home
            else if (!strcmp(sp->name, "FOCUS_HOME"))
            {
                dispatch_command(FHOME);
                read_tcfs(response);

                if (isSimulation())
                    strncpy(response, "DONE", TCFS_MAX_CMD);

                if (strcmp(response, "DONE") == 0)
                {
                    IUResetSwitch(&FocusGotoSP);
                    FocusGotoSP.s = IPS_OK;
                    IDSetSwitch(&FocusGotoSP, "Moving focuser to new calculated position based on temperature...");
                    return true;
                }
                else
                {
                    IUResetSwitch(&FocusGotoSP);
                    FocusGotoSP.s = IPS_ALERT;
                    IDSetSwitch(&FocusGotoSP, "Failed to move focuser to home position!");
                    return true;
                }
            }

            IDSetSwitch(&FocusGotoSP, nullptr);
            return true;
        }
        // handle quiet mode on/off
        if (!strcmp(FocusTelemetrySP.name, name))
        {
            IUUpdateSwitch(&FocusTelemetrySP, states, names, n);


            bool quiet = false;

            ISwitch *sp = IUFindOnSwitch(&FocusTelemetrySP);

            // Telemetry off
            if (!strcmp(sp->name, "FOCUS_TELEMETRY_OFF"))
            {
                dispatch_command(FQUIET, 1);
                quiet = true;
            }
            // Telemetry On
            else
                dispatch_command(FQUIET, 0);

            if (read_tcfs(response) == false)
            {
                IUResetSwitch(&FocusTelemetrySP);
                FocusTelemetrySP.s = IPS_ALERT;
                IDSetSwitch(&FocusTelemetrySP, "Error reading TCF-S reply.");
                return true;
            }

            if (isSimulation())
                strncpy(response, "DONE", TCFS_MAX_CMD);

            if (strcmp(response, "DONE") == 0)
            {
                FocusTelemetrySP.s = IPS_OK;
                IDSetSwitch(&FocusTelemetrySP, 
                        quiet ? "Focuser Telemetry is off." : "Focuser Telemetry is on.");
//                if (FocusTemperatureNP)
                {
                    FocusTemperatureNP.s = quiet?IPS_IDLE:IPS_OK;
                    IDSetNumber(&FocusTemperatureNP, nullptr);
                }
                return true;
            }
            else
            {
                FocusTelemetrySP.s = IPS_ALERT;
                IDSetSwitch(&FocusTelemetrySP, "Focuser telemetry mode failed. Response: %s.", response);
                return true;
            }
        }
    }
    return INDI::Focuser::ISNewSwitch(dev, name, states, names, n);
}
Exemplo n.º 10
0
bool INDI::CCD::ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n)
{

    if(strcmp(dev,getDeviceName())==0)
    {


        if(strcmp(name,PrimaryCCD.AbortExposureSP->name)==0)
        {
            IUResetSwitch(PrimaryCCD.AbortExposureSP);

            if (AbortExposure())
            {
                PrimaryCCD.AbortExposureSP->s = IPS_OK;
                PrimaryCCD.ImageExposureNP->s = IPS_IDLE;
                PrimaryCCD.ImageExposureN[0].value = 0;
            }
            else
            {
                PrimaryCCD.AbortExposureSP->s = IPS_ALERT;
                PrimaryCCD.ImageExposureNP->s = IPS_ALERT;
            }

            IDSetSwitch(PrimaryCCD.AbortExposureSP, NULL);
            IDSetNumber(PrimaryCCD.ImageExposureNP, NULL);

            return true;
        }


        if(strcmp(name,GuideCCD.AbortExposureSP->name)==0)
        {
            IUResetSwitch(GuideCCD.AbortExposureSP);

            if (AbortGuideExposure())
            {
                GuideCCD.AbortExposureSP->s = IPS_OK;
                GuideCCD.ImageExposureNP->s = IPS_IDLE;
                GuideCCD.ImageExposureN[0].value = 0;
            }
            else
            {
                GuideCCD.AbortExposureSP->s = IPS_ALERT;
                GuideCCD.ImageExposureNP->s = IPS_ALERT;
            }

            IDSetSwitch(GuideCCD.AbortExposureSP, NULL);
            IDSetNumber(GuideCCD.ImageExposureNP, NULL);

            return true;
        }


        if(strcmp(name,PrimaryCCD.CompressSP->name)==0)
        {

            IUUpdateSwitch(PrimaryCCD.CompressSP,states,names,n);
            IDSetSwitch(PrimaryCCD.CompressSP,NULL);

            if(PrimaryCCD.CompressS[0].s==ISS_ON    )
            {
                PrimaryCCD.SendCompressed=true;
            } else
            {
                PrimaryCCD.SendCompressed=false;
            }
            return true;
        }

        if(strcmp(name,GuideCCD.CompressSP->name)==0)
        {

            IUUpdateSwitch(GuideCCD.CompressSP,states,names,n);
            IDSetSwitch(GuideCCD.CompressSP,NULL);

            if(GuideCCD.CompressS[0].s==ISS_ON    )
            {
                GuideCCD.SendCompressed=true;
            } else
            {
                GuideCCD.SendCompressed=false;
            }
            return true;
        }

        if(strcmp(name,PrimaryCCD.FrameTypeSP->name)==0)
        {
            //  Compression Update
            IUUpdateSwitch(PrimaryCCD.FrameTypeSP,states,names,n);
            PrimaryCCD.FrameTypeSP->s=IPS_OK;
            if(PrimaryCCD.FrameTypeS[0].s==ISS_ON) PrimaryCCD.setFrameType(CCDChip::LIGHT_FRAME);
            else if(PrimaryCCD.FrameTypeS[1].s==ISS_ON) PrimaryCCD.setFrameType(CCDChip::BIAS_FRAME);
            else if(PrimaryCCD.FrameTypeS[2].s==ISS_ON) PrimaryCCD.setFrameType(CCDChip::DARK_FRAME);
            else if(PrimaryCCD.FrameTypeS[3].s==ISS_ON) PrimaryCCD.setFrameType(CCDChip::FLAT_FRAME);

            if (updateCCDFrameType(PrimaryCCD.getFrameType()) == false)
                PrimaryCCD.FrameTypeSP->s = IPS_ALERT;

            IDSetSwitch(PrimaryCCD.FrameTypeSP,NULL);

            return true;
        }
    }


    // let the default driver have a crack at it
    return DefaultDevice::ISNewSwitch(dev, name, states, names, n);
}
Exemplo n.º 11
0
bool AAGCloudWatcher::sendData() {
  CloudWatcherData data;

  int r = cwc->getAllData(&data);

  if (!r) {
    return false;
  }

  int N_DATA = 11;
  double values[N_DATA];
  char *names[N_DATA];

  names[0] = const_cast<char *>("supply");
  values[0] = data.supply;

  names[1] = const_cast<char *>("sky");
  values[1] = data.sky;

  names[2] = const_cast<char *>("sensor");
  values[2] = data.sensor;

  names[3] = const_cast<char *>("ambient");
  values[3] = data.ambient;

  names[4] = const_cast<char *>("rain");
  values[4] = data.rain;

  names[5] = const_cast<char *>("rainHeater");
  values[5] = data.rainHeater;

  names[6] = const_cast<char *>("rainTemp");
  values[6] = data.rainTemperature;

  names[7] = const_cast<char *>("LDR");
  values[7] = data.ldr;

  names[8] = const_cast<char *>("readCycle");
  values[8] = data.readCycle;
  lastReadPeriod = data.readCycle;

  names[9] = const_cast<char *>("windSpeed");
  values[9] = data.windSpeed;

  names[10] = const_cast<char *>("totalReadings");
  values[10] = data.totalReadings;
  
  INumberVectorProperty *nvp = getNumber("readings");
  IUUpdateNumber(nvp, values, names, N_DATA);
  nvp->s = IPS_OK;
  IDSetNumber(nvp, NULL);

  int N_ERRORS = 5;
  double valuesE[N_ERRORS];
  char *namesE[N_ERRORS];

  namesE[0] = const_cast<char *>("internalErrors");
  valuesE[0] = data.internalErrors;

  namesE[1] = const_cast<char *>("firstAddressByteErrors");
  valuesE[1] = data.firstByteErrors;

  namesE[2] = const_cast<char *>("commandByteErrors");
  valuesE[2] = data.commandByteErrors;

  namesE[3] = const_cast<char *>("secondAddressByteErrors");
  valuesE[3] = data.secondByteErrors;

  namesE[4] = const_cast<char *>("pecByteErrors");
  valuesE[4] = data.pecByteErrors;

  INumberVectorProperty *nvpE = getNumber("unitErrors");
  IUUpdateNumber(nvpE, valuesE, namesE, N_ERRORS);
  nvpE->s = IPS_OK;
  IDSetNumber(nvpE, NULL);

  int N_SENS = 8;
  double valuesS[N_SENS];
  char *namesS[N_SENS];

  float skyTemperature = float(data.sky) / 100.0;
  namesS[0] = const_cast<char *>("infraredSky");
  valuesS[0] = skyTemperature;

  namesS[1] = const_cast<char *>("infraredSensor");
  valuesS[1] = float(data.sensor) / 100.0;

  namesS[2] = const_cast<char *>("rainSensor");
  valuesS[2] = data.rain;

  float rainSensorTemperature = data.rainTemperature;
  if (rainSensorTemperature > 1022) {
    rainSensorTemperature = 1022;
  }
  if (rainSensorTemperature < 1) {
    rainSensorTemperature = 1;
  }
  rainSensorTemperature = constants.rainPullUpResistance / ((1023.0 / rainSensorTemperature) - 1.0);
  rainSensorTemperature = log(rainSensorTemperature / constants.rainResistanceAt25);
  rainSensorTemperature = 1.0 / (rainSensorTemperature / constants.rainBetaFactor + 1.0 / (ABS_ZERO + 25.0) ) - ABS_ZERO;

  namesS[3] = const_cast<char *>("rainSensorTemperature");
  valuesS[3] = rainSensorTemperature;

  float rainSensorHeater = data.rainHeater;
  rainSensorHeater = 100.0 * rainSensorHeater / 1023.0;
  namesS[4] = const_cast<char *>("rainSensorHeater");
  valuesS[4] = rainSensorHeater;

  float ambientLight = float(data.ldr);
  if (ambientLight > 1022.0) {
    ambientLight = 1022.0;
  }
  if (ambientLight < 1) {
    ambientLight = 1.0;
  }
  ambientLight = constants.ldrPullUpResistance / ((1023.0 / ambientLight) - 1.0);
  namesS[5] = const_cast<char *>("brightnessSensor");
  valuesS[5] = ambientLight;

  float ambientTemperature = data.ambient;

  if (ambientTemperature == -10000) {
    ambientTemperature = float(data.sensor) / 100.0;
  } else {
    if (ambientTemperature > 1022) {
      ambientTemperature = 1022;
    }
    if (ambientTemperature < 1) {
      ambientTemperature = 1;
    }
    ambientTemperature = constants.ambientPullUpResistance / ((1023.0 / ambientTemperature) - 1.0);
    ambientTemperature = log(ambientTemperature / constants.ambientResistanceAt25);
    ambientTemperature = 1.0 / (ambientTemperature / constants.ambientBetaFactor + 1.0 / (ABS_ZERO + 25.0)) - ABS_ZERO;
  }

  namesS[6] = const_cast<char *>("ambientTemperatureSensor");
  valuesS[6] = ambientTemperature;

  INumberVectorProperty *nvpSky = getNumber("skyCorrection");
  float k1 = getNumberValueFromVector(nvpSky, "k1");
  float k2 = getNumberValueFromVector(nvpSky, "k2");
  float k3 = getNumberValueFromVector(nvpSky, "k3");
  float k4 = getNumberValueFromVector(nvpSky, "k4");
  float k5 = getNumberValueFromVector(nvpSky, "k5");

  float correctedTemperature = skyTemperature - ( (k1 / 100.0) * (ambientTemperature - k2 / 10.0) + (k3 / 100.0) * pow(exp(k4 / 1000 * ambientTemperature), (k5 / 100.0)) );

  namesS[7] = const_cast<char *>("correctedInfraredSky");
  valuesS[7] = correctedTemperature;

  INumberVectorProperty *nvpS = getNumber("sensors");
  IUUpdateNumber(nvpS, valuesS, namesS, N_SENS);
  nvpS->s = IPS_OK;
  IDSetNumber(nvpS, NULL);



  ISState states[2];
  char * namesSw[2];
  namesSw[0] = const_cast<char *>("open");
  namesSw[1] = const_cast<char *>("close");
  //IDLog("%d\n", data.switchStatus);
  if (data.switchStatus == 1) {
    states[0] = ISS_OFF;
    states[1] = ISS_ON;
  } else {
    states[0] = ISS_ON;
    states[1] = ISS_OFF;
  }

  ISwitchVectorProperty *svpSw = getSwitch("deviceSwitch");
  IUUpdateSwitch(svpSw, states, namesSw, 2);
  svpSw->s = IPS_OK;
  IDSetSwitch(svpSw, NULL);


  INumberVectorProperty *nvpLimits = getNumber("limitsCloud");
  int clearLimit = getNumberValueFromVector(nvpLimits, "clear");
  int cloudyLimit = getNumberValueFromVector(nvpLimits, "cloudy");
  int overcastLimit = getNumberValueFromVector(nvpLimits, "overcast");

  ISState statesCloud[4];
  char * namesCloud[4];
  namesCloud[0] = const_cast<char *>("clear");
  namesCloud[1] = const_cast<char *>("cloudy");
  namesCloud[2] = const_cast<char *>("overcast");
  namesCloud[3] = const_cast<char *>("unknown");
  statesCloud[0] = ISS_OFF;
  statesCloud[1] = ISS_OFF;
  statesCloud[2] = ISS_OFF;
  statesCloud[3] = ISS_OFF;
  //IDLog("%d\n", data.switchStatus);
  if (correctedTemperature < clearLimit) {
    statesCloud[0] = ISS_ON;
  } else if (correctedTemperature < cloudyLimit) {
    statesCloud[1] = ISS_ON;
  } else if (correctedTemperature < overcastLimit) {
    statesCloud[2] = ISS_ON;
  } else {
    statesCloud[3] = ISS_ON;
  }

  ISwitchVectorProperty *svpCC = getSwitch("cloudConditions");
  IUUpdateSwitch(svpCC, statesCloud, namesCloud, 4);
  svpCC->s = IPS_OK;
  IDSetSwitch(svpCC, NULL);




  nvpLimits = getNumber("limitsRain");
  int dryLimit = getNumberValueFromVector(nvpLimits, "dry");
  int wetLimit = getNumberValueFromVector(nvpLimits, "wet");
  int rainLimit = getNumberValueFromVector(nvpLimits, "rain");

  ISState statesRain[4];
  char * namesRain[4];
  namesRain[0] = const_cast<char *>("dry");
  namesRain[1] = const_cast<char *>("wet");
  namesRain[2] = const_cast<char *>("rain");
  namesRain[3] = const_cast<char *>("unknown");
  statesRain[0] = ISS_OFF;
  statesRain[1] = ISS_OFF;
  statesRain[2] = ISS_OFF;
  statesRain[3] = ISS_OFF;
  //IDLog("%d\n", data.switchStatus);
  if (data.rain < rainLimit) {
    statesRain[3] = ISS_ON;
  } else if (data.rain < wetLimit) {
    statesRain[2] = ISS_ON;
  } else if (data.rain < dryLimit) {
    statesRain[1] = ISS_ON;
  } else {
    statesRain[0] = ISS_ON;
  }

  ISwitchVectorProperty *svpRC = getSwitch("rainConditions");
  IUUpdateSwitch(svpRC, statesRain, namesRain, 4);
  svpRC->s = IPS_OK;
  IDSetSwitch(svpRC, NULL);


  nvpLimits = getNumber("limitsBrightness");
  int darkLimit = getNumberValueFromVector(nvpLimits, "dark");
  int lightLimit = getNumberValueFromVector(nvpLimits, "light");
  int veryLightLimit = getNumberValueFromVector(nvpLimits, "veryLight");

  ISState statesBrightness[3];
  char * namesBrightness[3];
  namesBrightness[0] = const_cast<char *>("dark");
  namesBrightness[1] = const_cast<char *>("light");
  namesBrightness[2] = const_cast<char *>("veryLight");
  statesBrightness[0] = ISS_OFF;
  statesBrightness[1] = ISS_OFF;
  statesBrightness[2] = ISS_OFF;
  //IDLog("%d\n", data.switchStatus);
  if (ambientLight > darkLimit) {
    statesBrightness[0] = ISS_ON;
  } else if (ambientLight > lightLimit) {
    statesBrightness[1] = ISS_ON;
  } else {
    statesBrightness[2] = ISS_ON;
  }

  ISwitchVectorProperty *svpBC = getSwitch("brightnessConditions");
  IUUpdateSwitch(svpBC, statesBrightness, namesBrightness, 3);
  svpBC->s = IPS_OK;
  IDSetSwitch(svpBC, NULL);
  
  
  int windSpeed = data.windSpeed;
  nvpLimits = getNumber("limitsWind");
  int calmLimit = getNumberValueFromVector(nvpLimits, "calm");
  int moderateWindLimit = getNumberValueFromVector(nvpLimits, "moderateWind");
  
  INumberVectorProperty *consts = getNumber("constants");
  int anemometerStatus = getNumberValueFromVector(consts, "anemometerStatus");

  ISState statesWind[4];
  char * namesWind[4];
  namesWind[0] = const_cast<char *>("calm");
  namesWind[1] = const_cast<char *>("moderateWind");
  namesWind[2] = const_cast<char *>("strongWind");
  namesWind[3] = const_cast<char *>("unknown");
  statesWind[0] = ISS_OFF;
  statesWind[1] = ISS_OFF;
  statesWind[2] = ISS_OFF;
  statesWind[3] = ISS_OFF;
  //IDLog("%d\n", data.switchStatus);
  
  if (anemometerStatus) {
    if (windSpeed < calmLimit) {
      statesWind[0] = ISS_ON;
    } else if (windSpeed < moderateWindLimit) {
      statesWind[1] = ISS_ON;
    } else {
      statesWind[2] = ISS_ON;
    } 
  } else {
    statesWind[3] = ISS_ON;
  } 

  ISwitchVectorProperty *svpWC = getSwitch("windConditions");
  IUUpdateSwitch(svpWC, statesWind, namesWind, 4);
  svpWC->s = IPS_OK;
  IDSetSwitch(svpWC, NULL);
}
Exemplo n.º 12
0
bool AAGCloudWatcher::heatingAlgorithm() {

  INumberVectorProperty *heaterParameters = getNumber("heaterParameters");
  float tempLow = getNumberValueFromVector(heaterParameters, "tempLow");
  float tempHigh = getNumberValueFromVector(heaterParameters, "tempHigh");
  float deltaLow = getNumberValueFromVector(heaterParameters, "deltaLow");
  float deltaHigh = getNumberValueFromVector(heaterParameters, "deltaHigh");
  float heatImpulseTemp = getNumberValueFromVector(heaterParameters, "heatImpulseTemp");
  float heatImpulseDuration = getNumberValueFromVector(heaterParameters, "heatImpulseDuration");
  float heatImpulseCycle = getNumberValueFromVector(heaterParameters, "heatImpulseCycle");
  float min = getNumberValueFromVector(heaterParameters, "min");

  INumberVectorProperty *sensors = getNumber("sensors");
  float ambient = getNumberValueFromVector(sensors, "ambientTemperatureSensor");
  float rainSensorTemperature = getNumberValueFromVector(sensors, "rainSensorTemperature");

  INumberVectorProperty *ref = getNumber("refresh");
  float refresh = getNumberValueFromVector(ref, "refreshPeriod");

  if (globalRainSensorHeater == -1) {  // If not already setted
    globalRainSensorHeater = getNumberValueFromVector(sensors, "rainSensorHeater");
  }


  time_t currentTime = time(NULL);

  if ((isWetRain()) && (heatingStatus == normal)) {  // We check if sensor is wet.
    if (wetStartTime == -1) { // First moment wet
      wetStartTime = time(NULL);
    } else { // We have been wet for a while

      if (currentTime - wetStartTime >= heatImpulseCycle) { // We have been a cycle wet. Apply pulse
        wetStartTime = -1;
        heatingStatus = increasingToPulse;
        pulseStartTime = -1;
      }
    }
  } else {  // is not wet
    wetStartTime = -1;
  }

  if (heatingStatus == pulse) {
    if (currentTime - pulseStartTime > heatImpulseDuration) {  // Pulse ends
      heatingStatus = normal;
      wetStartTime = -1;
      pulseStartTime = -1;
    }
  }


  if (heatingStatus == normal) {
    // Compute desired temperature

    if (ambient < tempLow) {
      desiredSensorTemperature = deltaLow;
    } else if (ambient > tempHigh) {
      desiredSensorTemperature = ambient + deltaHigh;
    } else { // Between tempLow and tempHigh
      float delt = ((((ambient - tempLow) / (tempHigh - tempLow)) * (deltaHigh - deltaLow)) + deltaLow);

      desiredSensorTemperature = ambient + delt;

      if (desiredSensorTemperature < tempLow) {
        desiredSensorTemperature = deltaLow;
      }
    }
  } else {
    desiredSensorTemperature = ambient + heatImpulseTemp;
  }

  if (heatingStatus == increasingToPulse) {
    if (rainSensorTemperature < desiredSensorTemperature) {
      globalRainSensorHeater = 100.0;
    } else {
      // the pulse starts
      pulseStartTime = time(NULL);
      heatingStatus = pulse;
    }
  }

  if ( (heatingStatus == normal) || (heatingStatus == pulse) ) {  // Check desired temperature and act accordingly
    // Obtain the difference in temperature and modifier
    float dif = fabs(desiredSensorTemperature - rainSensorTemperature);
    float refreshModifier = sqrt(refresh / 10.0);
    float modifier = 1;

    if (dif > 8) {
      modifier = (1.4 / refreshModifier);
    } else if (dif > 4) {
      modifier = (1.2 / refreshModifier);
    } else if (dif > 3) {
      modifier = (1.1 / refreshModifier);
    } else if (dif > 2) {
      modifier = (1.06 / refreshModifier);
    } else if (dif > 1) {
      modifier = (1.04 / refreshModifier);
    } else if (dif > 0.5) {
      modifier = (1.02 / refreshModifier);
    } else if (dif > 0.3) {
      modifier = (1.01 / refreshModifier);
    }

    if (rainSensorTemperature > desiredSensorTemperature) {        // Lower heating
   //   IDLog("Temp: %f, Desired: %f, Lowering: %f %f -> %f\n", rainSensorTemperature, desiredSensorTemperature, modifier, globalRainSensorHeater, globalRainSensorHeater / modifier);
      globalRainSensorHeater /= modifier;
    } else {   // increase heating
   //   IDLog("Temp: %f, Desired: %f, Increasing: %f %f -> %f\n", rainSensorTemperature, desiredSensorTemperature, modifier, globalRainSensorHeater, globalRainSensorHeater * modifier);
      globalRainSensorHeater *= modifier;
    }
  }

  if (globalRainSensorHeater < min) {
    globalRainSensorHeater = min;
  }
  if (globalRainSensorHeater > 100.0) {
    globalRainSensorHeater = 100.0;
  }

  int rawSensorHeater = int(globalRainSensorHeater * 1023.0 / 100.0);

  cwc->setPWMDutyCycle(rawSensorHeater);

  // Sending heater status to clients
  char *namesSw[3];
  ISState statesSw[3];
  statesSw[0] = ISS_OFF;
  statesSw[1] = ISS_OFF;
  statesSw[2] = ISS_OFF;
  namesSw[0] = const_cast<char *>("normal");
  namesSw[1] = const_cast<char *>("increasing");
  namesSw[2] = const_cast<char *>("pulse");

  if (heatingStatus == normal) {
    statesSw[0] = ISS_ON;
  } else if (heatingStatus == increasingToPulse) {
    statesSw[1] = ISS_ON;
  } else if (heatingStatus == pulse) {
    statesSw[2] = ISS_ON;
  }

  ISwitchVectorProperty *svp = getSwitch("heaterStatus");
  IUUpdateSwitch(svp, statesSw, namesSw, 3);
  svp->s = IPS_OK;
  IDSetSwitch(svp, NULL);
}
Exemplo n.º 13
0
bool AAGCloudWatcher::ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n) {
	// ignore if not ours //

  if (strcmp (dev, getDefaultName())) {
    return false;
  }

  if (INDI::DefaultDevice::ISNewSwitch(dev, name, states, names, n) == true) {
    return true;
  }

  ISwitchVectorProperty *svp = getSwitch(name);

  if (!svp) {
    return false;
  }

  int error = 0;
  if (!strcmp(svp->name, "deviceSwitch")) {
    char * namesSw[2];
    ISState statesSw[2];
    statesSw[0] = ISS_ON;
    statesSw[1] = ISS_OFF;
    namesSw[0] = const_cast<char *>("open");
    namesSw[1] = const_cast<char *>("close");

    ISState openState;

    if (strcmp(names[0], "open") == 0) {
      openState = states[0];
    } else {
      openState = states[1];
    }

    if (openState == ISS_ON) {
      if (isConnected()) {
        bool r = cwc->openSwitch();

        if (!r) {
          statesSw[0] = ISS_OFF;
          statesSw[1] = ISS_ON;
        }
      } else {
        statesSw[0] = ISS_ON;
        statesSw[1] = ISS_OFF;
        error = 1;
      }
    } else {
      if (isConnected()) {
        bool r = cwc->closeSwitch();

        if (r) {
          statesSw[0] = ISS_OFF;
          statesSw[1] = ISS_ON;
        }
      } else {
        statesSw[0] = ISS_ON;
        statesSw[1] = ISS_OFF;
        error = 1;
      }
    }

    IUUpdateSwitch(svp, statesSw, namesSw, 2);
    if (error) {
      svp->s = IPS_IDLE;
    } else {
      svp->s = IPS_OK;
    }
    IDSetSwitch(svp, NULL);

    return true;
  }

  return DefaultDevice::ISNewSwitch(dev, name, states, names, n);
}
Exemplo n.º 14
0
bool ASICCD::ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n)
{
    ASI_ERROR_CODE errCode = ASI_SUCCESS;

    if(!strcmp(dev,getDeviceName()))
    {
        if (!strcmp(name, ControlSP.name))
        {
           IUUpdateSwitch(&ControlSP, states, names, n);

           for (int i=0; i < ControlSP.nsp; i++)
           {
               ASI_CONTROL_TYPE swType = *((ASI_CONTROL_TYPE *) ControlS[i].aux);
               ASI_BOOL swAuto = (ControlS[i].s == ISS_ON) ? ASI_TRUE : ASI_FALSE;

               for (int j=0; j < ControlNP.nnp; j++)
               {
                   ASI_CONTROL_TYPE nType = *((ASI_CONTROL_TYPE *) ControlN[j].aux0);

                   if (swType == nType)
                   {
                        DEBUGF(INDI::Logger::DBG_DEBUG, "ISNewSwitch->SetControlValue %d %.2f", nType, ControlN[j].value);
                       if ( (errCode = ASISetControlValue(m_camInfo->CameraID, nType, ControlN[j].value, swAuto )) != ASI_SUCCESS)
                       {
                           DEBUGF(INDI::Logger::DBG_ERROR, "ASISetControlValue (%s=%g) error (%d)", ControlN[j].name, ControlN[j].value, errCode);
                           ControlNP.s = IPS_ALERT;
                           ControlSP.s = IPS_ALERT;
                           IDSetNumber(&ControlNP, NULL);
                           IDSetSwitch(&ControlSP, NULL);
                           return false;
                       }

                       *((ASI_BOOL *) ControlN[j].aux1) = swAuto;
                       break;

                   }
               }
           }

           ControlSP.s = IPS_OK;
           IDSetSwitch(&ControlSP, NULL);
           return true;

        }

        /* Cooler */
       if (!strcmp (name, CoolerSP.name))
       {
         if (IUUpdateSwitch(&CoolerSP, states, names, n) < 0)
             return false;

         bool rc=false;

         if (CoolerS[0].s == ISS_ON)
           activateCooler(true);
         else
           activateCooler(false);

         return true;
       }

        if (!strcmp(name, VideoFormatSP.name))
        {
            #if !defined(OSX_EMBEDED_MODE) && !defined(__CYGWIN__)
            if (streamer->isBusy())
            {
                VideoFormatSP.s = IPS_ALERT;
                DEBUG(INDI::Logger::DBG_ERROR, "Cannot change format while streaming/recording.");
                IDSetSwitch(&VideoFormatSP, NULL);
                return true;
            }
            #endif

            IUUpdateSwitch(&VideoFormatSP, states, names, n);

            ASI_IMG_TYPE type = getImageType();

            switch (type)
            {
                case ASI_IMG_RAW16:
                    PrimaryCCD.setBPP(16);
                    break;

                default:
                   PrimaryCCD.setBPP(8);
                    break;
            }

            UpdateCCDFrame(PrimaryCCD.getSubX(), PrimaryCCD.getSubY(), PrimaryCCD.getSubW(), PrimaryCCD.getSubH());

            updateRecorderFormat();

            VideoFormatSP.s = IPS_OK;
            IDSetSwitch(&VideoFormatSP, NULL);
            return true;
        }

    }

   return INDI::CCD::ISNewSwitch(dev,name,states,names,n);
}
Exemplo n.º 15
0
/************************************************************************************
 *
* ***********************************************************************************/
bool BaaderDome::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
{
    if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
    {
        if (strcmp(name, CalibrateSP.name) == 0)
        {
            IUResetSwitch(&CalibrateSP);

            if (status == DOME_READY)
            {
                CalibrateSP.s = IPS_OK;
                DEBUG(INDI::Logger::DBG_SESSION, "Dome is already calibrated.");
                IDSetSwitch(&CalibrateSP, nullptr);
                return true;
            }

            if (CalibrateSP.s == IPS_BUSY)
            {
                Abort();
                DEBUG(INDI::Logger::DBG_SESSION, "Calibration aborted.");
                status        = DOME_UNKNOWN;
                CalibrateSP.s = IPS_IDLE;
                IDSetSwitch(&CalibrateSP, nullptr);
                return true;
            }

            status = DOME_CALIBRATING;

            DEBUG(INDI::Logger::DBG_SESSION, "Starting calibration procedure...");

            calibrationStage = CALIBRATION_STAGE1;

            calibrationStart = DomeAbsPosN[0].value;

            // Goal of procedure is to reach south point to hit sensor
            calibrationTarget1 = calibrationStart + 179;
            if (calibrationTarget1 > 360)
                calibrationTarget1 -= 360;

            if (MoveAbs(calibrationTarget1) == IPS_IDLE)
            {
                CalibrateSP.s = IPS_ALERT;
                DEBUG(INDI::Logger::DBG_ERROR, "Calibration failue due to dome motion failure.");
                status = DOME_UNKNOWN;
                IDSetSwitch(&CalibrateSP, nullptr);
                return false;
            }

            DomeAbsPosNP.s = IPS_BUSY;
            CalibrateSP.s  = IPS_BUSY;
            DEBUGF(INDI::Logger::DBG_SESSION, "Calibration is in progress. Moving to position %g.", calibrationTarget1);
            IDSetSwitch(&CalibrateSP, nullptr);
            return true;
        }

        if (strcmp(name, DomeFlapSP.name) == 0)
        {
            int ret        = 0;
            int prevStatus = IUFindOnSwitchIndex(&DomeFlapSP);
            IUUpdateSwitch(&DomeFlapSP, states, names, n);
            int FlapDome = IUFindOnSwitchIndex(&DomeFlapSP);

            // No change of status, let's return
            if (prevStatus == FlapDome)
            {
                DomeFlapSP.s = IPS_OK;
                IDSetSwitch(&DomeFlapSP, nullptr);
            }

            // go back to prev status in case of failure
            IUResetSwitch(&DomeFlapSP);
            DomeFlapS[prevStatus].s = ISS_ON;

            if (FlapDome == 0)
                ret = ControlDomeFlap(FLAP_OPEN);
            else
                ret = ControlDomeFlap(FLAP_CLOSE);

            if (ret == 0)
            {
                DomeFlapSP.s = IPS_OK;
                IUResetSwitch(&DomeFlapSP);
                DomeFlapS[FlapDome].s = ISS_ON;
                IDSetSwitch(&DomeFlapSP, "Flap is %s.", (FlapDome == 0 ? "open" : "closed"));
                return true;
            }
            else if (ret == 1)
            {
                DomeFlapSP.s = IPS_BUSY;
                IUResetSwitch(&DomeFlapSP);
                DomeFlapS[FlapDome].s = ISS_ON;
                IDSetSwitch(&DomeFlapSP, "Flap is %s...", (FlapDome == 0 ? "opening" : "closing"));
                return true;
            }

            DomeFlapSP.s = IPS_ALERT;
            IDSetSwitch(&DomeFlapSP, "Flap failed to %s.", (FlapDome == 0 ? "open" : "close"));
            return false;
        }
    }

    return INDI::Dome::ISNewSwitch(dev, name, states, names, n);
}
Exemplo n.º 16
0
bool GPhotoCCD::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
{

  if (strcmp(dev, getDeviceName()) == 0)
  {
      if (!strcmp(name, mIsoSP.name))
      {
          if (IUUpdateSwitch(&mIsoSP, states, names, n) < 0)
              return false;

          for (int i = 0; i < mIsoSP.nsp; i++)
          {
              if (mIsoS[i].s == ISS_ON)
              {
                  if (sim == false)
                      gphoto_set_iso(gphotodrv, i);
                  mIsoSP.s = IPS_OK;
                  IDSetSwitch(&mIsoSP, NULL);
                  break;
              }
          }
      }
      
      if (!strcmp(name, mFormatSP.name))
      {
          int prevSwitch = IUFindOnSwitchIndex(&mFormatSP);
          if (IUUpdateSwitch(&mFormatSP, states, names, n) < 0)
              return false;

          ISwitch *sp = IUFindOnSwitch(&mFormatSP);
          if (sp)
          {
              if (strstr(sp->label, "+"))
              {
                  DEBUGF(INDI::Logger::DBG_ERROR, "%s format is not supported.", sp->label);
                  IUResetSwitch(&mFormatSP);
                  mFormatSP.s = IPS_ALERT;
                  mFormatSP.sp[prevSwitch].s = ISS_ON;
                  IDSetSwitch(&mFormatSP, NULL);
                  return false;
              }
          }
          for (int i = 0; i < mFormatSP.nsp; i++)
          {
              if (mFormatS[i].s == ISS_ON)
              {
                  if (sim == false)
                    gphoto_set_format(gphotodrv, i);
                  mFormatSP.s = IPS_OK;
                  IDSetSwitch(&mFormatSP, NULL);
                  // We need to get frame W and H if format changes
                  frameInitialized = false;
                  break;
              }
          }
      }

      if (!strcmp(name, transferFormatSP.name))
      {
          IUUpdateSwitch(&transferFormatSP, states, names, n);
          transferFormatSP.s = IPS_OK;
          IDSetSwitch(&transferFormatSP, NULL);
          // We need to get frame W and H if transfer format changes
          frameInitialized = false;
          return true;
      }

      if (!strcmp(name, autoFocusSP.name))
      {
          IUResetSwitch(&autoFocusSP);
          if (gphoto_auto_focus(gphotodrv) == GP_OK)
              autoFocusSP.s = IPS_OK;
          else
              autoFocusSP.s = IPS_ALERT;

          IDSetSwitch(&autoFocusSP, NULL);
          return true;
      }

      if (!strcmp(name, UploadSP.name))
      {
          IUUpdateSwitch(&UploadSP, states, names, n);
          UploadSP.s = IPS_OK;
          IDSetSwitch(&UploadSP, NULL);

          if (!sim)
              gphoto_set_upload_settings(gphotodrv, IUFindOnSwitchIndex(&UploadSP));
          return true;
      }

      if (!strcmp(name, livePreviewSP.name))
      {
          IUUpdateSwitch(&livePreviewSP, states, names, n);
          if (livePreviewS[0].s == ISS_ON)
          {
              livePreviewSP.s = IPS_BUSY;
              SetTimer(STREAMPOLLMS);
          }
          else
              livePreviewSP.s = IPS_IDLE;
          IDSetSwitch(&livePreviewSP, NULL);
          return true;
      }

      if (strstr(name, "FOCUS"))
      {
          return processFocuserSwitch(dev, name, states, names, n);
      }

      if(CamOptions.find(name) != CamOptions.end())
      {
          cam_opt *opt = CamOptions[name];
          if (opt->widget->type != GP_WIDGET_RADIO
              && opt->widget->type != GP_WIDGET_MENU
              && opt->widget->type != GP_WIDGET_TOGGLE)
          {
              DEBUGF(INDI::Logger::DBG_ERROR, "ERROR: Property '%s'is not a switch (%d)", name, opt->widget->type);
              return false;
          }

          if (opt->widget->readonly)
          {
              DEBUGF(INDI::Logger::DBG_WARNING, "WARNING: Property %s is read-only", name);
              IDSetSwitch(&opt->prop.sw, NULL);
              return false;
          }

          if (IUUpdateSwitch(&opt->prop.sw, states, names, n) < 0)
              return false;

          if (opt->widget->type == GP_WIDGET_TOGGLE)
          {
              gphoto_set_widget_num(gphotodrv, opt->widget, opt->item.sw[ON_S].s == ISS_ON);
          } else
          {
              for (int i = 0; i < opt->prop.sw.nsp; i++)
              {
                  if (opt->item.sw[i].s == ISS_ON)
                  {
                      gphoto_set_widget_num(gphotodrv, opt->widget, i);
                      break;
                  }
              }
          }
          opt->prop.sw.s = IPS_OK;
          IDSetSwitch(&opt->prop.sw, NULL);
          return true;
      }            
  }

  return INDI::CCD::ISNewSwitch(dev, name, states, names, n);

}
Exemplo n.º 17
0
/************************************************************************************
 *
* ***********************************************************************************/
bool ScopeDome::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
{
    if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
    {
        if (strcmp(name, FindHomeSP.name) == 0)
        {
            if (status != DOME_HOMING)
            {
                LOG_INFO("Finding home sensor");
                status = DOME_HOMING;
                IUResetSwitch(&FindHomeSP);
                DomeAbsPosNP.s = IPS_BUSY;
                FindHomeSP.s   = IPS_BUSY;
                IDSetSwitch(&FindHomeSP, nullptr);
                writeCmd(FindHome);
            }
            return true;
        }

        if (strcmp(name, DerotateSP.name) == 0)
        {
            if (status != DOME_DEROTATING)
            {
                LOG_INFO("De-rotating started");
                status = DOME_DEROTATING;
                IUResetSwitch(&DerotateSP);
                DomeAbsPosNP.s = IPS_BUSY;
                DerotateSP.s   = IPS_BUSY;
                IDSetSwitch(&DerotateSP, nullptr);
            }
            return true;
        }

        if (strcmp(name, StartCalibrationSP.name) == 0)
        {
            if (status != DOME_CALIBRATING)
            {
                LOG_INFO("Calibration started");
                status = DOME_CALIBRATING;
                IUResetSwitch(&StartCalibrationSP);
                DomeAbsPosNP.s       = IPS_BUSY;
                StartCalibrationSP.s = IPS_BUSY;
                IDSetSwitch(&StartCalibrationSP, nullptr);
                writeCmd(FullSystemCal);
            }
            return true;
        }

        if (strcmp(name, PowerRelaysSP.name) == 0)
        {
            IUUpdateSwitch(&PowerRelaysSP, states, names, n);
            setOutputState(OUT_CCD, PowerRelaysS[0].s);
            setOutputState(OUT_SCOPE, PowerRelaysS[1].s);
            setOutputState(OUT_LIGHT, PowerRelaysS[2].s);
            setOutputState(OUT_FAN, PowerRelaysS[3].s);
            IDSetSwitch(&PowerRelaysSP, nullptr);
            return true;
        }

        if (strcmp(name, RelaysSP.name) == 0)
        {
            IUUpdateSwitch(&RelaysSP, states, names, n);
            setOutputState(OUT_RELAY1, RelaysS[0].s);
            setOutputState(OUT_RELAY2, RelaysS[1].s);
            setOutputState(OUT_RELAY3, RelaysS[2].s);
            setOutputState(OUT_RELAY4, RelaysS[3].s);
            IDSetSwitch(&RelaysSP, nullptr);
            return true;
        }

        if (strcmp(name, ParkShutterSP.name) == 0)
        {
            IUUpdateSwitch(&ParkShutterSP, states, names, n);
            ParkShutterSP.s = IPS_OK;
            IDSetSwitch(&ParkShutterSP, nullptr);
            return true;
        }
    }

    return INDI::Dome::ISNewSwitch(dev, name, states, names, n);
}
Exemplo n.º 18
0
bool NStep::ISNewSwitch(const char * dev, const char * name, ISState * states, char * names[], int n)
{
    if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
    {
        // Temperature Compensation Mode
        if (!strcmp(name, CompensationModeSP.name))
        {
            int prevIndex = IUFindOnSwitchIndex(&CompensationModeSP);
            IUUpdateSwitch(&CompensationModeSP, states, names, n);
            int mode = IUFindOnSwitchIndex(&CompensationModeSP);
            if (setCompensationMode(mode))
            {
                CompensationModeSP.s = IPS_OK;
                // If it was set to one shot, we put it back to off?
                switch (mode)
                {
                    case COMPENSATION_MODE_OFF:
                        LOG_INFO("Temperature compensation is disabled.");
                        break;

                    case COMPENSATION_MODE_ONE_SHOT:
                        IUResetSwitch(&CompensationModeSP);
                        CompensationModeS[COMPENSATION_MODE_OFF].s = ISS_ON;
                        LOG_INFO("One shot compensation applied.");
                        break;

                    case COMPENSATION_MODE_AUTO:
                        LOG_INFO("Automatic temperature compensation is enabled.");
                        break;
                }
            }
            else
            {
                IUResetSwitch(&CompensationModeSP);
                CompensationModeS[prevIndex].s = ISS_ON;
                CompensationModeSP.s = IPS_ALERT;
                LOG_ERROR("Failed to change temperature compnensation mode.");
            }

            IDSetSwitch(&CompensationModeSP, nullptr);
            return true;
        }

        // Manual Prime
        if (!strcmp(name, PrimeManualSP.name))
        {
            sendCommand(":TI");
            PrimeManualSP.s = IPS_OK;
            IDSetSwitch(&PrimeManualSP, nullptr);
            LOG_INFO("Prime for manual complete. Click One Shot to apply manual compensation once.");
            return true;
        }

        // Stepping Mode
        if (!strcmp(name, SteppingModeSP.name))
        {
            IUUpdateSwitch(&SteppingModeSP, states, names, n);
            SteppingModeSP.s = IPS_OK;
            IDSetSwitch(&SteppingModeSP, nullptr);
            return true;
        }

        // Coil Status after Move is done
        if (!strcmp(name, CoilStatusSP.name))
        {
            int prevIndex = IUFindOnSwitchIndex(&CoilStatusSP);
            IUUpdateSwitch(&CoilStatusSP, states, names, n);
            int state = IUFindOnSwitchIndex(&CoilStatusSP);
            if (setCoilStatus(state))
            {
                CoilStatusSP.s = IPS_OK;
                if (state == COIL_ENERGIZED_ON)
                    LOG_WARN("Coil shall be kept energized after motion is complete. Watch for motor heating!");
                else
                    LOG_INFO("Coil shall be de-energized after motion is complete.");
            }
            else
            {
                IUResetSwitch(&CoilStatusSP);
                CoilStatusS[prevIndex].s = ISS_ON;
                CoilStatusSP.s = IPS_ALERT;
                LOG_ERROR("Failed to update coil energization status.");
            }

            IDSetSwitch(&CoilStatusSP, nullptr);
            return true;
        }
    }

    return INDI::Focuser::ISNewSwitch(dev, name, states, names, n);
}
Exemplo n.º 19
0
bool ATIKCCD::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
{
    if (dev != nullptr && !strcmp(dev, getDeviceName()))
    {
        // Gain/Offset Presets
        if (!strcmp(name, ControlPresetsSP.name))
        {
            int prevIndex = IUFindOnSwitchIndex(&ControlPresetsSP);
            IUUpdateSwitch(&ControlPresetsSP, states, names, n);
            int targetIndex = IUFindOnSwitchIndex(&ControlPresetsSP);
            uint16_t value = static_cast<uint16_t>(targetIndex + 2);
            uint8_t *data = reinterpret_cast<uint8_t*>(&value);
            int rc = ArtemisCameraSpecificOptionSetData(hCam, ID_AtikHorizonGOPresetMode, data, 2);
            if (rc != ARTEMIS_OK)
            {
                ControlPresetsSP.s = IPS_ALERT;
                IUResetSwitch(&ControlPresetsSP);
                ControlPresetsS[prevIndex].s = ISS_ON;
            }
            else
                ControlPresetsSP.s = IPS_OK;

            IDSetSwitch(&ControlPresetsSP, nullptr);
            return true;
        }

        // Cooler controler
        if (!strcmp(name, CoolerSP.name))
        {
            if (IUUpdateSwitch(&CoolerSP, states, names, n) < 0)
            {
                CoolerSP.s = IPS_ALERT;
                IDSetSwitch(&CoolerSP, nullptr);
                return true;
            }

            bool enabled = (CoolerS[COOLER_ON].s == ISS_ON);

            // If user turns on cooler, but the requested temperature is higher than current temperature
            // then we set temperature to zero degrees. If that was still higher than current temperature
            // we return an error
            if (enabled && TemperatureRequest > TemperatureN[0].value)
            {
                TemperatureRequest = 0;
                // If current temperature is still lower than zero, then we shouldn't risk
                // setting temperature to any arbitrary value. Instead, we report an error and ask
                // user to explicitly set the requested temperature.
                if (TemperatureRequest > TemperatureN[0].value)
                {
                    CoolerS[COOLER_ON].s = ISS_OFF;
                    CoolerS[COOLER_OFF].s = ISS_OFF;
                    CoolerSP.s = IPS_ALERT;
                    LOGF_WARN("Cannot manually activate cooler since current temperature is %.2f. To activate cooler, request a lower temperature.", TemperatureN[0].value);
                    IDSetSwitch(&CoolerSP, nullptr);
                    return true;
                }

                SetTemperature(0);
                return true;
            }

            return activateCooler(enabled);
        }
    }

    return INDI::CCD::ISNewSwitch(dev, name, states, names, n);
}