The Controller class provides functionality to access a controller (e.g. joystick) input and send it to the requesting driver.
More...
#include <indicontroller.h>
|
enum | ControllerType { CONTROLLER_JOYSTICK
, CONTROLLER_AXIS
, CONTROLLER_BUTTON
, CONTROLLER_UNKNOWN
} |
|
typedef std::function< void(const char *joystick_n, double mag, double angle, void *context)> | joystickFunc |
| joystickFunc Joystick callback function signature. More...
|
|
typedef std::function< void(const char *axis_n, double value, void *context)> | axisFunc |
| axisFunc Axis callback function signature. More...
|
|
typedef std::function< void(const char *button_n, ISState state, void *context)> | buttonFunc |
| buttonFunc Button callback function signature. More...
|
|
|
| Controller (INDI::DefaultDevice *cdevice) |
| Controller Default ctor. More...
|
|
virtual | ~Controller () |
|
virtual void | ISGetProperties (const char *dev) |
|
virtual bool | initProperties () |
|
virtual bool | updateProperties () |
|
virtual bool | ISSnoopDevice (XMLEle *root) |
|
virtual bool | ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n) |
|
virtual bool | ISNewText (const char *dev, const char *name, char *texts[], char *names[], int n) |
|
virtual bool | saveConfigItems (FILE *fp) |
|
void | mapController (const char *propertyName, const char *propertyLabel, ControllerType type, const char *initialValue) |
| mapController adds a new property to the joystick's settings. More...
|
|
void | clearMap () |
| clearMap clears all properties added previously by mapController() More...
|
|
void | setJoystickCallback (joystickFunc joystickCallback) |
| setJoystickCallback Sets the callback function when a new joystick input is detected. More...
|
|
void | setAxisCallback (axisFunc axisCallback) |
| setAxisCallback Sets the callback function when a new axis input is detected. More...
|
|
void | setButtonCallback (buttonFunc buttonCallback) |
| setButtonCallback Sets the callback function when a new button input is detected. More...
|
|
ControllerType | getControllerType (const char *name) |
|
const char * | getControllerSetting (const char *name) |
|
|
static void | joystickEvent (const char *joystick_n, double mag, double angle, void *context) |
|
static void | axisEvent (const char *axis_n, int value, void *context) |
|
static void | buttonEvent (const char *button_n, int value, void *context) |
|
The Controller class provides functionality to access a controller (e.g. joystick) input and send it to the requesting driver.
- To use the class in an INDI::DefaultDevice based driver:
- Set the callback functions for each of input type requested.
- Map the properties you wish to /e listen to from the joystick driver by specifying the type of input requested and the initial default value. For example:
void mapController(const char *propertyName, const char *propertyLabel, ControllerType type, const char *initialValue)
mapController adds a new property to the joystick's settings.
After mapping all the desired controls, call the class initProperties() function. If the user enables joystick support in the driver and presses a button on the joystick, the button callback function will be invoked with the name & state of the button.
- Call the Controller's ISGetProperties(), initProperties(), updateProperties(), saveConfigItems(), and ISNewXXX functions from the same standard functions in your driver.
The class communicates with INDI joystick driver which in turn enumerates the game pad and provides three types of constrcuts:
-
Joysticks: Each joystick displays a normalized magnitude [0 to 1] and an angle. The angle is measured counter clock wise starting from the right/east direction [0 to 360]. They are defined as JOYSTICK_# where # is the joystick number.
-
Axes: Each joystick has two or more axes. Each axis has a raw value and angle. The raw value ranges from -32767.0 to 32767.0 They are defined as AXIS_# where # is the axis number.
-
Buttons: Buttons are either on or off. They are defined as BUTTON_# where # is the button number.
- Note
- All indexes start from 1. i.e. There is no BUTTON_0 or JOYSTICK_0.
- See also
- See the LX200 Generic & Celestron GPS drivers for an example implementation.
- Warning
- Both the indi_joystick driver and the driver using this class must be running in the same INDI server (or chained INDI servers) in order for it to work as it depends on snooping among drivers.
- Author
- Jasem Multaq
Definition at line 65 of file indicontroller.h.
◆ axisFunc
◆ buttonFunc
buttonFunc Button callback function signature.
Definition at line 83 of file indicontroller.h.
◆ joystickFunc
joystickFunc Joystick callback function signature.
Definition at line 73 of file indicontroller.h.
◆ ControllerType
Enumerator |
---|
CONTROLLER_JOYSTICK | |
CONTROLLER_AXIS | |
CONTROLLER_BUTTON | |
CONTROLLER_UNKNOWN | |
Definition at line 68 of file indicontroller.h.
◆ Controller()
◆ ~Controller()
INDI::Controller::~Controller |
( |
| ) |
|
|
virtual |
◆ axisEvent()
void INDI::Controller::axisEvent |
( |
const char * |
axis_n, |
|
|
int |
value, |
|
|
void * |
context |
|
) |
| |
|
staticprotected |
◆ buttonEvent()
void INDI::Controller::buttonEvent |
( |
const char * |
button_n, |
|
|
int |
value, |
|
|
void * |
context |
|
) |
| |
|
staticprotected |
◆ clearMap()
void INDI::Controller::clearMap |
( |
| ) |
|
◆ disableJoystick()
void INDI::Controller::disableJoystick |
( |
| ) |
|
|
protected |
◆ enableJoystick()
void INDI::Controller::enableJoystick |
( |
| ) |
|
|
protected |
◆ getControllerSetting()
const char * INDI::Controller::getControllerSetting |
( |
const char * |
name | ) |
|
◆ getControllerType()
◆ initProperties()
bool INDI::Controller::initProperties |
( |
| ) |
|
|
virtual |
◆ ISGetProperties()
void INDI::Controller::ISGetProperties |
( |
const char * |
dev | ) |
|
|
virtual |
◆ ISNewSwitch()
bool INDI::Controller::ISNewSwitch |
( |
const char * |
dev, |
|
|
const char * |
name, |
|
|
ISState * |
states, |
|
|
char * |
names[], |
|
|
int |
n |
|
) |
| |
|
virtual |
◆ ISNewText()
bool INDI::Controller::ISNewText |
( |
const char * |
dev, |
|
|
const char * |
name, |
|
|
char * |
texts[], |
|
|
char * |
names[], |
|
|
int |
n |
|
) |
| |
|
virtual |
◆ ISSnoopDevice()
bool INDI::Controller::ISSnoopDevice |
( |
XMLEle * |
root | ) |
|
|
virtual |
◆ joystickEvent()
void INDI::Controller::joystickEvent |
( |
const char * |
joystick_n, |
|
|
double |
mag, |
|
|
double |
angle, |
|
|
void * |
context |
|
) |
| |
|
staticprotected |
◆ mapController()
void INDI::Controller::mapController |
( |
const char * |
propertyName, |
|
|
const char * |
propertyLabel, |
|
|
ControllerType |
type, |
|
|
const char * |
initialValue |
|
) |
| |
mapController adds a new property to the joystick's settings.
- Parameters
-
propertyName | Name |
propertyLabel | Label |
type | The input type of the property. This value cannot be updated. |
initialValue | Initial value for the property. |
Definition at line 45 of file indicontroller.cpp.
◆ saveConfigItems()
bool INDI::Controller::saveConfigItems |
( |
FILE * |
fp | ) |
|
|
virtual |
◆ setAxisCallback()
void INDI::Controller::setAxisCallback |
( |
axisFunc |
axisCallback | ) |
|
setAxisCallback Sets the callback function when a new axis input is detected.
- Parameters
-
axisCallback | the callback function. |
Definition at line 319 of file indicontroller.cpp.
◆ setButtonCallback()
void INDI::Controller::setButtonCallback |
( |
buttonFunc |
buttonCallback | ) |
|
setButtonCallback Sets the callback function when a new button input is detected.
- Parameters
-
buttonCallback | the callback function. |
Definition at line 324 of file indicontroller.cpp.
◆ setJoystickCallback()
void INDI::Controller::setJoystickCallback |
( |
joystickFunc |
joystickCallback | ) |
|
setJoystickCallback Sets the callback function when a new joystick input is detected.
- Parameters
-
joystickCallback | the callback function. |
Definition at line 314 of file indicontroller.cpp.
◆ updateProperties()
bool INDI::Controller::updateProperties |
( |
| ) |
|
|
virtual |
◆ axisCallbackFunc
axisFunc INDI::Controller::axisCallbackFunc |
|
protected |
◆ buttonCallbackFunc
◆ device
◆ joystickCallbackFunc
The documentation for this class was generated from the following files: