Instrument Neutral Distributed Interface INDI 2.2.5
indipropertyswitch.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2021 by Pawel Soja <[email protected]>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17*/
18
19#include "indipropertyswitch.h"
21
22namespace INDI
23{
24
28
31
35
37 : PropertyBasic<ISwitch>(property_private_cast<PropertySwitchPrivate>(property.d_ptr))
38{ }
39
42
44{
45 D_PTR(PropertySwitch);
46 d->typedProperty.reset();
47}
48
50{
51 D_PTR(const PropertySwitch);
52 return d->typedProperty.findOnSwitchIndex();
53}
54
56{
57 D_PTR(const PropertySwitch);
58 return d->typedProperty.findOnSwitchName();
59}
60
62{
63 D_PTR(const PropertySwitch);
64 return d->typedProperty.findOnSwitch();
65}
66
67bool PropertySwitch::isSwitchOn(const std::string &name) const
68{
69 D_PTR(const PropertySwitch);
70 return d->typedProperty.isSwitchOn(name);
71}
72
73bool PropertySwitch::update(const ISState states[], const char * const names[], int n)
74{
75 D_PTR(PropertySwitch);
76 if (d->onNewValuesCallback)
77 {
78 NewValues newValues;
79 for (int i = 0; i < n; ++i)
80 {
81 newValues[names[i]] = states[i];
82 }
83
84 d->onNewValuesCallback(newValues);
85 return true;
86 }
87 return d->typedProperty.update(states, names, n) && (emitUpdate(), true);
88}
89
91{
92 D_PTR(const PropertySwitch);
93 return d->onNewValuesCallback != nullptr || d->onUpdateCallback != nullptr;
94}
95
97 const char *device, const char *name, const char *label, const char *group,
98 IPerm permission, ISRule rule, double timeout, IPState state
99)
100{
101 D_PTR(PropertySwitch);
102 d->typedProperty.setWidgets(d->widgets.data(), d->widgets.size());
103 d->typedProperty.fill(device, name, label, group, permission, rule, timeout, state);
104}
105
107{
108 D_PTR(PropertySwitch);
109 d->typedProperty.setRule(rule);
110}
111
113{
114 D_PTR(const PropertySwitch);
115 return d->typedProperty.getRule();
116}
117
119{
120 D_PTR(const PropertySwitch);
121 return d->typedProperty.getRuleAsString();
122}
123
124bool PropertySwitch::isUpdated(const ISState states[], const char * const names[], int n) const
125{
126 D_PTR(const PropertySwitch);
127 return d->typedProperty.isUpdated(states, names, n);
128}
129
130void PropertySwitch::onNewValues(const std::function<void(const INDI::PropertySwitch::NewValues &)> &callback)
131{
132 D_PTR(PropertySwitch);
133 d->onNewValuesCallback = callback;
134}
135
136}
hid_device * device
std::string findOnSwitchName() const
void onNewValues(const std::function< void(const NewValues &)> &callback)
bool isSwitchOn(const std::string &name) const
bool update(const ISState states[], const char *const names[], int n)
const char * getRuleAsString() const
INDI::WidgetViewSwitch * findOnSwitch() const
bool isUpdated(const ISState states[], const char *const names[], int n) const
void fill(const char *device, const char *name, const char *label, const char *group, IPerm permission, ISRule rule, double timeout, IPState state)
Provides generic container for INDI properties.
friend class PropertySwitch
ISState
Switch state.
Definition indiapi.h:148
IPerm
Permission hint, with respect to client.
Definition indiapi.h:181
IPState
Property state.
Definition indiapi.h:158
ISRule
Switch vector rule hint.
Definition indiapi.h:170
Namespace to encapsulate INDI client, drivers, and mediator classes.
One switch descriptor.