Instrument Neutral Distributed Interface INDI 2.2.5
indicontroller.h
Go to the documentation of this file.
1/*******************************************************************************
2 Copyright (C) 2013 Jasem Mutlaq <[email protected]>
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 <functional>
24
25namespace INDI
26{
65{
66 public:
68
72 typedef std::function<void(const char *joystick_n, double mag, double angle, void *context)> joystickFunc;
73
77 typedef std::function<void(const char *axis_n, double value, void *context)> axisFunc;
78
82 typedef std::function<void(const char *button_n, ISState state, void *context)> buttonFunc;
83
89 virtual ~Controller();
90
91 virtual void ISGetProperties(const char *dev);
92 virtual bool initProperties();
93 virtual bool updateProperties();
94 virtual bool ISSnoopDevice(XMLEle *root);
95 virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n);
96 virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n);
97 virtual bool saveConfigItems(FILE *fp);
98
106 void mapController(const char *propertyName, const char *propertyLabel, ControllerType type,
107 const char *initialValue);
108
112 void clearMap();
113
118 void setJoystickCallback(joystickFunc joystickCallback);
119
124 void setAxisCallback(axisFunc axisCallback);
125
130 void setButtonCallback(buttonFunc buttonCallback);
131
132 ControllerType getControllerType(const char *name);
133 const char *getControllerSetting(const char *name);
134
135 protected:
136 static void joystickEvent(const char *joystick_n, double mag, double angle, void *context);
137 static void axisEvent(const char *axis_n, int value, void *context);
138 static void buttonEvent(const char *button_n, int value, void *context);
139
140 void enableJoystick();
141 void disableJoystick();
142
146
148
149 private:
150 /* Joystick Support */
151 ISwitchVectorProperty UseJoystickSP;
152 ISwitch UseJoystickS[2];
153
154 ITextVectorProperty JoystickDeviceTP;
155 IText JoystickDeviceT[1] {};
156
157 ITextVectorProperty JoystickSettingTP;
158 IText *JoystickSettingT = nullptr;
159};
160}
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.
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:148
Namespace to encapsulate INDI client, drivers, and mediator classes.
uint16_t type
Definition pwc-ioctl.h:0
One switch descriptor.
One text descriptor.
Switch vector property descriptor.
Definition indiapi.h:365
Text vector property descriptor.
Definition indiapi.h:244