Kstars

indidustcap.cpp
1 /*
2  SPDX-FileCopyrightText: 2015 Jasem Mutlaq <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include <basedevice.h>
8 #include <KLocalizedString>
9 #include <QtDBus/qdbusmetatype.h>
10 
11 #include "indidustcap.h"
12 #include "dustcapadaptor.h"
13 
14 namespace ISD
15 {
16 
17 const QList<const char *> DustCap::capStates = { I18N_NOOP("Idle"), I18N_NOOP("Parking"), I18N_NOOP("UnParking"),
18  I18N_NOOP("Parked"), I18N_NOOP("Error")
19  };
20 
21 DustCap::DustCap(GenericDevice *parent): ConcreteDevice(parent)
22 {
23  qRegisterMetaType<ISD::DustCap::Status>("ISD::DustCap::Status");
24  qDBusRegisterMetaType<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 
31 void DustCap::processSwitch(ISwitchVectorProperty *svp)
32 {
33  if (!strcmp(svp->name, "CAP_PARK"))
34  {
35  Status currentStatus = CAP_ERROR;
36  ParkStatus currentParkStatus = PARK_UNKNOWN;
37 
38  switch (svp->s)
39  {
40  case IPS_IDLE:
41  if (svp->sp[0].s == ISS_ON)
42  {
43  currentStatus = CAP_PARKED;
44  currentParkStatus = PARK_PARKED;
45  }
46  else if (svp->sp[1].s == ISS_ON)
47  {
48  currentStatus = CAP_IDLE;
49  currentParkStatus = PARK_UNPARKED;
50  }
51  break;
52 
53  case IPS_OK:
54  if (svp->sp[0].s == 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->sp[0].s == 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 
100 bool DustCap::canPark()
101 {
102  auto parkSP = getSwitch("CAP_PARK");
103  if (!parkSP)
104  return false;
105  else
106  return true;
107 }
108 
109 bool 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 
118 bool 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 
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  sendNewSwitch(parkSP);
140 
141  return true;
142 }
143 
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  sendNewSwitch(parkSP);
157 
158  return true;
159 }
160 
161 const QString DustCap::getStatusString(DustCap::Status status, bool translated)
162 {
163  return translated ? i18n(capStates[status]) : capStates[status];
164 }
165 
166 }
167 
168 QDBusArgument &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 
176 const 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 }
Q_SCRIPTABLE bool park()
Park Close dust cap.
INDI::PropertyView< ISwitch > * getSwitch(const QString &name) const
KCALENDARCORE_EXPORT QDataStream & operator>>(QDataStream &in, const KCalendarCore::Alarm::Ptr &)
bool registerObject(const QString &path, QObject *object, QDBusConnection::RegisterOptions options)
QString i18n(const char *text, const TYPE &arg...)
QDBusConnection sessionBus()
void sendNewSwitch(ISwitchVectorProperty *pp)
Send new Switch command to server.
Q_SCRIPTABLE bool unpark()
UnPark Open dust cap.
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QDebug operator<<(QDebug d, const QCPVector2D &vec)
Definition: qcustomplot.h:446
void beginStructure()
void endStructure()
#define I18N_NOOP(text)
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Oct 6 2022 04:14:03 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.