Debian Codegraph @

src/joystick.hpp

raw
1 /*
2 ** jstest-gtk - A graphical joystick tester
3 ** Copyright (C) 2009 Ingo Ruhnke <[email protected]>
4 **
5 ** This program is free software: you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License as published by
7 ** the Free Software Foundation, either version 3 of the License, or
8 ** (at your option) any later version.
9 **
10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ** GNU General Public License for more details.
14 **
15 ** You should have received a copy of the GNU General Public License
16 ** along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #ifndef HEADER_JSTEST_GTK_JOYSTICK_HPP
20 #define HEADER_JSTEST_GTK_JOYSTICK_HPP
21
22 #include <sigc++/signal.h>
23 #include <sigc++/connection.h>
24 #include <glibmm/main.h>
25 #include <glibmm/ustring.h>
26 #include <linux/joystick.h>
27 #include "joystick_description.hpp"
28
29 class XMLReader;
30 class XMLWriter;
31
32 class Joystick
33 {
34 public:
35 struct CalibrationData {
36 bool calibrate;
37 bool invert;
38 int center_min;
39 int center_max;
40 int range_min;
41 int range_max;
42 };
43
44 private:
45 int fd;
46
47 std::string filename;
48 std::string orig_name;
49 Glib::ustring name;
50 int axis_count;
51 int button_count;
52
53 std::vector<int> axis_state;
54 std::vector<CalibrationData> orig_calibration_data;
55
56 sigc::connection connection;
57
58 public:
59 Joystick(const std::string& filename);
60 ~Joystick();
61
62 int get_fd() const { return fd; }
63
64 void update();
65 bool on_in(Glib::IOCondition cond);
66
67 std::string get_filename() const { return filename; }
68 Glib::ustring get_name() const { return name; }
69 int get_axis_count() const { return axis_count; }
70 int get_button_count() const { return button_count; }
71
72 sigc::signal<void, int, int> axis_move;
73 sigc::signal<void, int, bool> button_move;
74
75 int get_axis_state(int id);
76
77 static std::vector<JoystickDescription> get_joysticks();
78
79 std::vector<CalibrationData> get_calibration();
80 void set_calibration(const std::vector<CalibrationData>& data);
81 void reset_calibration();
82
83 /** Clears all calibration data, note that this will mean raw USB
84 input values, not values scaled to -32767/32767 */
85 void clear_calibration();
86
87 std::vector<int> get_button_mapping();
88 std::vector<int> get_axis_mapping();
89
90 void set_button_mapping(const std::vector<int>& mapping);
91 void set_axis_mapping(const std::vector<int>& mapping);
92
93 /** Corrects calibration data after remaping axes */
94 void correct_calibration(const std::vector<int>& mapping_old, const std::vector<int>& mapping_new);
95
96 void write(XMLWriter& out);
97 void load(const XMLReader& reader);
98
99 /** Get the evdev that this joystick device is based on. This call
100 is just a guess, not guranteed to be the exact same device, but
101 for our uses that should be enough. */
102 std::string get_evdev() const;
103
104 private:
105 Joystick(const Joystick&);
106 Joystick& operator=(const Joystick&);
107 };
108
109 #endif
110
111 /* EOF */