Kstars

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

KDE's Doxygen guidelines are available online.