File indexing completed on 2024-07-07 07:08:33

0001 /*
0002     SPDX-FileCopyrightText: 2012 Jasem Mutlaq <mutlaqja@ikarustech.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "basedevice.h"
0010 #include "skypoint.h"
0011 #include "kstarslite/skypointlite.h"
0012 #include "kstarslite/skyobjectlite.h"
0013 
0014 #include <QObject>
0015 
0016 class ClientManagerLite;
0017 
0018 /**
0019  * @class TelescopeLite
0020  *
0021  * device handle controlling telescope. It can slew and sync to a specific sky point and supports all standard properties with INDI
0022  * telescope device.
0023  *
0024  * @author Jasem Mutlaq
0025  */
0026 class TelescopeLite : public QObject
0027 {
0028     Q_OBJECT
0029 
0030     Q_PROPERTY(bool slewDecreasable READ isSlewDecreasable WRITE setSlewDecreasable NOTIFY slewDecreasableChanged)
0031     Q_PROPERTY(bool slewIncreasable READ isSlewIncreasable WRITE setSlewIncreasable NOTIFY slewIncreasableChanged)
0032     Q_PROPERTY(QString slewRateLabel READ getSlewRateLabel WRITE setSlewRateLabel NOTIFY slewRateLabelChanged)
0033     Q_PROPERTY(QString deviceName READ getDeviceName WRITE setDeviceName NOTIFY deviceNameChanged)
0034 
0035   public:
0036     explicit TelescopeLite(INDI::BaseDevice *device);
0037     TelescopeLite() { }
0038     ~TelescopeLite();
0039 
0040     enum TelescopeMotionNS
0041     {
0042         MOTION_NORTH,
0043         MOTION_SOUTH
0044     };
0045     enum TelescopeMotionWE
0046     {
0047         MOTION_WEST,
0048         MOTION_EAST
0049     };
0050     enum TelescopeMotionCommand
0051     {
0052         MOTION_START,
0053         MOTION_STOP
0054     };
0055 
0056     Q_ENUMS(TelescopeMotionNS)
0057     Q_ENUMS(TelescopeMotionWE)
0058     Q_ENUMS(TelescopeMotionCommand)
0059 
0060     void registerProperty(INDI::Property prop);
0061     void processSwitch(ISwitchVectorProperty *svp);
0062     void processText(ITextVectorProperty *tvp);
0063     void processNumber(INumberVectorProperty *nvp);
0064 
0065     INDI::BaseDevice *getDevice() { return baseDevice; }
0066     //deviceName
0067     QString getDeviceName() { return m_deviceName; }
0068     void setDeviceName(const QString &deviceName);
0069 
0070     bool isSlewDecreasable() { return m_slewDecreasable; }
0071     bool isSlewIncreasable() { return m_slewIncreasable; }
0072 
0073     QString getSlewRateLabel() { return m_slewRateLabel; }
0074 
0075     void setSlewDecreasable(bool slewDecreasable);
0076     void setSlewIncreasable(bool slewIncreasable);
0077 
0078     void setSlewRateLabel(const QString &slewRateLabel);
0079 
0080     Q_INVOKABLE bool decreaseSlewRate();
0081     Q_INVOKABLE bool increaseSlewRate();
0082 
0083     // Common Commands
0084     Q_INVOKABLE bool slew(SkyPointLite *ScopeTarget) { return slew(ScopeTarget->getPoint()); }
0085     Q_INVOKABLE bool slew(SkyPoint *ScopeTarget);
0086     bool slew(double ra, double dec);
0087     Q_INVOKABLE bool sync(SkyPointLite *ScopeTarget) { return sync(ScopeTarget->getPoint()); }
0088     Q_INVOKABLE bool sync(SkyPoint *ScopeTarget);
0089     bool sync(double ra, double dec);
0090     Q_INVOKABLE bool moveNS(TelescopeMotionNS dir, TelescopeMotionCommand cmd);
0091     Q_INVOKABLE bool moveWE(TelescopeMotionWE dir, TelescopeMotionCommand cmd);
0092     bool canGuide();
0093     bool canSync();
0094     bool canPark();
0095     bool isSlewing();
0096     bool isParked();
0097     bool isInMotion();
0098     /*bool doPulse(GuideDirection ra_dir, int ra_msecs, GuideDirection dec_dir, int dec_msecs );
0099         bool doPulse(GuideDirection dir, int msecs );*/
0100     bool getEqCoords(double *ra, double *dec);
0101     void setAltLimits(double minAltitude, double maxAltitude);
0102     Q_INVOKABLE bool isConnected() { return baseDevice->isConnected(); }
0103     Q_INVOKABLE QStringList getSlewRateLabels() { return m_slewRateLabels; };
0104 
0105   protected:
0106     bool sendCoords(SkyPoint *ScopeTarget);
0107 
0108   public slots:
0109     Q_INVOKABLE bool abort();
0110     bool park();
0111     bool unPark();
0112     bool setSlewRate(int index);
0113     void updateSlewRate(const QString &deviceName, const QString &propName);
0114 
0115   signals:
0116     void slewDecreasableChanged(bool);
0117     void slewIncreasableChanged(bool);
0118     void slewRateLabelChanged(QString);
0119     void deviceNameChanged(QString);
0120     void newTelescopeLiteCreated(TelescopeLite *);
0121     void slewRateUpdate(int index, int count);
0122 
0123   private:
0124     SkyPoint currentCoord;
0125     double minAlt { 0 };
0126     double maxAlt { 0 };
0127     bool IsParked { false };
0128     ClientManagerLite *clientManager { nullptr };
0129     INDI::BaseDevice *baseDevice { nullptr };
0130     int slewRateIndex { 0 };
0131     QString m_deviceName;
0132     bool m_slewDecreasable { false };
0133     bool m_slewIncreasable { false };
0134     QString m_slewRateLabel;
0135     QStringList m_slewRateLabels;
0136 };