Instrument Neutral Distributed Interface INDI  1.9.5
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 }
MAXINDIDEVICE
#define MAXINDIDEVICE
Definition: indiapi.h:192
INDI::DustCapInterface::CAP_PARK
@ CAP_PARK
Definition: indidustcapinterface.h:42
IPState
IPState
Property state.
Definition: indiapi.h:158
ISS_OFF
@ ISS_OFF
Definition: indiapi.h:150
INDI::DustCapInterface::UnParkCap
virtual IPState UnParkCap()
unPark dust cap (open cover). Must be implemented by child.
Definition: indidustcapinterface.cpp:72
IPS_ALERT
@ IPS_ALERT
Definition: indiapi.h:163
INDI_UNUSED
#define INDI_UNUSED(x)
Definition: indidevapi.h:799
INDI::DustCapInterface::ParkCapSP
ISwitchVectorProperty ParkCapSP
Definition: indidustcapinterface.h:72
IUResetSwitch
void IUResetSwitch(ISwitchVectorProperty *svp)
Reset all switches in a switch vector property to OFF.
Definition: indicom.c:1442
INDI::DustCapInterface::initDustCapProperties
void initDustCapProperties(const char *deviceName, const char *groupName)
Initilize dust cap properties. It is recommended to call this function within initProperties() of you...
Definition: indidustcapinterface.cpp:28
IUFillSwitchVector
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: indidriver.c:412
ISR_1OFMANY
@ ISR_1OFMANY
Definition: indiapi.h:172
IPS_IDLE
@ IPS_IDLE
Definition: indiapi.h:160
IUUpdateSwitch
int IUUpdateSwitch(ISwitchVectorProperty *svp, ISState *states, char *names[], int n)
Update all switches in a switch vector property.
Definition: indidriver.c:171
INDI::DustCapInterface::ParkCapS
ISwitch ParkCapS[2]
Definition: indidustcapinterface.h:73
INDI::DustCapInterface::CAP_UNPARK
@ CAP_UNPARK
Definition: indidustcapinterface.h:43
name
const char * name
Definition: indiserver.c:116
indidustcapinterface.h
_ISwitchVectorProperty::s
IPState s
Definition: indiapi.h:382
INDI::DustCapInterface::ParkCap
virtual IPState ParkCap()
Park dust cap (close cover). Must be implemented by child.
Definition: indidustcapinterface.cpp:66
INDI
Namespace to encapsulate INDI client, drivers, and mediator classes.
Definition: AlignmentSubsystemForClients.cpp:11
INDI::DustCapInterface::processDustCapSwitch
bool processDustCapSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Process dust cap switch properties.
Definition: indidustcapinterface.cpp:39
IP_RW
@ IP_RW
Definition: indiapi.h:185
ISState
ISState
Switch state.
Definition: indiapi.h:148
IUFindOnSwitchIndex
int IUFindOnSwitchIndex(const ISwitchVectorProperty *sp)
Returns the index of first ON switch it finds in the vector switch property.
Definition: indicom.c:1424
IDSetSwitch
void void void void void IDSetSwitch(const ISwitchVectorProperty *s, const char *msg,...) ATTRIBUTE_FORMAT_PRINTF(2
Tell client to update an existing switch vector property.
IUFillSwitch
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: indidriver.c:320
_ISwitchVectorProperty::name
char name[MAXINDINAME]
Definition: indiapi.h:370
ISS_ON
@ ISS_ON
Definition: indiapi.h:151