Instrument Neutral Distributed Interface INDI  2.0.2
indipropertyswitch.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2021 by Pawel Soja <kernel32.pl@gmail.com>
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"
20 #include "indipropertyswitch_p.h"
21 
22 namespace INDI
23 {
24 
27 { }
28 
30 { }
31 
34 { }
35 
37  : PropertyBasic<ISwitch>(property_private_cast<PropertySwitchPrivate>(property.d_ptr))
38 { }
39 
41 { }
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.findOnSwitch();
59 }
60 
61 bool PropertySwitch::update(const ISState states[], const char * const names[], int n)
62 {
63  D_PTR(PropertySwitch);
64  if (d->onNewValuesCallback)
65  {
66  NewValues newValues;
67  for (int i=0; i<n; ++i)
68  {
69  newValues[names[i]] = states[i];
70  }
71 
72  d->onNewValuesCallback(newValues);
73  return true;
74  }
75  return d->typedProperty.update(states, names, n) && (emitUpdate(), true);
76 }
77 
79 {
80  D_PTR(const PropertySwitch);
81  return d->onNewValuesCallback != nullptr || d->onUpdateCallback != nullptr;
82 }
83 
85  const char *device, const char *name, const char *label, const char *group,
86  IPerm permission, ISRule rule, double timeout, IPState state
87 )
88 {
89  D_PTR(PropertySwitch);
90  d->typedProperty.setWidgets(d->widgets.data(), d->widgets.size());
91  d->typedProperty.fill(device, name, label, group, permission, rule, timeout, state);
92 }
93 
95 {
96  D_PTR(PropertySwitch);
97  d->typedProperty.setRule(rule);
98 }
99 
101 {
102  D_PTR(const PropertySwitch);
103  return d->typedProperty.getRule();
104 }
105 
107 {
108  D_PTR(const PropertySwitch);
109  return d->typedProperty.getRuleAsString();
110 }
111 
112 void PropertySwitch::onNewValues(const std::function<void(const INDI::PropertySwitch::NewValues &)> &callback)
113 {
114  D_PTR(PropertySwitch);
115  d->onNewValuesCallback = callback;
116 }
117 
118 }
hid_device * device
void onNewValues(const std::function< void(const NewValues &)> &callback)
bool update(const ISState states[], const char *const names[], int n)
const char * getRuleAsString() const
void setRule(ISRule rule)
INDI::WidgetViewSwitch * findOnSwitch() 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.
Definition: indiproperty.h:48
friend class PropertySwitch
Definition: indiproperty.h:208
ISState
Switch state.
Definition: indiapi.h:150
IPerm
Permission hint, with respect to client.
Definition: indiapi.h:183
IPState
Property state.
Definition: indiapi.h:160
ISRule
Switch vector rule hint.
Definition: indiapi.h:172
Namespace to encapsulate INDI client, drivers, and mediator classes.
One switch descriptor.