Kstars

indifocuser.cpp
1/*
2 SPDX-FileCopyrightText: 2012 Jasem Mutlaq <mutlaqja@ikarustech.com>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include <basedevice.h>
8#include "indifocuser.h"
9#include "clientmanager.h"
10
11namespace ISD
12{
13
14void Focuser::registerProperty(INDI::Property prop)
15{
16 if (!prop.getRegistered())
17 return;
18
19 if (prop.isNameMatch("FOCUS_MAX"))
20 {
21 auto nvp = prop.getNumber();
22 m_maxPosition = nvp->at(0)->getValue();
23 }
24
25 ConcreteDevice::registerProperty(prop);
26}
27
28void Focuser::processNumber(INDI::Property prop)
29{
30 auto nvp = prop.getNumber();
31 if (prop.isNameMatch("FOCUS_MAX"))
32 {
33 m_maxPosition = nvp->at(0)->getValue();
34 }
35}
36
37bool Focuser::focusIn()
38{
39 auto focusProp = getSwitch("FOCUS_MOTION");
40
41 if (!focusProp)
42 return false;
43
44 auto inFocus = focusProp->findWidgetByName("FOCUS_INWARD");
45
46 if (!inFocus)
47 return false;
48
49 if (inFocus->getState() == ISS_ON)
50 return true;
51
52 focusProp->reset();
53 inFocus->setState(ISS_ON);
54
55 sendNewProperty(focusProp);
56
57 return true;
58}
59
60bool Focuser::stop()
61{
62 auto focusStop = getSwitch("FOCUS_ABORT_MOTION");
63
64 if (!focusStop)
65 return false;
66
67 focusStop->at(0)->setState(ISS_ON);
68 sendNewProperty(focusStop);
69
70 return true;
71}
72
73bool Focuser::focusOut()
74{
75 auto focusProp = getSwitch("FOCUS_MOTION");
76
77 if (!focusProp)
78 return false;
79
80 auto outFocus = focusProp->findWidgetByName("FOCUS_OUTWARD");
81
82 if (!outFocus)
83 return false;
84
85 if (outFocus->getState() == ISS_ON)
86 return true;
87
88 focusProp->reset();
89 outFocus->setState(ISS_ON);
90
91 sendNewProperty(focusProp);
92
93 return true;
94}
95
96bool Focuser::getFocusDirection(ISD::Focuser::FocusDirection *dir)
97{
98 auto focusProp = getSwitch("FOCUS_MOTION");
99
100 if (!focusProp)
101 return false;
102
103 auto inFocus = focusProp->findWidgetByName("FOCUS_INWARD");
104
105 if (!inFocus)
106 return false;
107
108 if (inFocus->getState() == ISS_ON)
109 *dir = FOCUS_INWARD;
110 else
111 *dir = FOCUS_OUTWARD;
112
113 return true;
114}
115
116bool Focuser::moveByTimer(int msecs)
117{
118 auto focusProp = getNumber("FOCUS_TIMER");
119
120 if (!focusProp)
121 return false;
122
123 focusProp->at(0)->setValue(msecs);
124
125 sendNewProperty(focusProp);
126
127 return true;
128}
129
130bool Focuser::moveAbs(int steps)
131{
132 auto focusProp = getNumber("ABS_FOCUS_POSITION");
133
134 if (!focusProp)
135 return false;
136
137 focusProp->at(0)->setValue(steps);
138
139 sendNewProperty(focusProp);
140
141 return true;
142}
143
144bool Focuser::canAbsMove()
145{
146 auto focusProp = getNumber("ABS_FOCUS_POSITION");
147
148 if (!focusProp)
149 return false;
150 else
151 return true;
152}
153
154bool Focuser::moveRel(int steps)
155{
156 INDI::PropertyView<INumber> *focusProp;
157
158 if(canManualFocusDriveMove())
159 {
160 focusProp = getNumber("manualfocusdrive");
161
162 FocusDirection dir;
163 if (!getFocusDirection(&dir))
164 return false;
165 if (dir == FOCUS_INWARD)
166 steps = -abs(steps);
167 else if (dir == FOCUS_OUTWARD)
168 steps = abs(steps);
169
170 //manualfocusdrive needs different steps value ​​at every turn
171 if (steps == getLastManualFocusDriveValue())
172 steps += 1;
173
174 //Nikon Z6 fails if step is -1, 0, 1
175 if (deviation == NIKONZ6)
176 {
177 if (abs(steps) < 2)
178 steps = 2;
179 }
180 }
181 else
182 {
183 focusProp = getNumber("REL_FOCUS_POSITION");
184 }
185
186 if (!focusProp)
187 return false;
188
189 focusProp->at(0)->setValue(steps);
190
191 sendNewProperty(focusProp);
192
193 return true;
194}
195
196bool Focuser::canRelMove()
197{
198 auto focusProp = getNumber("REL_FOCUS_POSITION");
199
200 if (!focusProp)
201 return false;
202 else
203 return true;
204}
205
206bool Focuser::canManualFocusDriveMove()
207{
208 auto focusProp = getNumber("manualfocusdrive");
209
210 if (!focusProp)
211 return false;
212 else
213 return true;
214}
215
216double Focuser::getLastManualFocusDriveValue()
217{
218 auto focusProp = getNumber("manualfocusdrive");
219
220 if (!focusProp)
221 return 0;
222
223 return focusProp->at(0)->getValue();
224}
225
226
227bool Focuser::canTimerMove()
228{
229 auto focusProp = getNumber("FOCUS_TIMER");
230
231 if (!focusProp)
232 return false;
233 else
234 return true;
235}
236
237bool Focuser::setMaxPosition(uint32_t steps)
238{
239 auto focusProp = getNumber("FOCUS_MAX");
240
241 if (!focusProp)
242 return false;
243
244 focusProp->at(0)->setValue(steps);
245 sendNewProperty(focusProp);
246
247 return true;
248}
249
250bool Focuser::hasBacklash()
251{
252 auto focusProp = getNumber("FOCUS_BACKLASH_STEPS");
253 return (focusProp != nullptr);
254}
255
256bool Focuser::setBacklash(int32_t steps)
257{
258 auto focusToggle = getSwitch("FOCUS_BACKLASH_TOGGLE");
259 if (!focusToggle)
260 return false;
261
262 // Make sure focus compensation is enabled.
263 if (steps != 0 && focusToggle->at(0)->getState() != ISS_ON)
264 {
265 focusToggle->reset();
266 focusToggle->at(0)->setState(ISS_ON);
267 focusToggle->at(1)->setState(ISS_OFF);
268 sendNewProperty(focusToggle);
269 }
270
271 auto focusProp = getNumber("FOCUS_BACKLASH_STEPS");
272 if (!focusProp)
273 return false;
274
275 focusProp->at(0)->setValue(steps);
276 sendNewProperty(focusProp);
277
278 // If steps = 0, disable compensation
279 if (steps == 0 && focusToggle->at(0)->getState() == ISS_ON)
280 {
281 focusToggle->reset();
282 focusToggle->at(0)->setState(ISS_OFF);
283 focusToggle->at(1)->setState(ISS_ON);
284 sendNewProperty(focusToggle);
285 }
286 return true;
287}
288
289int32_t Focuser::getBacklash()
290{
291 auto focusProp = getNumber("FOCUS_BACKLASH_STEPS");
292 if (!focusProp)
293 return -1;
294
295 return focusProp->at(0)->getValue();
296}
297
298bool Focuser::hasDeviation()
299{
300 if (getDeviceName() == "Nikon DSLR Z6")
301 {
302 deviation = NIKONZ6;
303 return true;
304 }
305 return false;
306}
307
308}
void sendNewProperty(INDI::Property prop)
Send new property command to server.
INDI::PropertyView< ISwitch > * getSwitch(const QString &name) const
ISD is a collection of INDI Standard Devices.
KIOCORE_EXPORT QString dir(const QString &fileClass)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 20 2024 11:53:00 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.