Kstars

refocusstate.cpp
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#include "refocusstate.h"
8#include "klocalizedstring.h"
9
10#include <ekos_capture_debug.h>
11
12namespace Ekos
13{
14
15uint RefocusState::getRefocusEveryNTimerElapsedSec()
16{
17 /* If timer isn't valid, consider there is no focus to be done, that is, that focus was just done */
18 return m_refocusEveryNTimer.isValid() ? static_cast<uint>(m_refocusEveryNTimer.elapsed() / 1000) : 0;
19}
20
21RefocusState::RefocusReason RefocusState::checkFocusRequired()
22{
23 setRefocusing(false);
24 setInSequenceFocus(isAutoFocusReady() && Options::enforceAutofocusHFR());
25
26 // 1. check if user requested an ad-hoc in-sequence Autofocus
27 if (forceInSeqAF())
28 {
29 qCDebug(KSTARS_EKOS_CAPTURE) << "User initiated ad-hoc in-sequence Autofocus";
30
31 setRefocusing(true);
32 appendLogText(i18n("User initiated ad-hoc in-sequence Autofocus..."));
33 return REFOCUS_USER_REQUEST;
34 }
35
36 // 2. check if time limit based refocusing is necessary
37 if (Options::enforceRefocusEveryN())
38 {
39 qCDebug(KSTARS_EKOS_CAPTURE) << "Focus elapsed time (secs): " << getRefocusEveryNTimerElapsedSec() <<
40 ". Requested Interval (secs): " << Options::refocusEveryN() * 60;
41
42 if (getRefocusEveryNTimerElapsedSec() >= Options::refocusEveryN() * 60)
43 {
44 setRefocusing(true);
45 appendLogText(i18n("Scheduled refocus starting after %1 seconds...", getRefocusEveryNTimerElapsedSec()));
46 return REFOCUS_TIME_ELAPSED;
47 }
48 }
49
50 // 3. check if temperature based refocusing is necessary
51 if (!isRefocusing() && Options::enforceAutofocusOnTemperature())
52 {
53 qCDebug(KSTARS_EKOS_CAPTURE) << "Focus temperature delta (°C): " << getFocusTemperatureDelta() <<
54 ". Requested maximum delta (°C): " << Options::maxFocusTemperatureDelta();
55
56 if (getFocusTemperatureDelta() > Options::maxFocusTemperatureDelta())
57 {
58 setRefocusing(true);
59 appendLogText(i18n("Refocus starting because of temperature change of %1 °C...", getFocusTemperatureDelta()));
60 return REFOCUS_TEMPERATURE;
61 }
62 }
63
64 // 4. check if post meridian flip refocusing is necessary
65 if (!isRefocusing() && isRefocusAfterMeridianFlip())
66 {
67 setRefocusing(true);
68 appendLogText(i18n("Refocus after meridian flip"));
69 return REFOCUS_POST_MF;
70 }
71
72 // 5. check if HFR based in sequence focusing is necessary
73 if (!isRefocusing() && isInSequenceFocus() && getInSequenceFocusCounter() == 0)
74 {
75 setRefocusing(true);
76 appendLogText(i18n("In sequence HFR based refocus starting..."));
77 return REFOCUS_HFR;
78 }
79
80 // 6. no full refocus required so check if adaptive focus is necessary - no need to do both
81 if (!isRefocusing() && Options::focusAdaptive() && !isAdaptiveFocusDone())
82 {
83 setRefocusing(true);
84 appendLogText(i18n("Adaptive focus starting..."));
85 return REFOCUS_ADAPTIVE;
86 }
87 // no refocusing necessary
88 return REFOCUS_NONE;
89}
90
91void RefocusState::startRefocusTimer(bool forced)
92{
93 /* If refocus is requested, only restart timer if not already running in order to keep current elapsed time since last refocus */
94 if (Options::enforceRefocusEveryN())
95 {
96 // How much time passed since we last started the time
97 long elapsedSecs = getRefocusEveryNTimer().elapsed() / 1000;
98 // How many seconds do we wait for between focusing (60 mins ==> 3600 secs)
99 int totalSecs = Options::refocusEveryN() * 60;
100
101 if (!getRefocusEveryNTimer().isValid() || forced)
102 {
103 appendLogText(i18n("Ekos will refocus in %1 seconds.", totalSecs));
104 restartRefocusEveryNTimer();
105 }
106 else if (elapsedSecs < totalSecs)
107 {
108 appendLogText(i18n("Ekos will refocus in %1 seconds, last procedure was %2 seconds ago.", totalSecs - elapsedSecs,
109 elapsedSecs));
110 }
111 else
112 {
113 appendLogText(i18n("Ekos will refocus as soon as possible, last procedure was %1 seconds ago.", elapsedSecs));
114 }
115 }
116}
117
118void RefocusState::decreaseInSequenceFocusCounter()
119{
120 if (inSequenceFocusCounter > 0)
121 --inSequenceFocusCounter;
122}
123
124void RefocusState::addHFRValue(const QString &filter)
125{
126 QList<double> filterHFRList = m_HFRMap[filter];
127 filterHFRList.append(getFocusHFR());
128 m_HFRMap[filter] = filterHFRList;
129}
130
131
132
133
134
135void RefocusState::appendLogText(const QString &message)
136{
137 qCInfo(KSTARS_EKOS_CAPTURE()) << message;
138 emit newLog(message);
139}
140
141
142} // namespace
QString i18n(const char *text, const TYPE &arg...)
Ekos is an advanced Astrophotography tool for Linux.
Definition align.cpp:83
bool isValid(QStringView ifopt)
qint64 elapsed() const const
bool isValid() const const
void append(QList< T > &&value)
QFuture< void > filter(QThreadPool *pool, Sequence &sequence, KeepFunctor &&filterFunction)
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.