Kstars

refocusstate.h
1/* Ekos state machine for refocusing
2 SPDX-FileCopyrightText: 2022 Wolfgang Reissenberger <sterne-jaeger@openfuture.de>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#pragma once
8
9#include <QObject>
10#include <QElapsedTimer>
11
12#include "Options.h"
13
14namespace Ekos
15{
16
17class RefocusState : public QObject
18{
20 public:
21 typedef enum
22 {
23 REFOCUS_NONE, /* no need to refocus */
24 REFOCUS_HFR, /* refocusing due to HFR (in sequence) value */
25 REFOCUS_ADAPTIVE, /* adaptive refocusing (in sequence) */
26 REFOCUS_TEMPERATURE, /* refocusing due to temperature change */
27 REFOCUS_TIME_ELAPSED, /* refocusing due to elapsed time since last focusing */
28 REFOCUS_POST_MF, /* refocusing after a completed meridian flip */
29 REFOCUS_USER_REQUEST /* user forced an in sequence Autofocus */
30 } RefocusReason;
31
32 explicit RefocusState(QObject *parent = nullptr): QObject{parent}{}
33
34 /**
35 * @brief Check if focusing is necessary:
36 * 1. forced by user
37 * 2. time limit based
38 * 3. temperature based
39 * 4. HFR based in sequence
40 * 5. post meridian flip *
41 */
42 RefocusReason checkFocusRequired();
43
44 /**
45 * @brief Start the timer triggering refosing after the configured time.
46 * @param forced if true restart the timer even if it is already running
47 */
48 void startRefocusTimer(bool forced = false);
49
50 const QElapsedTimer &getRefocusEveryNTimer() const
51 {
52 return m_refocusEveryNTimer;
53 }
54 qint64 restartRefocusEveryNTimer()
55 {
56 return m_refocusEveryNTimer.restart();
57 }
58
59 uint getRefocusEveryNTimerElapsedSec();
60
61 double getFocusHFR() const
62 {
63 return m_focusHFR;
64 }
65 void setFocusHFR(double newFocusHFR, bool inAutofocus)
66 {
67 m_focusHFR = newFocusHFR;
68 m_focusHFRInAutofocus = inAutofocus;
69 }
70 bool getFocusHFRInAutofocus() const
71 {
72 return m_focusHFRInAutofocus;
73 }
74
75 /**
76 * @brief Is the temperature or HFR based autofocus ready to start? This flag ensures that
77 * focusing has run at least once before the autofocus is triggered by the configured parameters.
78 * @return true if focusing has been executed once
79 */
80 bool isAutoFocusReady() const
81 {
82 return m_AutoFocusReady;
83 }
84 void setAutoFocusReady(bool value)
85 {
86 m_AutoFocusReady = value;
87 }
88
89 bool isInSequenceFocus() const
90 {
91 return m_InSequenceFocus;
92 }
93 void setInSequenceFocus(bool value)
94 {
95 m_InSequenceFocus = value;
96 }
97
98 bool isAdaptiveFocusDone() const
99 {
100 return m_AdaptiveFocusDone;
101 }
102 void setAdaptiveFocusDone(bool value)
103 {
104 m_AdaptiveFocusDone = value;
105 }
106
107 uint getInSequenceFocusCounter() const
108 {
109 return inSequenceFocusCounter;
110 }
111 void decreaseInSequenceFocusCounter();
112 void setInSequenceFocusCounter(uint value)
113 {
114 inSequenceFocusCounter = value;
115 }
116 void resetInSequenceFocusCounter()
117 {
118 inSequenceFocusCounter = Options::inSequenceCheckFrames();
119 }
120
121 double getFocusTemperatureDelta() const
122 {
123 return m_focusTemperatureDelta;
124 }
125 void setFocusTemperatureDelta(double value)
126 {
127 m_focusTemperatureDelta = value;
128 }
129
130 bool isRefocusAfterMeridianFlip() const
131 {
132 return m_refocusAfterMeridianFlip;
133 }
134 void setRefocusAfterMeridianFlip(bool value)
135 {
136 m_refocusAfterMeridianFlip = value;
137 }
138
139 bool isRefocusing() const
140 {
141 return m_refocusing;
142 }
143 void setRefocusing(bool value)
144 {
145 m_refocusing = value;
146 }
147
148 const QMap<QString, QList<double> > &getHFRMap() const
149 {
150 return m_HFRMap;
151 }
152 void setHFRMap(const QMap<QString, QList<double>> &newHFRMap)
153 {
154 m_HFRMap = newHFRMap;
155 }
156
157 /**
158 * @brief Add the current HFR value measured for a frame with given filter
159 */
160 void addHFRValue(const QString &filter);
161
162 bool forceInSeqAF() const
163 {
164 return m_ForceInSeqAF;
165 }
166 void setForceInSeqAF(bool newForceInSeqAF)
167 {
168 m_ForceInSeqAF = newForceInSeqAF;
169 }
170
171signals:
172 // new log text for the module log window
173 void newLog(const QString &text);
174
175
176 private:
177 // HFR value as received from the Ekos focus module
178 double m_focusHFR { 0 };
179 // Whether m_focusHFR was taken during Autofocus
180 bool m_focusHFRInAutofocus { false };
181 // used to determine when next force refocus should occur
182 QElapsedTimer m_refocusEveryNTimer;
183 // Ready for running autofocus (HFR or temperature based)
184 bool m_AutoFocusReady { false };
185 // focusing during the capture sequence
186 bool m_InSequenceFocus { false };
187 // User has requested an autofocus run as soon as possible
188 bool m_ForceInSeqAF {false};
189 // adaptive focusing complete
190 bool m_AdaptiveFocusDone { false };
191 // counter how many captures to be executed until focusing is triggered
192 uint inSequenceFocusCounter { 0 };
193 // Temperature change since last focusing
194 double m_focusTemperatureDelta { 0 };
195 // set to true at meridian flip to request refocus
196 bool m_refocusAfterMeridianFlip { false };
197 // map filter name --> list of HFR values
199
200
201 // Refocusing running
202 bool m_refocusing { false };
203
204
205 /**
206 * @brief Add log message
207 */
208 void appendLogText(const QString &message);
209
210};
211
212}; // namespace
Ekos is an advanced Astrophotography tool for Linux.
Definition align.cpp:83
qint64 restart()
Q_OBJECTQ_OBJECT
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:38:42 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.