Kstars

indirotator.cpp
1 /*
2  SPDX-FileCopyrightText: 2022 Jasem Mutlaq <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "indirotator.h"
8 
9 namespace ISD
10 {
11 
12 bool Rotator::setAbsoluteAngle(double angle)
13 {
14  auto nvp = getNumber("ABS_ROTATOR_ANGLE");
15 
16  if (!nvp)
17  return false;
18 
19  if (std::abs(angle - nvp->at(0)->getValue()) < 0.001)
20  return true;
21 
22  nvp->at(0)->setValue(angle);
23 
24  sendNewNumber(nvp);
25  return true;
26 }
27 
28 bool Rotator::setAbsoluteSteps(uint32_t steps)
29 {
30  auto nvp = getNumber("ABS_ROTATOR_POSITION");
31 
32  if (!nvp)
33  return false;
34 
35  if (steps == static_cast<uint32_t>(nvp->at(0)->getValue()))
36  return true;
37 
38  nvp->at(0)->setValue(steps);
39 
40  sendNewNumber(nvp);
41  return true;
42 }
43 
44 bool Rotator::setReversed(bool enabled)
45 {
46  auto svp = getSwitch("ROTATOR_REVERSE");
47 
48  if (!svp)
49  return false;
50 
51  if ( (enabled && svp->sp[0].s == ISS_ON) ||
52  (!enabled && svp->sp[1].s == ISS_ON))
53  return true;
54 
55  svp->reset();
56  svp->at(0)->setState(enabled ? ISS_ON : ISS_OFF);
57  svp->at(1)->setState(enabled ? ISS_OFF : ISS_ON);
58 
59  sendNewSwitch(svp);
60  return true;
61 }
62 
63 void Rotator::registerProperty(INDI::Property prop)
64 {
65  if (!strcmp(prop->getName(), "ABS_ROTATOR_ANGLE"))
66  processNumber(prop.getNumber());
67  if (!strcmp(prop->getName(), "ROTATOR_REVERSE"))
68  processSwitch(prop.getSwitch());
69 }
70 
71 void Rotator::processNumber(INumberVectorProperty *nvp)
72 {
73  if (!strcmp(nvp->name, "ABS_ROTATOR_ANGLE"))
74  {
75  if (std::abs(nvp->np[0].value - m_AbsoluteAngle) > 0 || nvp->s != m_AbsoluteAngleState)
76  {
77  m_AbsoluteAngle = nvp->np[0].value;
78  m_AbsoluteAngleState = nvp->s;
79  emit newAbsoluteAngle(m_AbsoluteAngle, m_AbsoluteAngleState);
80  }
81  }
82 }
83 
84 void Rotator::processSwitch(ISwitchVectorProperty *svp)
85 {
86  if (!strcmp(svp->name, "ROTATOR_REVERSE"))
87  {
88  auto reverse = IUFindOnSwitchIndex(svp) == 0;
89  if (m_Reversed != reverse)
90  {
91  m_Reversed = reverse;
92  emit reverseToggled(m_Reversed);
93  }
94  }
95 }
96 
97 }
INDI::PropertyView< ISwitch > * getSwitch(const QString &name) const
void sendNewSwitch(ISwitchVectorProperty *pp)
Send new Switch command to server.
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 Tue Dec 6 2022 03:59:17 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.