File indexing completed on 2024-04-28 03:43:41

0001 /*  Ekos Observatory Module
0002     SPDX-FileCopyrightText: Wolfgang Reissenberger <sterne-jaeger@t-online.de>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "observatorydomemodel.h"
0008 #include <KLocalizedString>
0009 
0010 namespace Ekos
0011 {
0012 
0013 void ObservatoryDomeModel::initModel(Dome *dome)
0014 {
0015     domeInterface = dome;
0016 
0017     connect(domeInterface, &Dome::ready, this, [&]()
0018     {
0019         initialized = true;
0020         emit ready();
0021     });
0022     connect(domeInterface, &Dome::disconnected, this, [&]()
0023     {
0024         emit disconnected();
0025         initialized = false;
0026     });
0027     connect(domeInterface, &Dome::newStatus, this, &ObservatoryDomeModel::newStatus);
0028     connect(domeInterface, &Dome::newParkStatus, this, &ObservatoryDomeModel::newParkStatus);
0029     connect(domeInterface, &Dome::newShutterStatus, this, &ObservatoryDomeModel::newShutterStatus);
0030     connect(domeInterface, &Dome::azimuthPositionChanged, this, &ObservatoryDomeModel::azimuthPositionChanged);
0031     connect(domeInterface, &Dome::newAutoSyncStatus, this, &ObservatoryDomeModel::newAutoSyncStatus);
0032 
0033     initialized = true;
0034 }
0035 
0036 ISD::Dome::Status ObservatoryDomeModel::status()
0037 {
0038     if (domeInterface == nullptr)
0039         return ISD::Dome::DOME_IDLE;
0040 
0041     return domeInterface->status();
0042 }
0043 
0044 ISD::Dome::ShutterStatus ObservatoryDomeModel::shutterStatus()
0045 {
0046     if (domeInterface == nullptr)
0047         return ISD::Dome::SHUTTER_UNKNOWN;
0048 
0049     return domeInterface->shutterStatus();
0050 }
0051 
0052 void ObservatoryDomeModel::park()
0053 {
0054     if (domeInterface == nullptr)
0055         return;
0056 
0057     emit newLog(i18n("Parking %1...", isRolloffRoof() ? i18n("rolloff roof") : i18n("dome")));
0058     domeInterface->park();
0059 }
0060 
0061 
0062 void ObservatoryDomeModel::unpark()
0063 {
0064     if (domeInterface == nullptr)
0065         return;
0066 
0067     emit newLog(i18n("Unparking %1...", isRolloffRoof() ? i18n("rolloff roof") : i18n("dome")));
0068     domeInterface->unpark();
0069 }
0070 
0071 ISD::ParkStatus ObservatoryDomeModel::parkStatus()
0072 {
0073     if (domeInterface == nullptr)
0074         return ISD::PARK_UNKNOWN;
0075     else if (isRolloffRoof())
0076     {
0077         // we need to override the parking status of the dome interface for opening and closing rolloff roofs
0078         if (domeInterface->status() == ISD::Dome::DOME_MOVING_CW)
0079             return ISD::PARK_UNPARKING;
0080         else if (domeInterface->status() == ISD::Dome::DOME_MOVING_CCW)
0081             return ISD::PARK_PARKING;
0082     }
0083 
0084     // in all other cases use the underlying park status
0085     return domeInterface->parkStatus();
0086 }
0087 
0088 void ObservatoryDomeModel::setAutoSync(bool activate)
0089 {
0090     if (domeInterface == nullptr)
0091         return;
0092 
0093     if (domeInterface->setAutoSync(activate))
0094         emit newLog(activate ? i18n("Slaving activated.") : i18n("Slaving deactivated."));
0095 
0096 }
0097 
0098 void ObservatoryDomeModel::abort()
0099 {
0100     if (domeInterface == nullptr)
0101         return;
0102 
0103     emit newLog(i18n("Aborting..."));
0104     domeInterface->abort();
0105 }
0106 
0107 void ObservatoryDomeModel::openShutter()
0108 {
0109     if (domeInterface == nullptr)
0110         return;
0111 
0112     emit newLog(i18n("Opening shutter..."));
0113     domeInterface->controlShutter(true);
0114 }
0115 
0116 void ObservatoryDomeModel::closeShutter()
0117 {
0118     if (domeInterface == nullptr)
0119         return;
0120 
0121     emit newLog(i18n("Closing shutter..."));
0122     domeInterface->controlShutter(false);
0123 }
0124 
0125 bool ObservatoryDomeModel::moveDome(bool moveCW, bool start)
0126 {
0127     if (domeInterface == nullptr)
0128         return false;
0129 
0130     if (isRolloffRoof())
0131         emit newLog(i18nc("%2 dome or rolloff roof motion %1...", "%2 rolloff roof %1...",
0132                           moveCW ? i18n("opening") : i18n("closing"), start ? i18n("Start") : i18n("Stop")));
0133     else
0134         emit newLog(i18nc("%2 dome or rolloff roof motion %1...", "%2 dome motion %1...",
0135                           moveCW ? i18n("clockwise") : i18n("counter clockwise"), start ? i18n("Start") : i18n("Stop")));
0136     return domeInterface->moveDome(moveCW, start);
0137 }
0138 
0139 void ObservatoryDomeModel::execute(WeatherActions actions)
0140 {
0141     if (hasShutter() && actions.closeShutter)
0142         closeShutter();
0143     if (actions.parkDome)
0144         park();
0145 }
0146 
0147 }