Instrument Neutral Distributed Interface INDI  2.0.2
indidustcapinterface.cpp
Go to the documentation of this file.
1 /*
2  Dust Cap Interface
3  Copyright (C) 2015 Jasem Mutlaq (mutlaqja@ikarustech.com)
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 
19 */
20 
21 #include "indidustcapinterface.h"
22 
23 #include <cstring>
24 
25 namespace INDI
26 {
27 
28 void DustCapInterface::initDustCapProperties(const char *deviceName, const char *groupName)
29 {
30  strncpy(dustCapName, deviceName, MAXINDIDEVICE);
31 
32  // Open/Close cover
33  IUFillSwitch(&ParkCapS[CAP_PARK], "PARK", "Park", ISS_OFF);
34  IUFillSwitch(&ParkCapS[CAP_UNPARK], "UNPARK", "Unpark", ISS_OFF);
35  IUFillSwitchVector(&ParkCapSP, ParkCapS, 2, deviceName, "CAP_PARK", "Dust Cover", groupName, IP_RW, ISR_1OFMANY, 0,
36  IPS_IDLE);
37 }
38 
39 bool DustCapInterface::processDustCapSwitch(const char *dev, const char *name, ISState *states, char *names[],
40  int n)
41 {
42  INDI_UNUSED(dev);
43  // Park/UnPark Dust Cover
44  if (!strcmp(ParkCapSP.name, name))
45  {
46  int prevSwitch = IUFindOnSwitchIndex(&ParkCapSP);
47  IUUpdateSwitch(&ParkCapSP, states, names, n);
48  if (ParkCapS[CAP_PARK].s == ISS_ON)
49  ParkCapSP.s = ParkCap();
50  else
51  ParkCapSP.s = UnParkCap();
52 
53  if (ParkCapSP.s == IPS_ALERT)
54  {
56  ParkCapS[prevSwitch].s = ISS_ON;
57  }
58 
59  IDSetSwitch(&ParkCapSP, nullptr);
60  return true;
61  }
62 
63  return false;
64 }
65 
67 {
68  // Must be implemented by child class
69  return IPS_ALERT;
70 }
71 
73 {
74  // Must be implemented by child class
75  return IPS_ALERT;
76 }
77 }
void initDustCapProperties(const char *deviceName, const char *groupName)
Initilize dust cap properties. It is recommended to call this function within initProperties() of you...
virtual IPState ParkCap()
Park dust cap (close cover). Must be implemented by child.
bool processDustCapSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Process dust cap switch properties.
ISwitchVectorProperty ParkCapSP
virtual IPState UnParkCap()
unPark dust cap (open cover). Must be implemented by child.
ISState
Switch state.
Definition: indiapi.h:150
@ ISS_OFF
Definition: indiapi.h:151
@ ISS_ON
Definition: indiapi.h:152
#define MAXINDIDEVICE
Definition: indiapi.h:193
@ IP_RW
Definition: indiapi.h:186
IPState
Property state.
Definition: indiapi.h:160
@ IPS_ALERT
Definition: indiapi.h:164
@ IPS_IDLE
Definition: indiapi.h:161
@ ISR_1OFMANY
Definition: indiapi.h:173
int IUFindOnSwitchIndex(const ISwitchVectorProperty *svp)
Returns the index of first ON switch it finds in the vector switch property.
Definition: indidevapi.c:128
void IUResetSwitch(ISwitchVectorProperty *svp)
Reset all switches in a switch vector property to OFF.
Definition: indidevapi.c:148
void IUFillSwitch(ISwitch *sp, const char *name, const char *label, ISState s)
Assign attributes for a switch property. The switch's auxiliary elements will be set to NULL.
Definition: indidevapi.c:158
void IUFillSwitchVector(ISwitchVectorProperty *svp, ISwitch *sp, int nsp, const char *dev, const char *name, const char *label, const char *group, IPerm p, ISRule r, double timeout, IPState s)
Assign attributes for a switch vector property. The vector's auxiliary elements will be set to NULL.
Definition: indidevapi.c:235
#define INDI_UNUSED(x)
Definition: indidevapi.h:131
int IUUpdateSwitch(ISwitchVectorProperty *svp, ISState *states, char *names[], int n)
Update all switches in a switch vector property.
Definition: indidriver.c:1308
void IDSetSwitch(const ISwitchVectorProperty *svp, const char *fmt,...)
Definition: indidriver.c:1231
Namespace to encapsulate INDI client, drivers, and mediator classes.
char name[MAXINDINAME]
Definition: indiapi.h:371