Kstars

indirotator.cpp
1/*
2 SPDX-FileCopyrightText: 2022 Jasem Mutlaq <mutlaqja@ikarustech.com>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "indirotator.h"
8
9namespace ISD
10{
11
12bool 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.01)
20 return true;
21
22 nvp->at(0)->setValue(angle);
23
25 return true;
26}
27
28bool 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
41 return true;
42}
43
44bool 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
60 return true;
61}
62
63void Rotator::registerProperty(INDI::Property prop)
64{
65 if (prop.isNameMatch("ABS_ROTATOR_ANGLE"))
66 processNumber(prop);
67 else if (prop.isNameMatch("ROTATOR_REVERSE"))
68 processSwitch(prop);
69}
70
71void Rotator::processNumber(INDI::Property prop)
72{
73 auto nvp = prop.getNumber();
74 if (nvp->isNameMatch("ABS_ROTATOR_ANGLE"))
75 {
76 if (std::abs(nvp->at(0)->getValue() - m_AbsoluteAngle) > 0 || nvp->getState() != m_AbsoluteAngleState)
77 {
78 m_AbsoluteAngle = nvp->at(0)->getValue();
79 m_AbsoluteAngleState = nvp->getState();
80 emit newAbsoluteAngle(m_AbsoluteAngle, m_AbsoluteAngleState);
81 }
82 }
83}
84
85void Rotator::processSwitch(INDI::Property prop)
86{
87 auto svp = prop.getSwitch();
88 if (svp->isNameMatch("ROTATOR_REVERSE"))
89 {
90 auto reverse = svp->findOnSwitchIndex() == 0;
91 if (m_Reversed != reverse)
92 {
93 m_Reversed = reverse;
94 emit reverseToggled(m_Reversed);
95 }
96 }
97}
98
99}
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.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 24 2024 11:49:22 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.