Instrument Neutral Distributed Interface INDI 2.2.5
indiinputinterface.cpp
Go to the documentation of this file.
1/*
2 Input Interface
3 Copyright (C) 2024 Jasem Mutlaq ([email protected])
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
19*/
20
21#include "indiinputinterface.h"
22#include <cstring>
23#include "indilogger.h"
24
25namespace INDI
26{
27
31InputInterface::InputInterface(DefaultDevice *defaultDevice) : m_defaultDevice(defaultDevice)
32{
33}
34
41
45void InputInterface::initProperties(const char *groupName, uint8_t digital, uint8_t analog,
46 const std::string &digitalPrefix, const std::string &analogPrefix)
47{
50
51 // @INDI_STANDARD_PROPERTY@
53 // Digital labels
54 for (size_t i = 0; i < digital; i++)
55 {
56 auto name = "DIGITAL_INPUT_" + std::to_string(i + 1);
57 auto label = digitalPrefix + " #" + std::to_string(i + 1);
58
59 INDI::WidgetText oneLabel;
60 oneLabel.fill(name, label, label);
61 DigitalInputLabelsTP.push(std::move(oneLabel));
62 }
63
64 if (digital > 0)
65 {
66 // @INDI_STANDARD_PROPERTY@
67 DigitalInputLabelsTP.fill(m_defaultDevice->getDeviceName(), "DIGITAL_INPUT_LABELS", "Digital Labels", groupName, IP_RW, 60,
68 IPS_IDLE);
71 }
72
73 // Analog labels
74 // @INDI_STANDARD_PROPERTY@
76 for (size_t i = 0; i < analog; i++)
77 {
78 auto name = "ANALOG_INPUT_" + std::to_string(i + 1);
79 auto label = analogPrefix + " #" + std::to_string(i + 1);
80
81 INDI::WidgetText oneLabel;
82 oneLabel.fill(name, label, label);
83 AnalogInputLabelsTP.push(std::move(oneLabel));
84 }
85
86 if (analog > 0)
87 {
88 AnalogInputLabelsTP.fill(m_defaultDevice->getDeviceName(), "ANALOG_INPUT_LABELS", "Analog Labels", groupName, IP_RW, 60,
89 IPS_IDLE);
92 }
93
94 // Analog inputs
95 // @INDI_STANDARD_PROPERTY@
96 AnalogInputsNP.reserve(analog);
97 for (size_t i = 0; i < analog; i++)
98 {
99 auto name = "ANALOG_INPUT_" + std::to_string(i + 1);
100 auto label = analogPrefix + " #" + std::to_string(i + 1);
101
102 if (i < AnalogInputLabelsTP.count())
103 label = AnalogInputLabelsTP[i].getText();
104
105 INDI::PropertyNumber oneNumber {1};
106 oneNumber[0].fill(name, label, "%.2f", 0, 1e6, 1, 1);
107 oneNumber.fill(m_defaultDevice->getDeviceName(), name.c_str(), label.c_str(), groupName, IP_RO, 60, IPS_IDLE);
108 AnalogInputsNP.push_back(std::move(oneNumber));
109 }
110
111 // @INDI_STANDARD_PROPERTY@
112 DigitalInputsSP.reserve(digital);
113 // Initialize switches, use labels if loaded.
114 for (size_t i = 0; i < digital; i++)
115 {
116 auto name = "DIGITAL_INPUT_" + std::to_string(i + 1);
117 auto label = digitalPrefix + " #" + std::to_string(i + 1);
118
119 INDI::PropertySwitch oneInput {2};
120 oneInput[Off].fill("OFF", "Off", ISS_OFF);
121 oneInput[On].fill("ON", "On", ISS_OFF);
122
123 if (i < DigitalInputLabelsTP.count())
124 label = DigitalInputLabelsTP[i].getText();
125 oneInput.fill(m_defaultDevice->getDeviceName(), name.c_str(), label.c_str(), groupName, IP_RO, ISR_1OFMANY, 60, IPS_IDLE);
126 DigitalInputsSP.push_back(std::move(oneInput));
127 }
128}
129
134{
136 {
137 if (!DigitalInputsSP.empty())
138 {
139 for (auto &oneInput : DigitalInputsSP)
142 }
143
144 if (!AnalogInputsNP.empty())
145 {
146 for (auto &oneInput : AnalogInputsNP)
149 }
150
151 }
152 else
153 {
154 if (!DigitalInputsSP.empty())
155 {
156 for (auto &oneInput : DigitalInputsSP)
159 }
160
161 if (!AnalogInputsNP.empty())
162 {
163 for (auto &oneInput : AnalogInputsNP)
166 }
167 }
168
169 return true;
170}
171
175bool InputInterface::processText(const char *dev, const char *name, char *texts[], char *names[], int n)
176{
177 if (dev && !strcmp(dev, m_defaultDevice->getDeviceName()))
178 {
179 // If this call due to config loading, let's delete existing dummy property and define the full one
181 {
182 DigitalInputLabelsTP.update(texts, names, n);
186 return true;
187 }
188
190 {
191 AnalogInputLabelsTP.update(texts, names, n);
195 return true;
196 }
197 }
198
199 return false;
200}
201
206{
209 return true;
210}
211
212}
bool isConnected() const
const char * getDeviceName() const
Class to provide extended functionality for devices in addition to the functionality provided by INDI...
virtual bool saveConfig(bool silent=false, const char *property=nullptr)
Save the current properties in a configuration file.
virtual bool deleteProperty(const char *propertyName)
Delete a property and unregister it. It will also be deleted from all clients.
void defineProperty(INumberVectorProperty *property)
bool processText(const char *dev, const char *name, char *texts[], char *names[], int n)
Process text properties.
INDI::PropertyText AnalogInputLabelsTP
std::vector< INDI::PropertySwitch > DigitalInputsSP
std::vector< INDI::PropertyNumber > AnalogInputsNP
bool saveConfigItems(FILE *fp)
saveConfigItems save Filter Names in config file
INDI::PropertyText DigitalInputLabelsTP
void initProperties(const char *groupName, uint8_t digital, uint8_t analog, const std::string &digitalPrefix="Digital", const std::string &analogPrefix="Analog")
Initialize filter wheel properties. It is recommended to call this function within initProperties() o...
bool updateProperties()
updateProperties Defines or Delete properties based on default device connection status
DefaultDevice * m_defaultDevice
InputInterface(DefaultDevice *defaultDevice)
InputInterface Initiailize Input Interface.
void push(WidgetView< T > &&item)
void setState(IPState state)
void apply(const char *format,...) const ATTRIBUTE_FORMAT_PRINTF(2
bool load()
load Attempt to load property values from configuration file.
void save(FILE *f) const
save Save property to configuration file.
void resize(size_t size)
bool isNameMatch(const char *otherName) const
void fill(const char *device, const char *name, const char *label, const char *group, IPerm permission, double timeout, IPState state)
void fill(const char *device, const char *name, const char *label, const char *group, IPerm permission, ISRule rule, double timeout, IPState state)
bool update(const char *const texts[], const char *const names[], int n)
void fill(const char *device, const char *name, const char *label, const char *group, IPerm permission, double timeout, IPState state)
INDI::PropertyViewText * getText() const
@ ISS_OFF
Definition indiapi.h:149
@ IP_RW
Definition indiapi.h:184
@ IP_RO
Definition indiapi.h:182
@ IPS_IDLE
Definition indiapi.h:159
@ IPS_OK
Definition indiapi.h:160
@ ISR_1OFMANY
Definition indiapi.h:171
Namespace to encapsulate INDI client, drivers, and mediator classes.
void fill(const char *device, const char *name, const char *label, const char *group, IPerm permission, double timeout, IPState state)
void fill(const char *name, const char *label, const char *initialText)