Instrument Neutral Distributed Interface INDI  2.0.2
indicontroller.h
Go to the documentation of this file.
1 /*******************************************************************************
2  Copyright (C) 2013 Jasem Mutlaq <mutlaqja@ikarustech.com>
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 #pragma once
20 
21 #include "defaultdevice.h"
22 
23 #include <ciso646> // detect std::lib
24 #include <functional>
25 
26 namespace INDI
27 {
66 {
67  public:
69 
73  typedef std::function<void(const char *joystick_n, double mag, double angle, void *context)> joystickFunc;
74 
78  typedef std::function<void(const char *axis_n, double value, void *context)> axisFunc;
79 
83  typedef std::function<void(const char *button_n, ISState state, void *context)> buttonFunc;
84 
90  virtual ~Controller();
91 
92  virtual void ISGetProperties(const char *dev);
93  virtual bool initProperties();
94  virtual bool updateProperties();
95  virtual bool ISSnoopDevice(XMLEle *root);
96  virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n);
97  virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n);
98  virtual bool saveConfigItems(FILE *fp);
99 
107  void mapController(const char *propertyName, const char *propertyLabel, ControllerType type,
108  const char *initialValue);
109 
113  void clearMap();
114 
119  void setJoystickCallback(joystickFunc joystickCallback);
120 
125  void setAxisCallback(axisFunc axisCallback);
126 
131  void setButtonCallback(buttonFunc buttonCallback);
132 
133  ControllerType getControllerType(const char *name);
134  const char *getControllerSetting(const char *name);
135 
136  protected:
137  static void joystickEvent(const char *joystick_n, double mag, double angle, void *context);
138  static void axisEvent(const char *axis_n, int value, void *context);
139  static void buttonEvent(const char *button_n, int value, void *context);
140 
141  void enableJoystick();
142  void disableJoystick();
143 
147 
149 
150  private:
151  /* Joystick Support */
152  ISwitchVectorProperty UseJoystickSP;
153  ISwitch UseJoystickS[2];
154 
155  ITextVectorProperty JoystickDeviceTP;
156  IText JoystickDeviceT[1] {};
157 
158  ITextVectorProperty JoystickSettingTP;
159  IText *JoystickSettingT = nullptr;
160 };
161 }
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.
static void joystickEvent(const char *joystick_n, double mag, double angle, void *context)
virtual bool ISSnoopDevice(XMLEle *root)
const char * getControllerSetting(const char *name)
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
void clearMap()
clearMap clears all properties added previously by mapController()
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()
void setAxisCallback(axisFunc axisCallback)
setAxisCallback Sets the callback function when a new axis input is detected.
INDI::DefaultDevice * device
virtual bool saveConfigItems(FILE *fp)
virtual void ISGetProperties(const char *dev)
std::function< void(const char *button_n, ISState state, void *context)> buttonFunc
buttonFunc Button callback function signature.
axisFunc axisCallbackFunc
virtual bool updateProperties()
void setJoystickCallback(joystickFunc joystickCallback)
setJoystickCallback Sets the callback function when a new joystick input is detected.
joystickFunc joystickCallbackFunc
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
static void buttonEvent(const char *button_n, int value, void *context)
std::function< void(const char *axis_n, double value, void *context)> axisFunc
axisFunc Axis callback function signature.
Controller(INDI::DefaultDevice *cdevice)
Controller Default ctor.
ControllerType getControllerType(const char *name)
std::function< void(const char *joystick_n, double mag, double angle, void *context)> joystickFunc
joystickFunc Joystick callback function signature.
buttonFunc buttonCallbackFunc
static void axisEvent(const char *axis_n, int value, void *context)
Class to provide extended functionality for devices in addition to the functionality provided by INDI...
ISState
Switch state.
Definition: indiapi.h:150
Namespace to encapsulate INDI client, drivers, and mediator classes.
__le16 type
Definition: pwc-ioctl.h:0
One switch descriptor.
One text descriptor.
Switch vector property descriptor.
Definition: indiapi.h:367
Text vector property descriptor.
Definition: indiapi.h:246