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. time limit based
37 * 2. temperature based
38 * 3. HFR based in sequence
39 * 4. post meridian flip *
40 */
41 RefocusReason checkFocusRequired();
42
43 /**
44 * @brief Start the timer triggering refosing after the configured time.
45 * @param forced if true restart the timer even if it is already running
46 */
47 void startRefocusTimer(bool forced = false);
48
49 const QElapsedTimer &getRefocusEveryNTimer() const
50 {
51 return m_refocusEveryNTimer;
52 }
53 qint64 restartRefocusEveryNTimer()
54 {
55 return m_refocusEveryNTimer.restart();
56 }
57
58 int getRefocusEveryNTimerElapsedSec();
59
60 double getFocusHFR() const
61 {
62 return m_focusHFR;
63 }
64 void setFocusHFR(double newFocusHFR, bool inAutofocus)
65 {
66 m_focusHFR = newFocusHFR;
67 m_focusHFRInAutofocus = inAutofocus;
68 }
69 bool getFocusHFRInAutofocus() const
70 {
71 return m_focusHFRInAutofocus;
72 }
73
74 /**
75 * @brief Is the temperature or HFR based autofocus ready to start? This flag ensures that
76 * focusing has run at least once before the autofocus is triggered by the configured parameters.
77 * @return true if focusing has been executed once
78 */
79 bool isAutoFocusReady() const
80 {
81 return m_AutoFocusReady;
82 }
83 void setAutoFocusReady(bool value)
84 {
85 m_AutoFocusReady = value;
86 }
87
88 bool isInSequenceFocus() const
89 {
90 return m_InSequenceFocus;
91 }
92 void setInSequenceFocus(bool value)
93 {
94 m_InSequenceFocus = value;
95 }
96
97 bool isAdaptiveFocusDone() const
98 {
99 return m_AdaptiveFocusDone;
100 }
101 void setAdaptiveFocusDone(bool value)
102 {
103 m_AdaptiveFocusDone = value;
104 }
105
106 uint getInSequenceFocusCounter() const
107 {
108 return inSequenceFocusCounter;
109 }
110 void decreaseInSequenceFocusCounter();
111 void setInSequenceFocusCounter(uint value)
112 {
113 inSequenceFocusCounter = value;
114 }
115 void resetInSequenceFocusCounter()
116 {
117 inSequenceFocusCounter = Options::inSequenceCheckFrames();
118 }
119
120 double getFocusTemperatureDelta() const
121 {
122 return m_focusTemperatureDelta;
123 }
124 void setFocusTemperatureDelta(double value)
125 {
126 m_focusTemperatureDelta = value;
127 }
128
129 bool isRefocusAfterMeridianFlip() const
130 {
131 return m_refocusAfterMeridianFlip;
132 }
133 void setRefocusAfterMeridianFlip(bool value)
134 {
135 m_refocusAfterMeridianFlip = value;
136 }
137
138 bool isRefocusing() const
139 {
140 return m_refocusing;
141 }
142 void setRefocusing(bool value)
143 {
144 m_refocusing = value;
145 }
146
147 const QMap<QString, QList<double> > &getHFRMap() const
148 {
149 return m_HFRMap;
150 }
151 void setHFRMap(const QMap<QString, QList<double>> &newHFRMap)
152 {
153 m_HFRMap = newHFRMap;
154 }
155
156 /**
157 * @brief Add the current HFR value measured for a frame with given filter
158 */
159 void addHFRValue(const QString &filter);
160
161 signals:
162 // new log text for the module log window
163 void newLog(const QString &text);
164
165
166 private:
167 // HFR value as received from the Ekos focus module
168 double m_focusHFR { 0 };
169 // Whether m_focusHFR was taken during Autofocus
170 bool m_focusHFRInAutofocus { false };
171 // used to determine when next force refocus should occur
172 QElapsedTimer m_refocusEveryNTimer;
173 // Ready for running autofocus (HFR or temperature based)
174 bool m_AutoFocusReady { false };
175 // focusing during the capture sequence
176 bool m_InSequenceFocus { false };
177 // adaptive focusing complete
178 bool m_AdaptiveFocusDone { false };
179 // counter how many captures to be executed until focusing is triggered
180 uint inSequenceFocusCounter { 0 };
181 // Temperature change since last focusing
182 double m_focusTemperatureDelta { 0 };
183 // set to true at meridian flip to request refocus
184 bool m_refocusAfterMeridianFlip { false };
185 // map filter name --> list of HFR values
187
188
189 // Refocusing running
190 bool m_refocusing { false };
191
192
193 /**
194 * @brief Add log message
195 */
196 void appendLogText(const QString &message);
197
198};
199
200}; // namespace
Ekos is an advanced Astrophotography tool for Linux.
Definition align.cpp:79
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 Fri May 24 2024 11:49:21 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.