Instrument Neutral Distributed Interface INDI  1.9.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 
34  controller->setJoystickCallback(joystickHelper);
35  controller->setButtonCallback(buttonHelper);
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  {
54  serialConnection->registerHandshake([&]() { return callHandshake(); });
56  }
57 
58  if (filterConnection & CONNECTION_TCP)
59  {
60  tcpConnection = new Connection::TCP(this);
61  tcpConnection->registerHandshake([&]() { return callHandshake(); });
62 
64  }
65 
66  return true;
67 }
68 
69 void FilterWheel::ISGetProperties(const char *dev)
70 {
72 
74  return;
75 }
76 
78 {
79  // Update default device
81 
82  // Update Filter Interface
84 
85  // Update controller
87 
88  return true;
89 }
90 
91 bool FilterWheel::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
92 {
93  controller->ISNewSwitch(dev, name, states, names, n);
94  return DefaultDevice::ISNewSwitch(dev, name, states, names, n);
95 }
96 
97 bool FilterWheel::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
98 {
99  if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
100  {
101  if (strcmp(name, "FILTER_SLOT") == 0)
102  {
103  FilterInterface::processNumber(dev, name, values, names, n);
104  return true;
105  }
106  }
107 
108  return DefaultDevice::ISNewNumber(dev, name, values, names, n);
109 }
110 
111 bool FilterWheel::ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
112 {
113  if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
114  {
115  if (strcmp(name, FilterNameTP->name) == 0)
116  {
117  FilterInterface::processText(dev, name, texts, names, n);
118  return true;
119  }
120  }
121 
122  controller->ISNewText(dev, name, texts, names, n);
123  return DefaultDevice::ISNewText(dev, name, texts, names, n);
124 }
125 
126 bool FilterWheel::saveConfigItems(FILE *fp)
127 {
129 
131 
133 
134  return true;
135 }
136 
138 {
139  return -1;
140 }
141 
143 {
144  return false;
145 }
146 
148 {
149  controller->ISSnoopDevice(root);
150 
151  return DefaultDevice::ISSnoopDevice(root);
152 }
153 
154 void FilterWheel::joystickHelper(const char *joystick_n, double mag, double angle, void *context)
155 {
156  static_cast<FilterWheel *>(context)->processJoystick(joystick_n, mag, angle);
157 }
158 
159 void FilterWheel::buttonHelper(const char *button_n, ISState state, void *context)
160 {
161  static_cast<FilterWheel *>(context)->processButton(button_n, state);
162 }
163 
164 void FilterWheel::processJoystick(const char *joystick_n, double mag, double angle)
165 {
166  if (!strcmp(joystick_n, "Change Filter"))
167  {
168  // Put high threshold
169  if (mag > 0.9)
170  {
171  // North
172  if (angle > 0 && angle < 180)
173  {
174  // Previous switch
175  if (FilterSlotN[0].value == FilterSlotN[0].min)
176  TargetFilter = FilterSlotN[0].max;
177  else
178  TargetFilter = FilterSlotN[0].value - 1;
179 
181  }
182  // South
183  if (angle > 180 && angle < 360)
184  {
185  // Next Switch
186  if (FilterSlotN[0].value == FilterSlotN[0].max)
187  TargetFilter = FilterSlotN[0].min;
188  else
189  TargetFilter = FilterSlotN[0].value + 1;
190 
192  }
193  }
194  }
195 }
196 
197 void FilterWheel::processButton(const char *button_n, ISState state)
198 {
199  //ignore OFF
200  if (state == ISS_OFF)
201  return;
202 
203  // Reset
204  if (!strcmp(button_n, "Reset"))
205  {
206  TargetFilter = FilterSlotN[0].min;
208  }
209 }
210 
212 {
213  return false;
214 }
215 
216 bool FilterWheel::callHandshake()
217 {
218  if (filterConnection > 0)
219  {
222  else if (getActiveConnection() == tcpConnection)
224  }
225 
226  return Handshake();
227 }
228 
229 void FilterWheel::setFilterConnection(const uint8_t &value)
230 {
232 
233  if (value == 0 || (mask & value) == 0)
234  {
235  DEBUGF(Logger::DBG_ERROR, "Invalid connection mode %d", value);
236  return;
237  }
238 
239  filterConnection = value;
240 }
241 }
INDI::FilterWheel::buttonHelper
static void buttonHelper(const char *button_n, ISState state, void *context)
Definition: indifilterwheel.cpp:175
Connection::TCP::getPortFD
int getPortFD() const
Definition: connectiontcp.h:105
min
double min(void)
INDI::FilterWheel::initProperties
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
Definition: indifilterwheel.cpp:54
INDI::BaseDevice::FILTER_INTERFACE
@ FILTER_INTERFACE
Definition: basedevice.h:76
INDI::Controller::saveConfigItems
virtual bool saveConfigItems(FILE *fp)
Definition: indicontroller.cpp:302
ISS_OFF
@ ISS_OFF
Definition: indiapi.h:150
connectiontcp.h
INDI::FilterWheel::serialConnection
Connection::Serial * serialConnection
Definition: indifilterwheel.h:90
Connection::Serial
The Serial class manages connection with serial devices including Bluetooth. Serial communication is ...
Definition: connectionserial.h:56
INDI::FilterWheel::controller
Controller * controller
Definition: indifilterwheel.h:88
Connection::TCP
The TCP class manages connection with devices over the network via TCP/IP. Upon successfull connectio...
Definition: connectiontcp.h:55
INDI::Logger::DBG_ERROR
@ DBG_ERROR
Definition: indilogger.h:192
INDI::FilterInterface::processNumber
bool processNumber(const char *dev, const char *name, double values[], char *names[], int n)
Process number properties.
Definition: indifilterinterface.cpp:71
INDI::FilterWheel::ISNewNumber
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition: indifilterwheel.cpp:113
FILTER_TAB
const char * FILTER_TAB
FILTER_TAB Where all the properties for filter wheels are located.
Definition: defaultdevice.cpp:40
indifilterwheel.h
INDI::BaseDevice::getDeviceName
const char * getDeviceName() const
Definition: basedevice.cpp:799
INDI::FilterWheel::ISNewText
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
Definition: indifilterwheel.cpp:127
INDI::FilterWheel::setFilterConnection
void setFilterConnection(const uint8_t &value)
setFilterConnection Set Filter connection mode. Child class should call this in the constructor befor...
Definition: indifilterwheel.cpp:245
INDI::FilterInterface::FilterSlotN
INumber FilterSlotN[1]
Definition: indifilterinterface.h:122
INDI::Controller::mapController
void mapController(const char *propertyName, const char *propertyLabel, ControllerType type, const char *initialValue)
mapController adds a new property to the joystick's settings.
Definition: indicontroller.cpp:61
INDI::FilterInterface::updateProperties
bool updateProperties()
updateProperties Defines or Delete proprties based on default device connection status
Definition: indifilterinterface.cpp:48
INDI::DefaultDevice::initProperties
virtual bool initProperties()
Initilize properties initial state and value. The child class must implement this function.
Definition: defaultdevice.cpp:917
max
double max(void)
INDI::FilterWheel::FilterWheel
FilterWheel()
Definition: indifilterwheel.cpp:46
INDI::FilterWheel::ISSnoopDevice
virtual bool ISSnoopDevice(XMLEle *root) override
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
Definition: indifilterwheel.cpp:163
INDI::DefaultDevice::ISSnoopDevice
virtual bool ISSnoopDevice(XMLEle *root)
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
Definition: defaultdevice.cpp:633
INDI::Controller::ISNewSwitch
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Definition: indicontroller.cpp:158
INDI::Controller::ISSnoopDevice
virtual bool ISSnoopDevice(XMLEle *root)
Definition: indicontroller.cpp:239
INDI::Controller::ISGetProperties
virtual void ISGetProperties(const char *dev)
Definition: indicontroller.cpp:123
INDI::FilterWheel::tcpConnection
Connection::TCP * tcpConnection
Definition: indifilterwheel.h:91
INDI::DefaultDevice::ISNewNumber
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
Process the client newNumber command.
Definition: defaultdevice.cpp:593
INDI::Controller::CONTROLLER_JOYSTICK
@ CONTROLLER_JOYSTICK
Definition: indicontroller.h:84
connectionserial.h
INDI::DefaultDevice::registerConnection
void registerConnection(Connection::Interface *newConnection)
registerConnection Add new connection plugin to the existing connection pool. The connection type sha...
Definition: defaultdevice.cpp:1107
FilterInterface
Provides interface to implement Filter Wheel functionality.
INDI::FilterWheel::processJoystick
void processJoystick(const char *joystick_n, double mag, double angle)
Definition: indifilterwheel.cpp:180
xml_ele_
Definition: lilxml.c:105
INDI::FilterInterface::FilterNameTP
ITextVectorProperty * FilterNameTP
Definition: indifilterinterface.h:125
_ITextVectorProperty::name
char name[MAXINDINAME]
Definition: indiapi.h:249
INDI::FilterWheel
Definition: indifilterwheel.h:36
INDI::FilterWheel::joystickHelper
static void joystickHelper(const char *joystick_n, double mag, double angle, void *context)
Definition: indifilterwheel.cpp:170
indicontroller.h
INDI::FilterWheel::ISNewSwitch
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
Definition: indifilterwheel.cpp:107
INDI::Controller::CONTROLLER_BUTTON
@ CONTROLLER_BUTTON
Definition: indicontroller.h:84
INDI::FilterInterface::TargetFilter
int TargetFilter
Definition: indifilterinterface.h:129
INDI::DefaultDevice::ISGetProperties
virtual void ISGetProperties(const char *dev)
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
Definition: defaultdevice.cpp:750
INDI::FilterWheel::CONNECTION_SERIAL
@ CONNECTION_SERIAL
Definition: indifilterwheel.h:50
INDI::FilterInterface::saveConfigItems
bool saveConfigItems(FILE *fp)
saveConfigItems save Filter Names in config file
Definition: indifilterinterface.cpp:167
INDI::FilterWheel::CONNECTION_TCP
@ CONNECTION_TCP
Definition: indifilterwheel.h:51
INDI::FilterInterface::processText
bool processText(const char *dev, const char *name, char *texts[], char *names[], int n)
Process text properties.
Definition: indifilterinterface.cpp:112
INDI
Namespace to encapsulate INDI client, drivers, and mediator classes.
Definition: AlignmentSubsystemForClients.cpp:11
Connection::Interface::registerHandshake
void registerHandshake(std::function< bool()> callback)
registerHandshake Register a handshake function to be called once the intial connection to the device...
Definition: connectioninterface.cpp:108
INDI::FilterWheel::PortFD
int PortFD
For Serial & TCP connections.
Definition: indifilterwheel.h:94
DEBUGF
#define DEBUGF(priority, msg,...)
Definition: indilogger.h:57
INDI::DefaultDevice::saveConfigItems
virtual bool saveConfigItems(FILE *fp)
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
Definition: defaultdevice.cpp:175
INDI::FilterWheel::processButton
void processButton(const char *button_n, ISState state)
Definition: indifilterwheel.cpp:213
INDI::FilterWheel::updateProperties
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition: indifilterwheel.cpp:93
INDI::FilterWheel::ISGetProperties
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...
Definition: indifilterwheel.cpp:85
INDI::Controller::initProperties
virtual bool initProperties()
Definition: indicontroller.cpp:109
ISState
ISState
Switch state.
Definition: indiapi.h:148
Connection::Serial::getPortFD
int getPortFD() const
Definition: connectionserial.h:136
INDI::DefaultDevice::ISNewSwitch
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Process the client newSwitch command.
Definition: defaultdevice.cpp:409
INDI::FilterWheel::saveConfigItems
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
Definition: indifilterwheel.cpp:142
INDI::FilterInterface::initProperties
void initProperties(const char *groupName)
Initilize filter wheel properties. It is recommended to call this function within initProperties() of...
Definition: indifilterinterface.cpp:39
INDI::FilterWheel::QueryFilter
virtual int QueryFilter() override
Return current filter position.
Definition: indifilterwheel.cpp:153
INDI::FilterWheel::Handshake
virtual bool Handshake()
perform handshake with device to check communication
Definition: indifilterwheel.cpp:227
INDI::DefaultDevice::ISNewText
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
Process the client newSwitch command.
Definition: defaultdevice.cpp:614
INDI::Controller::ISNewText
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
Definition: indicontroller.cpp:183
INDI::DefaultDevice::setDriverInterface
void setDriverInterface(uint16_t value)
setInterface Set driver interface. By default the driver interface is set to GENERAL_DEVICE....
Definition: defaultdevice.cpp:902
INDI::Controller::updateProperties
virtual bool updateProperties()
Definition: indicontroller.cpp:138
INDI::FilterWheel::SelectFilter
virtual bool SelectFilter(int) override
Select a new filter position.
Definition: indifilterwheel.cpp:158
INDI::DefaultDevice::updateProperties
virtual bool updateProperties()
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition: defaultdevice.cpp:890
INDI::FilterWheel::CONNECTION_NONE
@ CONNECTION_NONE
Definition: indifilterwheel.h:49
INDI::DefaultDevice::getActiveConnection
Connection::Interface * getActiveConnection()
Definition: defaultdevice.cpp:1245