Instrument Neutral Distributed Interface INDI 2.2.5
indidustcapinterface.cpp
Go to the documentation of this file.
1/*
2 Dust Cap Interface
3 Copyright (C) 2015-2025 Jasem Mutlaq ([email protected])
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
22#include "defaultdevice.h"
23
24#include <cstring>
25
26namespace INDI
27{
28
35DustCapInterface::DustCapInterface(DefaultDevice *defaultDevice) : m_DefaultDevice(defaultDevice)
36{
37}
38
42void DustCapInterface::initProperties(const char *group, uint32_t capabilities)
43{
44 m_Capabilities = capabilities;
45
46 // Open/Close cover
47 ParkCapSP[CAP_PARK].fill("PARK", "Park", ISS_OFF);
48 ParkCapSP[CAP_UNPARK].fill("UNPARK", "Unpark", ISS_OFF);
49 ParkCapSP.fill(m_DefaultDevice->getDeviceName(), "CAP_PARK", "Dust Cover", group, IP_RW, ISR_1OFMANY, 0, IPS_IDLE);
50
51 // Abort motion
52 AbortCapSP[0].fill("ABORT", "Abort", ISS_OFF);
53 AbortCapSP.fill(m_DefaultDevice->getDeviceName(), "CAP_ABORT", "Motion", group, IP_RW, ISR_ATMOST1, 60, IPS_IDLE);
54}
55
60{
61 if (m_DefaultDevice->isConnected())
62 {
63 m_DefaultDevice->defineProperty(ParkCapSP);
64 if (m_Capabilities & CAN_ABORT)
65 m_DefaultDevice->defineProperty(AbortCapSP);
66 }
67 else
68 {
69 m_DefaultDevice->deleteProperty(ParkCapSP);
70 if (m_Capabilities & CAN_ABORT)
71 m_DefaultDevice->deleteProperty(AbortCapSP);
72 }
73
74 return true;
75}
76
80bool DustCapInterface::processSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
81{
82 INDI_UNUSED(dev);
83 // Park/UnPark Dust Cover
84 if (ParkCapSP.isNameMatch(name))
85 {
86 auto prevSwitch = ParkCapSP.findOnSwitchIndex();
87 ParkCapSP.update(states, names, n);
88 ParkCapSP.setState((ParkCapSP[CAP_PARK].getState() == ISS_ON) ? ParkCap() : UnParkCap());
89
90 if (ParkCapSP.getState() == IPS_ALERT)
91 {
92 ParkCapSP.reset();
93 ParkCapSP[prevSwitch].setState(ISS_ON);
94 }
95 ParkCapSP.apply();
96 return true;
97 }
98 else if (AbortCapSP.isNameMatch(name))
99 {
100 auto state = AbortCap();
101 AbortCapSP.setState(state);
102 AbortCapSP.apply();
103 // In case cap was in motion, and was aborted, we update its state to ABORT
104 // We reset all switches as well.
105 if (state == IPS_OK && ParkCapSP.getState() == IPS_BUSY)
106 {
107 ParkCapSP.reset();
108 ParkCapSP.setState(IPS_ALERT);
109 ParkCapSP.apply();
110 }
111 return true;
112 }
113
114 return false;
115}
116
118{
119 // Must be implemented by child class
120 return IPS_ALERT;
121}
122
124{
125 // Must be implemented by child class
126 return IPS_ALERT;
127}
128
130{
131 // Must be implemented by child class
132 return IPS_ALERT;
133}
134}
Class to provide extended functionality for devices in addition to the functionality provided by INDI...
virtual IPState ParkCap()
Park dust cap (close cover). Must be implemented by child.
DustCapInterface(DefaultDevice *device)
INDI::PropertySwitch ParkCapSP
virtual IPState AbortCap()
Abort motion. Must be implemented by child.
virtual IPState UnParkCap()
unPark dust cap (open cover). Must be implemented by child.
bool updateProperties()
updateProperties Defines or Delete properties based on default device connection status
INDI::PropertySwitch AbortCapSP
void initProperties(const char *group, uint32_t capabilities=0)
Initialize dust cap properties. It is recommended to call this function within initProperties() of yo...
bool processSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Process dust cap switch properties.
ISState
Switch state.
Definition indiapi.h:148
@ ISS_OFF
Definition indiapi.h:149
@ ISS_ON
Definition indiapi.h:150
@ IP_RW
Definition indiapi.h:184
IPState
Property state.
Definition indiapi.h:158
@ IPS_BUSY
Definition indiapi.h:161
@ IPS_ALERT
Definition indiapi.h:162
@ IPS_IDLE
Definition indiapi.h:159
@ IPS_OK
Definition indiapi.h:160
@ ISR_1OFMANY
Definition indiapi.h:171
@ ISR_ATMOST1
Definition indiapi.h:172
#define INDI_UNUSED(x)
Definition indidevapi.h:132
*brief user defined string literal for JSON values *sa std::size_t n
Namespace to encapsulate INDI client, drivers, and mediator classes.