Exemplo n.º 1
0
void LX200_16::ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n)
{
   int index;
   int err;

  if (strcmp (dev, thisDevice))
    return;

   if (!strcmp(name, FanStatusSw.name))
   {
      if (checkPower(&FanStatusSw))
       return;

          IUResetSwitches(&FanStatusSw);
          IUUpdateSwitches(&FanStatusSw, states, names, n);
          index = getOnSwitch(&FanStatusSw);

	  if (index == 0)
	  {
	    if ( (err = turnFanOn()) < 0)
	    {
	      handleError(&FanStatusSw, err, "Changing fan status");
	      return;
	    }
	  }
	  else
	  {
	    if ( (err = turnFanOff()) < 0)
	    {
	      handleError(&FanStatusSw, err, "Changing fan status");
	      return;
	    }
	  }
	  
	  FanStatusSw.s = IPS_OK;
	  IDSetSwitch (&FanStatusSw, index == 0 ? "Fan is ON" : "Fan is OFF");
	  return;
   }

   if (!strcmp(name, HomeSearchSw.name))
   {
      if (checkPower(&HomeSearchSw))
       return;

          IUResetSwitches(&HomeSearchSw);
          IUUpdateSwitches(&HomeSearchSw, states, names, n);
          index = getOnSwitch(&HomeSearchSw);

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

   if (!strcmp(name, FieldDeRotatorSw.name))
   {
      if (checkPower(&FieldDeRotatorSw))
       return;

          IUResetSwitches(&FieldDeRotatorSw);
          IUUpdateSwitches(&FieldDeRotatorSw, states, names, n);
          index = getOnSwitch(&FieldDeRotatorSw);

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

    LX200Autostar::ISNewSwitch (dev, name, states, names, n);

}
Exemplo n.º 2
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);
}