Instrument Neutral Distributed Interface INDI  2.0.2
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 
27 namespace INDI
28 {
29 
31 {
32  controller = new Controller(this);
33 
36 }
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  {
63  tcpConnection = new Connection::TCP(this);
65  {
66  return callHandshake();
67  });
68 
70  }
71 
72  return true;
73 }
74 
75 void 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 
97 bool 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 
103 bool 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 
117 bool 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 (strcmp(name, FilterNameTP->name) == 0)
122  {
123  FilterInterface::processText(dev, name, texts, names, n);
124  return true;
125  }
126  }
127 
128  controller->ISNewText(dev, name, texts, names, n);
129  return DefaultDevice::ISNewText(dev, name, texts, names, n);
130 }
131 
133 {
135 
137 
139 
140  return true;
141 }
142 
144 {
145  return -1;
146 }
147 
149 {
150  return false;
151 }
152 
154 {
155  controller->ISSnoopDevice(root);
156 
157  return DefaultDevice::ISSnoopDevice(root);
158 }
159 
160 void FilterWheel::joystickHelper(const char *joystick_n, double mag, double angle, void *context)
161 {
162  static_cast<FilterWheel *>(context)->processJoystick(joystick_n, mag, angle);
163 }
164 
165 void FilterWheel::buttonHelper(const char *button_n, ISState state, void *context)
166 {
167  static_cast<FilterWheel *>(context)->processButton(button_n, state);
168 }
169 
170 void FilterWheel::processJoystick(const char *joystick_n, double mag, double angle)
171 {
172  if (!strcmp(joystick_n, "Change Filter"))
173  {
174  // Put high threshold
175  if (mag > 0.9)
176  {
177  // North
178  if (angle > 0 && angle < 180)
179  {
180  // Previous switch
181  if (FilterSlotN[0].value == FilterSlotN[0].min)
182  TargetFilter = FilterSlotN[0].max;
183  else
184  TargetFilter = FilterSlotN[0].value - 1;
185 
187  }
188  // South
189  if (angle > 180 && angle < 360)
190  {
191  // Next Switch
192  if (FilterSlotN[0].value == FilterSlotN[0].max)
193  TargetFilter = FilterSlotN[0].min;
194  else
195  TargetFilter = FilterSlotN[0].value + 1;
196 
198  }
199  }
200  }
201 }
202 
203 void FilterWheel::processButton(const char *button_n, ISState state)
204 {
205  //ignore OFF
206  if (state == ISS_OFF)
207  return;
208 
209  // Reset
210  if (!strcmp(button_n, "Reset"))
211  {
212  TargetFilter = FilterSlotN[0].min;
214  }
215 }
216 
218 {
219  return false;
220 }
221 
222 bool FilterWheel::callHandshake()
223 {
224  if (filterConnection > 0)
225  {
228  else if (getActiveConnection() == tcpConnection)
230  }
231 
232  return Handshake();
233 }
234 
235 void FilterWheel::setFilterConnection(const uint8_t &value)
236 {
238 
239  if (value == 0 || (mask & value) == 0)
240  {
241  DEBUGF(Logger::DBG_ERROR, "Invalid connection mode %d", value);
242  return;
243  }
244 
245  filterConnection = value;
246 }
247 }
void registerHandshake(std::function< bool()> callback)
registerHandshake Register a handshake function to be called once the intial connection to the device...
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 successfull connectio...
Definition: connectiontcp.h:38
int getPortFD() const
Definition: connectiontcp.h:84
const char * getDeviceName() const
Definition: basedevice.cpp:821
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...
virtual bool saveConfigItems(FILE *fp)
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
virtual bool initProperties()
Initilize 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.
void setDriverInterface(uint16_t value)
setInterface Set driver interface. By default the driver interface is set to GENERAL_DEVICE....
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.
ITextVectorProperty * FilterNameTP
bool updateProperties()
updateProperties Defines or Delete proprties 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)
Initilize filter wheel properties. It is recommended to call this function within initProperties() of...
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
Initilize 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.
double max(void)
double min(void)
ISState
Switch state.
Definition: indiapi.h:150
@ ISS_OFF
Definition: indiapi.h:151
#define DEBUGF(priority, msg,...)
Definition: indilogger.h:57
Namespace to encapsulate INDI client, drivers, and mediator classes.
char name[MAXINDINAME]
Definition: indiapi.h:250