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

KDE's Doxygen guidelines are available online.