Kstars

indidustcap.cpp
1/*
2 SPDX-FileCopyrightText: 2015 Jasem Mutlaq <mutlaqja@ikarustech.com>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include <basedevice.h>
8#include <KLocalizedString>
9#include <qdbusmetatype.h>
10
11#include "indidustcap.h"
12#include "dustcapadaptor.h"
13
14namespace ISD
15{
16
17const QList<const char *> DustCap::capStates = { I18N_NOOP("Idle"), I18N_NOOP("Parking"), I18N_NOOP("UnParking"),
18 I18N_NOOP("Parked"), I18N_NOOP("Error")
19 };
20
21DustCap::DustCap(GenericDevice *parent): ConcreteDevice(parent)
22{
23 qRegisterMetaType<ISD::DustCap::Status>("ISD::DustCap::Status");
25
26 new DustCapAdaptor(this);
27 m_DBusObjectPath = QString("/KStars/INDI/DustCap/%1").arg(getID());
28 QDBusConnection::sessionBus().registerObject(m_DBusObjectPath, this);
29}
30
31void DustCap::processSwitch(INDI::Property prop)
32{
33 auto svp = prop.getSwitch();
34 if (svp->isNameMatch("CAP_PARK"))
35 {
36 Status currentStatus = CAP_ERROR;
37 ParkStatus currentParkStatus = PARK_UNKNOWN;
38
39 switch (svp->getState())
40 {
41 case IPS_IDLE:
42 if (svp->at(0)->getState() == ISS_ON)
43 {
44 currentStatus = CAP_PARKED;
45 currentParkStatus = PARK_PARKED;
46 }
47 else if (svp->at(1)->getState() == ISS_ON)
48 {
49 currentStatus = CAP_IDLE;
50 currentParkStatus = PARK_UNPARKED;
51 }
52 break;
53
54 case IPS_OK:
55 if (svp->at(0)->getState() == ISS_ON)
56 {
57 currentStatus = CAP_PARKED;
58 currentParkStatus = PARK_PARKED;
59 }
60 else
61 {
62 currentStatus = CAP_IDLE;
63 currentParkStatus = PARK_UNPARKED;
64 }
65 break;
66
67 case IPS_BUSY:
68 if (svp->at(0)->getState() == ISS_ON)
69 {
70 currentStatus = CAP_PARKING;
71 currentParkStatus = PARK_PARKING;
72 }
73 else
74 {
75 currentStatus = CAP_UNPARKING;
76 currentParkStatus = PARK_UNPARKING;
77 }
78 break;
79
80 case IPS_ALERT:
81 currentStatus = CAP_ERROR;
82 currentParkStatus = PARK_ERROR;
83 }
84
85 if (currentStatus != m_Status)
86 {
87 m_Status = currentStatus;
88 emit newStatus(m_Status);
89 }
90
91 if (currentParkStatus != m_ParkStatus)
92 {
93 m_ParkStatus = currentParkStatus;
94 emit newParkStatus(m_ParkStatus);
95 }
96
97
98 }
99}
100
101bool DustCap::canPark()
102{
103 auto parkSP = getSwitch("CAP_PARK");
104 if (!parkSP)
105 return false;
106 else
107 return true;
108}
109
110bool DustCap::isParked()
111{
112 auto parkSP = getSwitch("CAP_PARK");
113 if (!parkSP)
114 return false;
115
116 return ((parkSP->getState() == IPS_OK || parkSP->getState() == IPS_IDLE) && parkSP->at(0)->getState() == ISS_ON);
117}
118
119bool DustCap::isUnParked()
120{
121 auto parkSP = getSwitch("CAP_PARK");
122 if (!parkSP)
123 return false;
124
125 return ( (parkSP->getState() == IPS_OK || parkSP->getState() == IPS_IDLE) && parkSP->at(1)->getState() == ISS_ON);
126}
127
128bool DustCap::park()
129{
130 auto parkSP = getSwitch("CAP_PARK");
131 if (!parkSP)
132 return false;
133
134 auto parkSW = parkSP->findWidgetByName("PARK");
135 if (!parkSW)
136 return false;
137
138 parkSP->reset();
139 parkSW->setState(ISS_ON);
140 sendNewProperty(parkSP);
141
142 return true;
143}
144
145bool DustCap::unpark()
146{
147 auto parkSP = getSwitch("CAP_PARK");
148 if (!parkSP)
149 return false;
150
151 auto parkSW = parkSP->findWidgetByName("UNPARK");
152 if (!parkSW)
153 return false;
154
155 parkSP->reset();
156 parkSW->setState(ISS_ON);
157 sendNewProperty(parkSP);
158
159 return true;
160}
161
162const QString DustCap::getStatusString(DustCap::Status status, bool translated)
163{
164 return translated ? i18n(capStates[status]) : capStates[status];
165}
166
167}
168
169QDBusArgument &operator<<(QDBusArgument &argument, const ISD::DustCap::Status &source)
170{
171 argument.beginStructure();
173 argument.endStructure();
174 return argument;
175}
176
177const QDBusArgument &operator>>(const QDBusArgument &argument, ISD::DustCap::Status &dest)
178{
179 int a;
180 argument.beginStructure();
181 argument >> a;
182 argument.endStructure();
183 dest = static_cast<ISD::DustCap::Status>(a);
184 return argument;
185}
QString i18n(const char *text, const TYPE &arg...)
ISD is a collection of INDI Standard Devices.
KCALENDARCORE_EXPORT QDataStream & operator>>(QDataStream &in, const KCalendarCore::Alarm::Ptr &)
bool registerObject(const QString &path, QObject *object, RegisterOptions options)
QDBusConnection sessionBus()
QString arg(Args &&... args) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:19:03 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.