Instrument Neutral Distributed Interface INDI  1.9.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 {
65 class Controller
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 }
INDI::Controller::getControllerType
ControllerType getControllerType(const char *name)
Definition: indicontroller.cpp:367
INDI::Controller::~Controller
virtual ~Controller()
Definition: indicontroller.cpp:53
INDI::Controller::CONTROLLER_UNKNOWN
@ CONTROLLER_UNKNOWN
Definition: indicontroller.h:84
INDI::Controller::buttonEvent
static void buttonEvent(const char *button_n, int value, void *context)
Definition: indicontroller.cpp:360
INDI::Controller::device
INDI::DefaultDevice * device
Definition: indicontroller.h:164
ISwitch
One switch descriptor.
INDI::Controller::saveConfigItems
virtual bool saveConfigItems(FILE *fp)
Definition: indicontroller.cpp:302
INDI::Controller::axisEvent
static void axisEvent(const char *axis_n, int value, void *context)
Definition: indicontroller.cpp:353
INDI::Controller::setButtonCallback
void setButtonCallback(buttonFunc buttonCallback)
setButtonCallback Sets the callback function when a new button input is detected.
Definition: indicontroller.cpp:340
INDI::Controller::Controller
Controller(INDI::DefaultDevice *cdevice)
Controller Default ctor.
Definition: indicontroller.cpp:41
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
_ITextVectorProperty
Text vector property descriptor.
Definition: indiapi.h:244
INDI::Controller::CONTROLLER_AXIS
@ CONTROLLER_AXIS
Definition: indicontroller.h:84
type
__le16 type
Definition: pwc-ioctl.h:2
INDI::Controller::clearMap
void clearMap()
clearMap clears all properties added previously by mapController()
Definition: indicontroller.cpp:96
INDI::Controller::disableJoystick
void disableJoystick()
Definition: indicontroller.cpp:325
INDI::Controller::setAxisCallback
void setAxisCallback(axisFunc axisCallback)
setAxisCallback Sets the callback function when a new axis input is detected.
Definition: indicontroller.cpp:335
IText
One text descriptor.
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::Controller::CONTROLLER_JOYSTICK
@ CONTROLLER_JOYSTICK
Definition: indicontroller.h:84
INDI::Controller::joystickFunc
std::function< void(const char *joystick_n, double mag, double angle, void *context)> joystickFunc
joystickFunc Joystick callback function signature.
Definition: indicontroller.h:89
xml_ele_
Definition: lilxml.c:105
INDI::Controller::getControllerSetting
const char * getControllerSetting(const char *name)
Definition: indicontroller.cpp:381
defaultdevice.h
INDI::Controller::ControllerType
ControllerType
Definition: indicontroller.h:84
INDI::Controller::setJoystickCallback
void setJoystickCallback(joystickFunc joystickCallback)
setJoystickCallback Sets the callback function when a new joystick input is detected.
Definition: indicontroller.cpp:330
INDI::Controller::joystickCallbackFunc
joystickFunc joystickCallbackFunc
Definition: indicontroller.h:160
INDI::Controller::CONTROLLER_BUTTON
@ CONTROLLER_BUTTON
Definition: indicontroller.h:84
INDI::Controller::joystickEvent
static void joystickEvent(const char *joystick_n, double mag, double angle, void *context)
Definition: indicontroller.cpp:345
INDI::Controller::buttonFunc
std::function< void(const char *button_n, ISState state, void *context)> buttonFunc
buttonFunc Button callback function signature.
Definition: indicontroller.h:99
INDI
Namespace to encapsulate INDI client, drivers, and mediator classes.
Definition: AlignmentSubsystemForClients.cpp:11
INDI::Controller::buttonCallbackFunc
buttonFunc buttonCallbackFunc
Definition: indicontroller.h:161
INDI::Controller::axisFunc
std::function< void(const char *axis_n, double value, void *context)> axisFunc
axisFunc Axis callback function signature.
Definition: indicontroller.h:94
INDI::Controller::initProperties
virtual bool initProperties()
Definition: indicontroller.cpp:109
ISState
ISState
Switch state.
Definition: indiapi.h:148
INDI::Controller::enableJoystick
void enableJoystick()
Definition: indicontroller.cpp:311
INDI::DefaultDevice
Class to provide extended functionality for devices in addition to the functionality provided by INDI...
Definition: defaultdevice.h:118
INDI::Controller::ISNewText
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
Definition: indicontroller.cpp:183
INDI::Controller::updateProperties
virtual bool updateProperties()
Definition: indicontroller.cpp:138
_ISwitchVectorProperty
Switch vector property descriptor.
Definition: indiapi.h:365
INDI::Controller::axisCallbackFunc
axisFunc axisCallbackFunc
Definition: indicontroller.h:162