Instrument Neutral Distributed Interface INDI  2.0.2
joystick.h
Go to the documentation of this file.
1 /*******************************************************************************
2  Copyright(c) 2013 Jasem Mutlaq. All rights reserved.
3 
4  This program is free software; you can redistribute it and/or modify it
5  under the terms of the GNU General Public License as published by the Free
6  Software Foundation; either version 2 of the License, or (at your option)
7  any later version.
8 
9  This program is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 
19  The full GNU General Public License is included in this distribution in the
20  file called LICENSE.
21 *******************************************************************************/
22 
23 #pragma once
24 
25 #include "defaultdevice.h"
26 #include <memory>
27 
28 class JoyStickDriver;
29 
36 {
37  public:
38  JoyStick();
39 
40  virtual bool initProperties() override;
41  virtual bool updateProperties() override;
42  virtual void ISGetProperties(const char *dev) override;
43  virtual bool ISSnoopDevice(XMLEle *root) override;
44  virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override;
45  virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
46 
47  static void joystickHelper(int joystick_n, double mag, double angle);
48  static void axisHelper(int axis_n, int value);
49  static void buttonHelper(int button_n, int value);
50 
51  protected:
52  // Generic indi device entries
53  virtual bool Connect() override;
54  virtual bool Disconnect() override;
55  virtual const char *getDefaultName() override;
56 
57  bool saveConfigItems(FILE *fp) override;
58 
59  void setupParams();
60 
61  void joystickEvent(int joystick_n, double mag, double angle);
62  void axisEvent(int axis_n, int value);
63  void buttonEvent(int button_n, int value);
64 
66  INumber *JoyStickN = nullptr;
67 
69  INumber *AxisN = nullptr;
70 
72  INumber *DeadZoneN = nullptr;
73 
75  ISwitch *ButtonS = nullptr;
76 
77  ITextVectorProperty PortTP; // A text vector that stores out physical port name
78  IText PortT[1] {};
79 
82 
83  std::unique_ptr<JoyStickDriver> driver;
84 };
Class to provide extended functionality for devices in addition to the functionality provided by INDI...
The JoyStickDriver class provides basic functionality to read events from supported game pads under L...
The JoyStick class provides an INDI driver that displays event data from game pads....
Definition: joystick.h:36
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
Definition: joystick.cpp:123
JoyStick()
Definition: joystick.cpp:34
ISwitchVectorProperty ButtonSP
Definition: joystick.h:74
IText PortT[1]
Definition: joystick.h:78
static void buttonHelper(int button_n, int value)
Definition: joystick.cpp:269
virtual bool Disconnect() override
Disconnect from device.
Definition: joystick.cpp:60
IText JoystickInfoT[5]
Definition: joystick.h:81
INumberVectorProperty AxisNP
Definition: joystick.h:68
std::unique_ptr< JoyStickDriver > driver
Definition: joystick.h:83
static void joystickHelper(int joystick_n, double mag, double angle)
Definition: joystick.cpp:264
bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
Definition: joystick.cpp:331
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition: joystick.cpp:248
virtual const char * getDefaultName() override
Definition: joystick.cpp:39
ITextVectorProperty PortTP
Definition: joystick.h:77
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: joystick.cpp:204
static void axisHelper(int axis_n, int value)
Definition: joystick.cpp:274
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition: joystick.cpp:143
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: joystick.cpp:223
void joystickEvent(int joystick_n, double mag, double angle)
Definition: joystick.cpp:279
INumberVectorProperty DeadZoneNP
Definition: joystick.h:71
ISwitch * ButtonS
Definition: joystick.h:75
INumber * AxisN
Definition: joystick.h:69
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
Definition: joystick.cpp:228
virtual bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
Definition: joystick.cpp:44
INumberVectorProperty * JoyStickNP
Definition: joystick.h:65
void axisEvent(int axis_n, int value)
Definition: joystick.cpp:297
void setupParams()
Definition: joystick.cpp:67
INumber * JoyStickN
Definition: joystick.h:66
ITextVectorProperty JoystickInfoTP
Definition: joystick.h:80
void buttonEvent(int button_n, int value)
Definition: joystick.cpp:318
INumber * DeadZoneN
Definition: joystick.h:72
One number descriptor.
One switch descriptor.
One text descriptor.
Number vector property descriptor.
Definition: indiapi.h:319
Switch vector property descriptor.
Definition: indiapi.h:367
Text vector property descriptor.
Definition: indiapi.h:246