Kstars

focusmodule.h
1/*
2 SPDX-FileCopyrightText: 2012 Jasem Mutlaq <mutlaqja@ikarustech.com>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "ui_focusmodule.h"
10#include "focus.h"
11
12
13namespace Ekos
14{
15
16
17class FocusModule : public QWidget, public Ui::FocusManager
18{
20 Q_CLASSINFO("D-Bus Interface", "org.kde.kstars.Ekos.Focus")
21
22public:
23 FocusModule();
24 ~FocusModule();
25
26 // ////////////////////////////////////////////////////////////////////
27 // Access to the focusers
28 // ////////////////////////////////////////////////////////////////////
29
30 QSharedPointer<Focus> &focuser(int i);
31
32 QSharedPointer<Focus> mainFocuser();
33
34 /**
35 * @brief find the focuser using the given train
36 * @param train optical train name
37 * @param addIfNecessary if true, add a new camera with the given train, if none uses this train
38 * @return index in the list of focusers (@see #camera(int))
39 */
40 int findFocuser(const QString &trainname, bool addIfNecessary);
41
42 /**
43 * @brief showOptions Open the options dialog for the currently selected focuser
44 */
45 void showOptions();
46
47 /**
48 * @brief Run the autofocus process for the currently selected filter
49 * @param The reason Autofocus has been called.
50 * @param trainname name of the optical train to select the focuser
51 */
52 void runAutoFocus(const AutofocusReason autofocusReason, const QString &reasonInfo, const QString &trainname);
53
54 /**
55 * @brief Reset the camera frame being used by the focuser.
56 * @param trainname name of the optical train to select the focuser
57 */
58 void resetFrame(const QString &trainname);
59
60 /**
61 * @brief Abort the autofocus operation.
62 * @param trainname name of the optical train to select the focuser
63 */
64 void abort(const QString &trainname);
65
66 /**
67 * @brief adaptiveFocus moves the focuser between subframes to stay at focus
68 * @param trainname name of the optical train to select the focuser
69 */
70 void adaptiveFocus(const QString &trainname);
71
72 /**
73 * @brief React when a meridian flip has been started
74 * @param trainname name of the optical train to select the focuser
75 */
76 void meridianFlipStarted(const QString &trainname);
77
78 // Update Mount module status
79 void setMountStatus(ISD::Mount::Status newState);
80
81 // Update Altitude From Mount
82 void setMountCoords(const SkyPoint &position, ISD::Mount::PierSide pierSide, const dms &ha);
83
84 // ////////////////////////////////////////////////////////////////////
85 // DBus interface
86 // ////////////////////////////////////////////////////////////////////
87 /** DBUS interface function.
88 * Retrieve the status from the focuser of the given optical train.
89 */
90 Q_SCRIPTABLE Ekos::FocusState status(const QString &trainname);
91
92 /** DBUS interface function.
93 * Retrieve the CCD device from the focuser of the given optical train.
94 */
95 Q_SCRIPTABLE QString camera(const QString &trainname);
96
97 /** DBUS interface function.
98 * Retrieve the focuser device name from the focuser of the given optical train.
99 */
100 Q_SCRIPTABLE QString focuser(const QString &trainname);
101
102 /** DBUS interface function.
103 * Retrieve the filter wheel device name from the focuser of the given optical train.
104 */
105 Q_SCRIPTABLE QString filterWheel(const QString &trainname);
106
107 /** DBUS interface function.
108 * select the filter from the available filters.
109 * @return Returns true if filter is found and set, false otherwise.
110 */
111 Q_SCRIPTABLE bool setFilter(const QString &filter, const QString &trainname);
112 Q_SCRIPTABLE QString filter(const QString &trainname);
113
114 /** DBUS interface function.
115 * @return Returns Half-Flux-Radius in pixels from the focuser of the given optical train..
116 */
117 Q_SCRIPTABLE double getHFR(const QString &trainname);
118
119 /** DBUS interface function.
120 * Set CCD exposure value for the focuser of the given optical train.
121 */
122 Q_SCRIPTABLE bool setExposure(double value, const QString &trainname);
123 Q_SCRIPTABLE double exposure(const QString &trainname);
124
125 /** DBUS interface function.
126 * @return Returns True if the focuser of the given optical train supports auto-focusing
127 */
128 Q_SCRIPTABLE bool canAutoFocus(const QString &trainname);
129
130 /** DBUS interface function.
131 * @return Returns True if the focuser of the given optical train uses the full field for focusing
132 */
133 Q_SCRIPTABLE bool useFullField(const QString &trainname);
134
135 /** DBUS interface function.
136 * Set CCD binning for the focuser of the given optical train.
137 */
138 Q_SCRIPTABLE bool setBinning(int binX, int binY, const QString &trainname);
139
140 /** DBUS interface function.
141 * Set Auto Focus options for the focuser of the given optical train. The options must be set before starting
142 * the autofocus operation. If no options are set, the options loaded from the user configuration are used.
143 * @param enable If true, Ekos will attempt to automatically select the best focus star in the frame.
144 * If it fails to select a star, the user will be asked to select a star manually.
145 */
146 Q_SCRIPTABLE bool setAutoStarEnabled(bool enable, const QString &trainname);
147
148 /** DBUS interface function.
149 * Set Auto Focus options for the focuser of the given optical train. The options must be set before
150 * starting the autofocus operation. If no options are set, the options loaded from the user configuration are used.
151 * @param enable if true, Ekos will capture a subframe around the selected focus star.
152 * The subframe size is determined by the boxSize parameter.
153 */
154 Q_SCRIPTABLE bool setAutoSubFrameEnabled(bool enable, const QString &trainname);
155
156 /** DBUS interface function.
157 * Set Autofocus parameters for the focuser of the given optical train.
158 * @param boxSize the box size around the focus star in pixels. The boxsize is used to subframe around the focus star.
159 * @param stepSize the initial step size to be commanded to the focuser. If the focuser is absolute, the step size is in ticks. For relative focusers, the focuser will be commanded to focus inward for stepSize milliseconds initially.
160 * @param maxTravel the maximum steps permitted before the autofocus operation aborts.
161 * @param tolerance Measure of how accurate the autofocus algorithm is. If the difference between the current HFR and minimum measured HFR is less than %tolerance after the focuser traversed both ends of the V-curve, then the focusing operation
162 * is deemed successful. Otherwise, the focusing operation will continue.
163 */
164 Q_SCRIPTABLE bool setAutoFocusParameters(const QString &trainname, int boxSize, int stepSize, int maxTravel, double tolerance);
165
166 // ////////////////////////////////////////////////////////////////////
167 // Device handling
168 // ////////////////////////////////////////////////////////////////////
169 /**
170 * @brief removeDevice Remove device from Focus module
171 * @param deviceRemoved pointer to device
172 */
173 void removeDevice(const QSharedPointer<ISD::GenericDevice> &deviceRemoved);
174
175 /**
176 * @brief addTemperatureSource Add temperature source to the list of available sources.
177 * @param newSource Device with temperature reporting capability
178 * @return True if added successfully, false if duplicate or failed to add.
179 */
180 bool addTemperatureSource(const QSharedPointer<ISD::GenericDevice> &device);
181
182 /**
183 * @brief syncCameraInfo Read current CCD information and update settings accordingly.
184 */
185 void syncCameraInfo(const char *devicename);
186
187 /**
188 * @brief Check all focusers and make sure information is updated accordingly.
189 */
190 void checkFocusers()
191 {
192 // iterate over all focusers
193 for (auto focuser : m_Focusers)
194 focuser->checkFocuser();
195 }
196
197 /**
198 * @brief Check all CCDs and make sure information is updated accordingly.
199 */
200 void checkCameras()
201 {
202 // iterate over all focusers
203 for (auto focuser : m_Focusers)
204 focuser->checkCamera();
205 }
206
207
208 // ////////////////////////////////////////////////////////////////////
209 // Module logging
210 // ////////////////////////////////////////////////////////////////////
211 Q_INVOKABLE void clearLog();
212 void appendLogText(const QString &logtext);
213 void appendFocusLogText(const QString &lines);
214
215 QStringList logText()
216 {
217 return m_LogText;
218 }
219 QString getLogText()
220 {
221 return m_LogText.join("\n");
222 }
223
224public slots:
225 // ////////////////////////////////////////////////////////////////////
226 // DBus interface
227 // ////////////////////////////////////////////////////////////////////
228 /** DBUS interface function.
229 * Start the autofocus operation.
230 */
231 Q_SCRIPTABLE bool start(const QString &trainname);
232
233 /** DBUS interface function.
234 * Capture a focus frame.
235 * @param settleTime if > 0 wait for the given time in seconds before starting to capture
236 */
237 Q_SCRIPTABLE bool capture(const QString &trainname, double settleTime = 0.0);
238
239 /** DBUS interface function.
240 * Focus inward
241 * @param ms If set, focus inward for ms ticks (Absolute Focuser), or ms milliseconds (Relative Focuser). If not set, it will use the value specified in the options.
242 */
243 Q_SCRIPTABLE bool focusIn(const QString &trainname, int ms = -1);
244
245 /** DBUS interface function.
246 * Focus outward
247 * @param ms If set, focus outward for ms ticks (Absolute Focuser), or ms milliseconds (Relative Focuser). If not set, it will use the value specified in the options.
248 */
249 Q_SCRIPTABLE bool focusOut(const QString &trainname, int ms = -1);
250
251 /**
252 * @brief checkFocus Given the minimum required HFR, check focus and calculate HFR. If current HFR exceeds required HFR, start autofocus process, otherwise do nothing.
253 * @param requiredHFR Minimum HFR to trigger autofocus process.
254 */
255 Q_SCRIPTABLE Q_NOREPLY void checkFocus(double requiredHFR, const QString &trainname);
256
257
258
259signals:
260 Q_SCRIPTABLE void newLog(const QString &text);
261 Q_SCRIPTABLE void newStatus(FocusState state, const QString &trainname);
262 Q_SCRIPTABLE void newHFR(double hfr, int position, bool inAutofocus, const QString &trainname);
263 void suspendGuiding();
264 void resumeGuiding();
265 void focusAdaptiveComplete(bool success, const QString &trainname);
266 void newFocusTemperatureDelta(double delta, double absTemperature, const QString &trainname);
267 void inSequenceAF(bool requested, const QString &trainname);
268
269
270private:
271 // ////////////////////////////////////////////////////////////////////
272 // focuser handling
273 // ////////////////////////////////////////////////////////////////////
274
275 /**
276 * @brief addFocuser Add a new focuser under focus management control
277 * @param trainname name of the optical train
278 */
279 QSharedPointer<Focus> addFocuser(const QString &trainname = "");
280
281 void initFocuser(QSharedPointer<Focus> newFocuser);
282
283 /**
284 * @brief Update the focuser
285 * @param ID that holds the focuser
286 * @param current focuser is valid
287 */
288 void updateFocuser(int tabID, bool isValid);
289
290 void closeFocuserTab(int tabIndex);
291
292 void checkCloseFocuserTab(int tabIndex);
293
294 // ////////////////////////////////////////////////////////////////////
295 // Helper functions
296 // ////////////////////////////////////////////////////////////////////
297 /**
298 * @brief findUnusedOpticalTrain Find the name of the first optical train that is not used by another tab
299 * @return
300 */
301 const QString findUnusedOpticalTrain();
302
303 // ////////////////////////////////////////////////////////////////////
304 // Attributes
305 // ////////////////////////////////////////////////////////////////////
306 QList<QSharedPointer<Focus>> m_Focusers;
307
308 /// They're generic GDInterface because they could be either ISD::Camera or ISD::FilterWheel or ISD::Weather
309 QList<QSharedPointer<ISD::GenericDevice>> m_TemperatureSources;
310
311 // ////////////////////////////////////////////////////////////////////
312 // Logging
313 // ////////////////////////////////////////////////////////////////////
314 QStringList m_LogText;
315 QFile m_FocusLogFile;
316 QString m_FocusLogFileName;
317 bool m_FocusLogEnabled { false };
318
319};
320
321}
Ekos is an advanced Astrophotography tool for Linux.
Definition align.cpp:83
Q_CLASSINFO(Name, Value)
Q_INVOKABLEQ_INVOKABLE
Q_OBJECTQ_OBJECT
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Feb 21 2025 11:54:27 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.