File indexing completed on 2024-07-21 06:28:22

0001 /*
0002     SPDX-FileCopyrightText: 2015 Jasem Mutlaq <mutlaqja@ikarustech.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <memory>
0010 #include <QTimer>
0011 
0012 #include "indiconcretedevice.h"
0013 
0014 namespace ISD
0015 {
0016 /**
0017  * @class DustCap
0018  * Handles operation of a remotely controlled dust cover cap.
0019  *
0020  * @author Jasem Mutlaq
0021  */
0022 class DustCap : public ConcreteDevice
0023 {
0024         Q_OBJECT
0025         Q_CLASSINFO("D-Bus Interface", "org.kde.kstars.INDI.DustCap")
0026         Q_PROPERTY(ISD::DustCap::Status status READ status NOTIFY newStatus)
0027         Q_PROPERTY(ISD::ParkStatus parkStatus READ parkStatus NOTIFY newParkStatus)
0028         Q_PROPERTY(bool canPark READ canPark)
0029 
0030     public:
0031         explicit DustCap(GenericDevice *parent);
0032         virtual ~DustCap() override = default;
0033         typedef enum
0034         {
0035             CAP_IDLE,
0036             CAP_PARKING,
0037             CAP_UNPARKING,
0038             CAP_PARKED,
0039             CAP_ERROR
0040         } Status;
0041 
0042         virtual void processSwitch(INDI::Property prop) override;
0043 
0044         Q_SCRIPTABLE virtual bool canPark();        
0045         // Check if cap is fully parked.
0046         Q_SCRIPTABLE virtual bool isParked();
0047         // Check if cap is fully unparked. We need this because we have parking and unparking in progress
0048         Q_SCRIPTABLE virtual bool isUnParked();
0049 
0050         static const QString getStatusString(Status status, bool translated = true);
0051 
0052     public slots:
0053         /**
0054          * @brief Park Close dust cap
0055          * @return True if operation is successful, false otherwise.
0056          */
0057         Q_SCRIPTABLE bool park();
0058 
0059         /**
0060          * @brief UnPark Open dust cap
0061          * @return True if operation is successful, false otherwise.
0062          */
0063         Q_SCRIPTABLE bool unpark();
0064 
0065         Q_SCRIPTABLE Status status()
0066         {
0067             return m_Status;
0068         }
0069         ISD::ParkStatus parkStatus() const
0070         {
0071             return m_ParkStatus;
0072         }
0073 
0074     signals:
0075         void newStatus(ISD::DustCap::Status status);
0076         void newParkStatus(ISD::ParkStatus status);
0077 
0078     private:
0079         Status m_Status { CAP_IDLE };
0080         ParkStatus m_ParkStatus { PARK_UNKNOWN };
0081         static const QList<const char *> capStates;
0082 };
0083 
0084 }
0085 
0086 Q_DECLARE_METATYPE(ISD::DustCap::Status)
0087 QDBusArgument &operator<<(QDBusArgument &argument, const ISD::DustCap::Status &source);
0088 const QDBusArgument &operator>>(const QDBusArgument &argument, ISD::DustCap::Status &dest);