FlightGear next
FGJoystickInput.hxx
Go to the documentation of this file.
1// FGJoystickInput.hxx -- handle user input from joystick devices
2//
3// Written by Torsten Dreyer, started August 2009
4// Based on work from David Megginson, started May 2001.
5//
6// Copyright (C) 2009 Torsten Dreyer, Torsten (at) t3r _dot_ de
7// Copyright (C) 2001 David Megginson, david@megginson.com
8//
9// This program is free software; you can redistribute it and/or
10// modify it under the terms of the GNU General Public License as
11// published by the Free Software Foundation; either version 2 of the
12// License, or (at your option) any later version.
13//
14// This program is distributed in the hope that it will be useful, but
15// WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17// General Public License for more details.
18//
19// You should have received a copy of the GNU General Public License
20// along with this program; if not, write to the Free Software
21// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22//
23// $Id$
24
25#ifndef _FGJOYSTICKINPUT_HXX
26#define _FGJOYSTICKINPUT_HXX
27
28#include "FGCommonInput.hxx"
29#include "FGButton.hxx"
30
31#include <memory> // for std::unique_ptr
32#include <simgear/structure/subsystem_mgr.hxx>
33
34#include "FlightGear_js.h"
35
37// The Joystick Input Class
39class FGJoystickInput : public SGSubsystem,
41{
42public:
44 virtual ~FGJoystickInput();
45
46 // Subsystem API.
47 void init() override;
48 void postinit() override;
49 void reinit() override;
50 void update(double dt) override;
51
52 // Subsystem identification.
53 static const char* staticSubsystemClassId() { return "input-joystick"; }
54
55 static const int MAX_JOYSTICKS = 16;
56 static const int MAX_JOYSTICK_AXES = _JS_MAX_AXES;
57 static const int MAX_JOYSTICK_BUTTONS = 32;
58
59private:
69 std::string computeDeviceIndexName(const std::string &name, int lastIndex) const;
70
71 void _remove(bool all);
72 SGPropertyNode_ptr status_node;
73
77 struct axis {
78 axis ();
79 virtual ~axis ();
80 float last_value;
81 float tolerance;
82 binding_list_t bindings[KEYMOD_MAX];
83 float low_threshold;
84 float high_threshold;
85 FGButton low;
86 FGButton high;
87 float interval_sec, delay_sec, release_delay_sec;
88 double last_dt;
89 };
90
94 struct joystick {
95 joystick ();
96 virtual ~joystick ();
97 int jsnum;
98 std::unique_ptr<jsJoystick> plibJS;
99 int naxes;
100 int nbuttons;
101 axis * axes;
102 FGButton * buttons;
103 bool predefined;
104 bool initializing = true;
105 bool initialized = false;
106 float values[MAX_JOYSTICK_AXES];
107 double init_dt = 0.0f;
108
109 void clearAxesAndButtons();
110 };
111
112 joystick joysticks[MAX_JOYSTICKS];
113 void updateJoystick(int index, joystick* joy, double dt);
114};
115
116#endif
SGBindingList binding_list_t
static const int MAX_JOYSTICKS
static const char * staticSubsystemClassId()
void update(double dt) override
static const int MAX_JOYSTICK_AXES
void reinit() override
void postinit() override
static const int MAX_JOYSTICK_BUTTONS
virtual ~FGJoystickInput()
void init() override
const char * name
@ KEYMOD_MAX
Definition fg_os.hxx:32