Instrument Neutral Distributed Interface INDI 2.2.5
indifilterwheel.cpp
Go to the documentation of this file.
1/*******************************************************************************
2 Copyright(c) 2010, 2011 Gerry Rozema. All rights reserved.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
17*******************************************************************************/
18
19#include "indifilterwheel.h"
20
21#include "indicontroller.h"
24
25#include <cstring>
26
27namespace INDI
28{
29
37
39{
41
43
44 controller->mapController("Change Filter", "Change Filter", Controller::CONTROLLER_JOYSTICK, "JOYSTICK_1");
45 controller->mapController("Reset", "Reset", Controller::CONTROLLER_BUTTON, "BUTTON_1");
46
48
50
51 if (filterConnection & CONNECTION_SERIAL)
52 {
55 {
56 return callHandshake();
57 });
59 }
60
61 if (filterConnection & CONNECTION_TCP)
62 {
65 {
66 return callHandshake();
67 });
68
70 }
71
72 return true;
73}
74
75void FilterWheel::ISGetProperties(const char *dev)
76{
78
80 return;
81}
82
84{
85 // Update default device
87
88 // Update Filter Interface
90
91 // Update controller
93
94 return true;
95}
96
97bool FilterWheel::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
98{
99 controller->ISNewSwitch(dev, name, states, names, n);
100 return DefaultDevice::ISNewSwitch(dev, name, states, names, n);
101}
102
103bool FilterWheel::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
104{
105 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
106 {
107 if (strcmp(name, "FILTER_SLOT") == 0)
108 {
109 FilterInterface::processNumber(dev, name, values, names, n);
110 return true;
111 }
112 }
113
114 return DefaultDevice::ISNewNumber(dev, name, values, names, n);
115}
116
117bool FilterWheel::ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
118{
119 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
120 {
121 if (FilterInterface::processText(dev, name, texts, names, n))
122 return true;
123 }
124
125 controller->ISNewText(dev, name, texts, names, n);
126 return DefaultDevice::ISNewText(dev, name, texts, names, n);
127}
128
130{
132
134
136
137 return true;
138}
139
141{
142 return -1;
143}
144
146{
147 return false;
148}
149
151{
153
154 return DefaultDevice::ISSnoopDevice(root);
155}
156
157void FilterWheel::joystickHelper(const char *joystick_n, double mag, double angle, void *context)
158{
159 static_cast<FilterWheel *>(context)->processJoystick(joystick_n, mag, angle);
160}
161
162void FilterWheel::buttonHelper(const char *button_n, ISState state, void *context)
163{
164 static_cast<FilterWheel *>(context)->processButton(button_n, state);
165}
166
167void FilterWheel::processJoystick(const char *joystick_n, double mag, double angle)
168{
169 if (!strcmp(joystick_n, "Change Filter"))
170 {
171 // Put high threshold
172 if (mag > 0.9)
173 {
174 // North
175 if (angle > 0 && angle < 180)
176 {
177 // Previous switch
178 if (FilterSlotNP[0].getValue() == FilterSlotNP[0].getMin())
179 TargetFilter = FilterSlotNP[0].getMax();
180 else
181 TargetFilter = FilterSlotNP[0].getValue() - 1;
182
184 }
185 // South
186 if (angle > 180 && angle < 360)
187 {
188 // Next Switch
189 if (FilterSlotNP[0].getValue() == FilterSlotNP[0].getMax())
190 TargetFilter = FilterSlotNP[0].getMin();
191 else
192 TargetFilter = FilterSlotNP[0].getValue() + 1;
193
195 }
196 }
197 }
198}
199
200void FilterWheel::processButton(const char *button_n, ISState state)
201{
202 //ignore OFF
203 if (state == ISS_OFF)
204 return;
205
206 // Reset
207 if (!strcmp(button_n, "Reset"))
208 {
209 TargetFilter = FilterSlotNP[0].getMin();
211 }
212}
213
215{
216 return false;
217}
218
219bool FilterWheel::callHandshake()
220{
221 if (filterConnection > 0)
222 {
227 }
228
229 return Handshake();
230}
231
232void FilterWheel::setFilterConnection(const uint8_t &value)
233{
235
236 if (value == 0 || (mask & value) == 0)
237 {
238 LOGF_ERROR("Invalid connection mode %d", value);
239 return;
240 }
241
242 filterConnection = value;
243}
244}
void registerHandshake(std::function< bool()> callback)
registerHandshake Register a handshake function to be called once the initial connection to the devic...
The Serial class manages connection with serial devices including Bluetooth. Serial communication is ...
The TCP class manages connection with devices over the network via TCP/IP. Upon successful connection...
int getPortFD() const
const char * getDeviceName() const
The Controller class provides functionality to access a controller (e.g. joystick) input and send it ...
void setButtonCallback(buttonFunc buttonCallback)
setButtonCallback Sets the callback function when a new button input is detected.
virtual bool ISSnoopDevice(XMLEle *root)
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
void mapController(const char *propertyName, const char *propertyLabel, ControllerType type, const char *initialValue)
mapController adds a new property to the joystick's settings.
virtual bool initProperties()
virtual bool saveConfigItems(FILE *fp)
virtual void ISGetProperties(const char *dev)
virtual bool updateProperties()
void setJoystickCallback(joystickFunc joystickCallback)
setJoystickCallback Sets the callback function when a new joystick input is detected.
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
virtual bool updateProperties()
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Process the client newSwitch command.
void registerConnection(Connection::Interface *newConnection)
registerConnection Add new connection plugin to the existing connection pool. The connection type sha...
virtual void ISGetProperties(const char *dev)
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
virtual bool ISSnoopDevice(XMLEle *root)
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
void setDriverInterface(uint32_t value)
setInterface Set driver interface. By default the driver interface is set to GENERAL_DEVICE....
virtual bool saveConfigItems(FILE *fp)
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
virtual bool initProperties()
Initialize properties initial state and value. The child class must implement this function.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
Process the client newNumber command.
Connection::Interface * getActiveConnection()
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
Process the client newSwitch command.
bool processText(const char *dev, const char *name, char *texts[], char *names[], int n)
Process text properties.
INDI::PropertyNumber FilterSlotNP
bool updateProperties()
updateProperties Defines or Delete properties based on default device connection status
bool processNumber(const char *dev, const char *name, double values[], char *names[], int n)
Process number properties.
void initProperties(const char *groupName)
Initialize filter wheel properties. It is recommended to call this function within initProperties() o...
bool saveConfigItems(FILE *fp)
saveConfigItems save Filter Names in config file
static void buttonHelper(const char *button_n, ISState state, void *context)
virtual void ISGetProperties(const char *dev) override
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Controller * controller
void processJoystick(const char *joystick_n, double mag, double angle)
virtual bool Handshake()
perform handshake with device to check communication
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
Connection::TCP * tcpConnection
virtual int QueryFilter() override
Return current filter position.
virtual bool ISSnoopDevice(XMLEle *root) override
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
Connection::Serial * serialConnection
virtual bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
void processButton(const char *button_n, ISState state)
void setFilterConnection(const uint8_t &value)
setFilterConnection Set Filter connection mode. Child class should call this in the constructor befor...
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
static void joystickHelper(const char *joystick_n, double mag, double angle, void *context)
virtual bool SelectFilter(int) override
Select a new filter position.
int PortFD
For Serial & TCP connections.
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
const char * FILTER_TAB
FILTER_TAB Where all the properties for filter wheels are located.
ISState
Switch state.
Definition indiapi.h:148
@ ISS_OFF
Definition indiapi.h:149
#define LOGF_ERROR(fmt,...)
Definition indilogger.h:80
Namespace to encapsulate INDI client, drivers, and mediator classes.