Debian Codegraph @

src/joystick.cpp

raw symbols SCIP
1 // SPDX-FileCopyrightText: 2009 Ingo Ruhnke <[email protected]>cxx . . $ `<file>/src/joystick.cpp`/
2 // SPDX-FileCopyrightText: 2025 Raphael Rosch <[email protected]>
3 // SPDX-License-Identifier: GPL-3.0-or-later
4
5 #include <assert.h>
6 #include <math.h>
7 #include <algorithm>
8 #include <iostream>
9 #include <stdexcept>
10 #include <stdint.h>
11 #include <string.h>
12 #include <errno.h>
13 #include <sys/types.h>
14 #include <sys/stat.h>
15 #include <fcntl.h>
16 #include <string.h>
17 #include <sstream>
18 #include <unistd.h>
19 #include <linux/joystick.h>
20 #include <glibmm.h>
21
22 #include "evdev_helper.hpp"cxx . . $ `<file>/src/evdev_helper.hpp`/
23 #include "joystick.hpp"cxx . . $ `<file>/src/joystick.hpp`/
24 #include "main.hpp"cxx . . $ `<file>/src/main.hpp`/
25
26 stdcxx . . $ std/::stringcxx . . $ std/string# get_js_dev_id_from_filenamecxx . . $ get_js_dev_id_from_filename(fd626fc03107dd24).(const stdcxx . . $ std/::stringcxx . . $ std/string#& filename)
27 {
28 size_t pos = filename.find_last_ofcxx . . $ std/__cxx11/basic_string#find_last_of(625b4b37461b5dfd).('/');
29 if (pos == stdcxx . . $ std/::stringcxx . . $ std/string#::nposcxx . . $ std/__cxx11/basic_string#npos.)
30 {
31 return filenamecxx . . $ std/__cxx11/basic_string#basic_string(a47f53d4115f6ce5).; // No '/' found, return whole string
32 }
33 return filenamecxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f)..substrcxx . . $ std/__cxx11/basic_string#substr(149c655009c9bbd2).(pos + 1);
34 }
35
36 Joystickcxx . . $ Joystick#::Joystickcxx . . $ Joystick#Joystick(c3ca1c130ce09c52).(const stdcxx . . $ std/::stringcxx . . $ std/string#& filename_, const stdcxx . . $ std/::stringcxx . . $ std/string#& js_id_)
37 : filenamecxx . . $ Joystick#filename.(filename_),
38 js_idcxx . . $ Joystick#js_id.(js_id_)
39 {
40 fdcxx . . $ Joystick#fd. = get_new_joystick_fdcxx . . $ Joystick#get_new_joystick_fd(b126dc7c1de90089).(); // throws on failure
41
42 uint8_tcxx . . $ uint8_t# num_axis = 0;
43 uint8_tcxx . . $ uint8_t# num_button = 0;
44 ioctl(fdcxx . . $ Joystick#fd., JSIOCGAXEScxx . . $ `<external>/11922856331072503508/joystick.h:57:9`!, &num_axis);
45 ioctl(fdcxx . . $ Joystick#fd., JSIOCGBUTTONScxx . . $ `<external>/11922856331072503508/joystick.h:58:9`!, &num_button);
46 axis_countcxx . . $ Joystick#axis_count. = num_axis;
47 button_countcxx . . $ Joystick#button_count. = num_button;
48
49 // Get Name
50 char name_c_str[1024];
51 if (ioctl(fdcxx . . $ Joystick#fd., JSIOCGNAMEcxx . . $ `<external>/11922856331072503508/joystick.h:59:9`!(sizeof(name_c_str)), name_c_str) < 0)
52 {
53 stdcxx . . $ std/::ostringstreamcxx . . $ std/ostringstream# strcxx . . $ std/__cxx11/basic_ostringstream#basic_ostringstream(49f6e7a06ebc5aa8).;
54 str <<cxx . . $ std/`operator<<`(88df5bef833f7f83). filenamecxx . . $ Joystick#filename. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ": " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
55 throw stdcxx . . $ std/runtime_error#runtime_error(6be18eeaba0abf21).::runtime_errorcxx . . $ std/runtime_error#(str.strcxx . . $ std/__cxx11/basic_ostringstream#str(d33e1a6fd36255f7).());
56 }
57
58 orig_namecxx . . $ Joystick#orig_name. =cxx . . $ std/__cxx11/basic_string#`operator=`(978ca1133b5f6e74). name_c_str;
59 try {
60 namecxx . . $ Joystick#name. =cxx . . $ Glib/ustring#`operator=`(f1aadc30ccccd39a). Glibcxx . . $ Glib/::convert_with_fallbackcxx . . $ Glib/convert_with_fallback(e868d604ebdc78b4).(name_c_strcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., "UTF-8"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., "ISO-8859-1"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
61 } catch(Glibcxx . . $ Glib/::ConvertErrorcxx . . $ Glib/ConvertError#& err) {
62 stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ Glib/`operator<<`(d3a65685b7328161). err.whatcxx . . $ Glib/Error#what(fff0f585954e56f3).() <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).;
63 namecxx . . $ Joystick#name. =cxx . . $ Glib/ustring#`operator=`(6082a55360a9226). name_c_str;
64 }
65
66 axis_statecxx . . $ Joystick#axis_state..resizecxx . . $ std/vector#resize(2c44cd906ae4e829).(axis_countcxx . . $ Joystick#axis_count.);
67
68 auto tmp_usb_id_pair = get_usb_id_pair_from_udevcxx . . $ std/pair#pair(59816e23a2f1b31c).(js_idcxx . . $ Joystick#js_id.);
69 if (!tmp_usb_id_pair.firstcxx . . $ std/pair#first..emptycxx . . $ std/__cxx11/basic_string#empty(50ce9a9e25b4a850).() && !tmp_usb_id_pair.secondcxx . . $ std/pair#second..emptycxx . . $ std/__cxx11/basic_string#empty(50ce9a9e25b4a850).()) {
70 vendor_idcxx . . $ Joystick#vendor_id. =cxx . . $ std/__cxx11/basic_string#`operator=`(c0b47be1fddc0e75). tmp_usb_id_pair.firstcxx . . $ std/pair#first.;
71 product_idcxx . . $ Joystick#product_id. =cxx . . $ std/__cxx11/basic_string#`operator=`(c0b47be1fddc0e75). tmp_usb_id_pair.secondcxx . . $ std/pair#second.;
72 usb_idcxx . . $ Joystick#usb_id. =cxx . . $ std/__cxx11/basic_string#`operator=`(706c69e8c742c906). vendor_idcxx . . $ Joystick#vendor_id. +cxx . . $ std/operator+(40fc1db9226233c6). ":" +cxx . . $ std/operator+(db5dc2ea912c6495). product_idcxx . . $ Joystick#product_id.;
73 js_cfgcxx . . $ Joystick#js_cfg. =cxx . . $ JoystickConfig#`operator=`(314ca01250c6a6f2). get_config_for_usb_idcxx . . $ get_config_for_usb_id(846110c2b27fd439).(usb_idcxx . . $ Joystick#usb_id.);
74 js_typecxx . . $ Joystick#js_type. =cxx . . $ std/__cxx11/basic_string#`operator=`(706c69e8c742c906). get_js_type_from_configcxx . . $ Joystick#get_js_type_from_config(ae472d0fb84499ed).(js_cfgcxx . . $ Joystick#js_cfg.);
75 }
76 connect_jscxx . . $ Joystick#connect_js(49f6e7a06ebc5aa8).();
77 orig_calibration_datacxx . . $ Joystick#orig_calibration_data. =cxx . . $ std/vector#`operator=`(27b3db0518c64371). get_calibrationcxx . . $ Joystick#get_calibration(2ef09a8d9ed4db48).();
78 }
79
80 Joystickcxx . . $ Joystick#::~cxx . . $ Joystick#`~Joystick`(49f6e7a06ebc5aa8).Joystickcxx . . $ Joystick#()
81 {
82 connectioncxx . . $ Joystick#connection..disconnectcxx . . $ sigc/connection#disconnect(49f6e7a06ebc5aa8).();
83 if (fdcxx . . $ Joystick#fd. >= 0)
84 {
85 close(fdcxx . . $ Joystick#fd.);
86 fdcxx . . $ Joystick#fd. = -1;
87 }
88 }
89
90 int
91 Joystickcxx . . $ Joystick#::get_new_joystick_fdcxx . . $ Joystick#get_new_joystick_fd(b126dc7c1de90089).()
92 {
93 int tmp_fd = open(filenamecxx . . $ Joystick#filename..c_strcxx . . $ std/__cxx11/basic_string#c_str(1016ee5406d91ab9).(), O_RDONLYcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:43:9`!);
94 if (tmp_fd < 0)
95 {
96 stdcxx . . $ std/::ostringstreamcxx . . $ std/ostringstream# strcxx . . $ std/__cxx11/basic_ostringstream#basic_ostringstream(49f6e7a06ebc5aa8).;
97 str <<cxx . . $ std/`operator<<`(88df5bef833f7f83). filenamecxx . . $ Joystick#filename. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ": " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
98 throw stdcxx . . $ std/runtime_error#runtime_error(6be18eeaba0abf21).::runtime_errorcxx . . $ std/runtime_error#(str.strcxx . . $ std/__cxx11/basic_ostringstream#str(d33e1a6fd36255f7).());
99 }
100 return tmp_fd;
101 }
102
103 void
104 Joystickcxx . . $ Joystick#::connect_jscxx . . $ Joystick#connect_js(49f6e7a06ebc5aa8).()
105 {
106 connectioncxx . . $ Joystick#connection. =cxx . . $ sigc/connection#`operator=`(d6e79c7c2c834e86). Glibcxx . . $ Glib/::signal_iocxx . . $ Glib/signal_io(8fdd6778f26497b6).().connectcxx . . $ Glib/SignalIO#connect(450bbd9c2fea62e7).(sigccxx . . $ sigc/slot#slot(edcd8b2679e9bd1a).::mem_funcxx . . $ sigc/mem_fun(6f5a0390fdf5a127).(this, &Joystickcxx . . $ Joystick#::on_incxx . . $ Joystick#on_in(eeaa91d3ba1dceee).), fdcxx . . $ Joystick#fd.,
107 Glibcxx . . $ Glib/::IO_INcxx . . $ Glib/IO_IN. |cxx . . $ Glib/`operator|`(58ad2238cafe6385). Glibcxx . . $ Glib/::IO_HUPcxx . . $ Glib/IO_HUP. |cxx . . $ Glib/`operator|`(58ad2238cafe6385). Glibcxx . . $ Glib/::IO_ERRcxx . . $ Glib/IO_ERR.);
108 }
109
110 bool
111 Joystickcxx . . $ Joystick#::try_adopt_devicecxx . . $ Joystick#try_adopt_device(1667653f663d0d88).(const stdcxx . . $ std/::stringcxx . . $ std/string#& path, const stdcxx . . $ std/::stringcxx . . $ std/string#& new_js_id)
112 {
113 int tmp_fd = open(path.c_strcxx . . $ std/__cxx11/basic_string#c_str(1016ee5406d91ab9).(), O_RDONLYcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:43:9`!);
114 if (tmp_fd < 0)
115 return false;
116
117 char name_c_str[1024];
118 if (ioctl(tmp_fd, JSIOCGNAMEcxx . . $ `<external>/11922856331072503508/joystick.h:59:9`!(sizeof(name_c_str)), name_c_str) < 0)
119 {
120 close(tmp_fd);
121 return false;
122 }
123 if (orig_namecxx . . $ Joystick#orig_name. !=cxx . . $ std/`operator!=`(4b17aa87c9f300c6). name_c_str)
124 {
125 close(tmp_fd);
126 return false;
127 }
128
129 auto tmp_usb_id_pair = get_usb_id_pair_from_udevcxx . . $ std/pair#pair(59816e23a2f1b31c).(new_js_id);
130 stdcxx . . $ std/::stringcxx . . $ std/string# tmp_usb_id = tmp_usb_id_paircxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f)..firstcxx . . $ std/pair#first. +cxx . . $ std/operator+(40fc1db9226233c6). ":" +cxx . . $ std/operator+(db5dc2ea912c6495). tmp_usb_id_pair.secondcxx . . $ std/pair#second.;
131 if (!usb_idcxx . . $ Joystick#usb_id..emptycxx . . $ std/__cxx11/basic_string#empty(50ce9a9e25b4a850).() && tmp_usb_id !=cxx . . $ std/`operator!=`(2965e344aacb545b). usb_idcxx . . $ Joystick#usb_id.)
132 {
133 close(tmp_fd);
134 return false;
135 }
136
137 if (fdcxx . . $ Joystick#fd. >= 0)
138 close(fdcxx . . $ Joystick#fd.);
139 connectioncxx . . $ Joystick#connection..disconnectcxx . . $ sigc/connection#disconnect(49f6e7a06ebc5aa8).();
140
141 fdcxx . . $ Joystick#fd. = tmp_fd;
142 filenamecxx . . $ Joystick#filename. =cxx . . $ std/__cxx11/basic_string#`operator=`(c0b47be1fddc0e75). path;
143 js_idcxx . . $ Joystick#js_id. =cxx . . $ std/__cxx11/basic_string#`operator=`(c0b47be1fddc0e75). new_js_id;
144 connect_jscxx . . $ Joystick#connect_js(49f6e7a06ebc5aa8).();
145 return true;
146 }
147
148 bool
149 Joystickcxx . . $ Joystick#::reconnectedcxx . . $ Joystick#reconnected(c9857a73d68e59ba).()
150 {
151 // Prefer the original node, then scan js0..js31 for the same identity
152 // (name + USB id) so replug order changes can still recover.
153 if (m_verbosecxx . . $ m_verbose.)
154 stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "attempting joystick reconnect... " <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).;
155
156 if (try_adopt_devicecxx . . $ Joystick#try_adopt_device(1667653f663d0d88).(filenamecxx . . $ Joystick#filename., js_idcxx . . $ Joystick#js_id.))
157 {
158 if (m_verbosecxx . . $ m_verbose.)
159 stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "reconnected on " <<cxx . . $ std/`operator<<`(88df5bef833f7f83). filenamecxx . . $ Joystick#filename. <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).;
160 return true;
161 }
162
163 for (int i = 0; i < 32; ++i)
164 {
165 stdcxx . . $ std/::stringcxx . . $ std/string# id = "js"cxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f). +cxx . . $ std/operator+(39ed2c165380f78e). stdcxx . . $ std/::to_stringcxx . . $ std/__cxx11/to_string(7eb93f795f0defb3).(i);
166 stdcxx . . $ std/::stringcxx . . $ std/string# path = "/dev/input/"cxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f). +cxx . . $ std/operator+(42c652dfebe55ad7). id;
167 if (path ==cxx . . $ std/`operator==`(2965e344aacb545b). filenamecxx . . $ Joystick#filename.)
168 continue;
169 if (!Glibcxx . . $ Glib/::file_testcxx . . $ Glib/file_test(60aaef9f7bdf1611).(path, Glibcxx . . $ Glib/::FILE_TEST_EXISTScxx . . $ Glib/FILE_TEST_EXISTS.))
170 continue;
171 if (try_adopt_devicecxx . . $ Joystick#try_adopt_device(1667653f663d0d88).(path, id))
172 {
173 if (m_verbosecxx . . $ m_verbose.)
174 stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "reconnected on " <<cxx . . $ std/`operator<<`(88df5bef833f7f83). path <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " (was rescanned)" <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).;
175 return true;
176 }
177 }
178
179 if (m_verbosecxx . . $ m_verbose.)
180 stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "reconnect failed for " <<cxx . . $ std/`operator<<`(88df5bef833f7f83). orig_namecxx . . $ Joystick#orig_name. <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).;
181 return false;
182 }
183
184
185 stdcxx . . $ std/::paircxx . . $ std/pair#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::stringcxx . . $ std/string#>
186 Joystickcxx . . $ Joystick#::get_usb_id_pair_from_udevcxx . . $ Joystick#get_usb_id_pair_from_udev(a72b7ff781e8654f).(const stdcxx . . $ std/::stringcxx . . $ std/string#& sysname)
187 {
188 struct udev* udev = udev_new();
189 if (!udev)
190 {
191 stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "udev: Cannot create udev" <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).;
192 return {cxx . . $ std/pair#pair(49f6e7a06ebc5aa8).};
193 }
194
195 struct udev_device* input_dev =
196 udev_device_new_from_subsystem_sysname(udev, "input", sysname.c_strcxx . . $ std/__cxx11/basic_string#c_str(1016ee5406d91ab9).());
197 if (!input_dev)
198 {
199 stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(88df5bef833f7f83). filenamecxx . . $ Joystick#filename. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ": udev: Unable to find input device " <<cxx . . $ std/`operator<<`(88df5bef833f7f83). js_idcxx . . $ Joystick#js_id. <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).;
200 udev_unref(udev);
201 return {cxx . . $ std/pair#pair(49f6e7a06ebc5aa8).};
202 }
203
204 // Borrowed reference; do not unref
205 struct udev_device* dev =
206 udev_device_get_parent_with_subsystem_devtype(input_dev, "usb", "usb_device");
207 if (!dev)
208 {
209 stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(88df5bef833f7f83). filenamecxx . . $ Joystick#filename. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ": udev: Unable to find parent USB device" <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).;
210 udev_device_unref(input_dev);
211 udev_unref(udev);
212 return {cxx . . $ std/pair#pair(49f6e7a06ebc5aa8).};
213 }
214
215 const char* vid = udev_device_get_sysattr_value(dev, "idVendor");
216 const char* pid = udev_device_get_sysattr_value(dev, "idProduct");
217 stdcxx . . $ std/::stringcxx . . $ std/string# tmp_vendor_idcxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f). = vidcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d). ? vid : "";
218 stdcxx . . $ std/::stringcxx . . $ std/string# tmp_product_idcxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f). = pidcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d). ? pid : "";
219
220 udev_device_unref(input_dev);
221 udev_unref(udev);
222 return {cxx . . $ std/pair#pair(14d64bafa7379ebc).tmp_vendor_id, tmp_product_id};
223 }
224
225 bool
226 Joystickcxx . . $ Joystick#::on_incxx . . $ Joystick#on_in(eeaa91d3ba1dceee).(Glibcxx . . $ Glib/::IOConditioncxx . . $ Glib/IOCondition# cond)
227 {
228 if (cond &cxx . . $ Glib/`operator&`(58ad2238cafe6385). Glibcxx . . $ Glib/::IO_INcxx . . $ Glib/IO_IN.)
229 {
230 updatecxx . . $ Joystick#update(49f6e7a06ebc5aa8).();
231 }
232
233 if (cond &cxx . . $ Glib/`operator&`(58ad2238cafe6385). Glibcxx . . $ Glib/::IO_HUPcxx . . $ Glib/IO_HUP.)
234 {
235 stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(88df5bef833f7f83). filenamecxx . . $ Joystick#filename. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ": joystick got disconnected" <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).;
236 connectioncxx . . $ Joystick#connection..disconnectcxx . . $ sigc/connection#disconnect(49f6e7a06ebc5aa8).();
237 }
238
239 if (cond &cxx . . $ Glib/`operator&`(58ad2238cafe6385). Glibcxx . . $ Glib/::IO_ERRcxx . . $ Glib/IO_ERR.)
240 {
241 stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(88df5bef833f7f83). filenamecxx . . $ Joystick#filename. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ": error while reading from joystick" <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).;
242 connectioncxx . . $ Joystick#connection..disconnectcxx . . $ sigc/connection#disconnect(49f6e7a06ebc5aa8).();
243 }
244
245 return true;
246 }
247
248 void
249 Joystickcxx . . $ Joystick#::updatecxx . . $ Joystick#update(49f6e7a06ebc5aa8).()
250 {
251 struct js_eventcxx . . $ js_event# event;
252
253 ssize_t len = read(fdcxx . . $ Joystick#fd., &event, sizeof(event));
254
255 if (len < 0)
256 {
257 stdcxx . . $ std/::ostringstreamcxx . . $ std/ostringstream# strcxx . . $ std/__cxx11/basic_ostringstream#basic_ostringstream(49f6e7a06ebc5aa8).;
258 str <<cxx . . $ std/`operator<<`(88df5bef833f7f83). filenamecxx . . $ Joystick#filename. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ": " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
259 throw stdcxx . . $ std/runtime_error#runtime_error(6be18eeaba0abf21).::runtime_errorcxx . . $ std/runtime_error#(str.strcxx . . $ std/__cxx11/basic_ostringstream#str(d33e1a6fd36255f7).());
260 }
261 else if (len == sizeof(event))
262 { // ok
263 if (event.typecxx . . $ js_event#type. & JS_EVENT_AXIScxx . . $ `<external>/11922856331072503508/joystick.h:41:9`!)
264 {
265 //std::cout << "Axis: " << (int)event.number << " -> " << (int)event.value << std::endl;
266 axis_statecxx . . $ Joystick#axis_state.[cxx . . $ std/vector#`operator[]`(428bb168810b9e52).event.numbercxx . . $ js_event#number.] = event.valuecxx . . $ js_event#value.;
267 axis_movecxx . . $ Joystick#axis_move.(cxx . . $ sigc/signal2#`operator()`(23fa8672da8e2eb7).event.numbercxx . . $ js_event#number., event.valuecxx . . $ js_event#value.);
268 }
269 else if (event.typecxx . . $ js_event#type. & JS_EVENT_BUTTONcxx . . $ `<external>/11922856331072503508/joystick.h:40:9`!)
270 {
271 //std::cout << "Button: " << (int)event.number << " -> " << (int)event.value << std::endl;
272 button_presscxx . . $ Joystick#button_press.(cxx . . $ sigc/signal2#`operator()`(23fa8672da8e2eb7).event.numbercxx . . $ js_event#number., event.valuecxx . . $ js_event#value.);
273 }
274 }
275 else
276 {
277 throw stdcxx . . $ std/runtime_error#runtime_error(6be18eeaba0abf21).::runtime_errorcxx . . $ std/runtime_error#("Joystick::update(): unknown read error");
278 }
279 }
280
281 stdcxx . . $ std/::vectorcxx . . $ std/vector#<JoystickDescriptioncxx . . $ JoystickDescription#>
282 Joystickcxx . . $ Joystick#::get_joystickscxx . . $ Joystick#get_joysticks(53f4d129233960e1).()
283 {
284 stdcxx . . $ std/::vectorcxx . . $ std/vector#<JoystickDescriptioncxx . . $ JoystickDescription#> joystickscxx . . $ std/vector#vector(49f6e7a06ebc5aa8).;
285
286 for(int i = 0; i < 32; ++i)
287 {
288 try
289 {
290 stdcxx . . $ std/::stringcxx . . $ std/string# js_id = stdcxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f).::stringcxx . . $ std/string#("js") +cxx . . $ std/operator+(aa1c00e85b87da6b). stdcxx . . $ std/::to_stringcxx . . $ std/__cxx11/to_string(7eb93f795f0defb3).(i);
291 stdcxx . . $ std/::stringcxx . . $ std/string# str = stdcxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f).::stringcxx . . $ std/string#("/dev/input/") +cxx . . $ std/operator+(db5dc2ea912c6495). js_id;
292
293 if (Glibcxx . . $ Glib/::file_testcxx . . $ Glib/file_test(60aaef9f7bdf1611).(str, Glibcxx . . $ Glib/::FILE_TEST_EXISTScxx . . $ Glib/FILE_TEST_EXISTS.))
294 {
295 Joystickcxx . . $ Joystick# joystickcxx . . $ Joystick#Joystick(c3ca1c130ce09c52).(str, js_id);
296
297 joysticks.push_backcxx . . $ std/vector#push_back(fe7a8a4d1eddb70).(JoystickDescriptioncxx . . $ JoystickDescription#JoystickDescription(b0ad3453320d5607).(joystick.get_filenamecxx . . $ Joystick#get_filename(219584694fe2b248).(),
298 joystick.get_namecxx . . $ Joystick#get_name(fff0f585954e56f3).(),
299 joystick.get_js_idcxx . . $ Joystick#get_js_id(219584694fe2b248).(),
300 joystick.get_vendor_idcxx . . $ Joystick#get_vendor_id(219584694fe2b248).(),
301 joystick.get_product_idcxx . . $ Joystick#get_product_id(219584694fe2b248).(),
302 joystick.get_usb_idcxx . . $ Joystick#get_usb_id(219584694fe2b248).(),
303 joystick.get_axis_countcxx . . $ Joystick#get_axis_count(455f465bc33b4cdf).(),
304 joystick.get_button_countcxx . . $ Joystick#get_button_count(455f465bc33b4cdf).()));
305 }
306 }
307 catch(stdcxx . . $ std/::exception& err)
308 {
309 // ok
310 }
311 }
312
313 return joystickscxx . . $ std/vector#vector(b1ea180184b47f03).;
314 }
315
316 Joystickcxx . . $ Joystick#::CalibrationDatacxx . . $ Joystick#CalibrationData# corr2calcxx . . $ corr2cal(22040f2930458bb3).(const struct js_corrcxx . . $ js_corr#& corr_)
317 {
318 struct js_corrcxx . . $ js_corr# corr = corr_;
319
320 Joystickcxx . . $ Joystick#::CalibrationDatacxx . . $ Joystick#CalibrationData# data;
321
322 if (corr.typecxx . . $ js_corr#type.)
323 {
324 data.calibratecxx . . $ Joystick#CalibrationData#calibrate. = true;
325 data.invertcxx . . $ Joystick#CalibrationData#invert. = (corr.coefcxx . . $ js_corr#coef.[2] < 0 && corr.coefcxx . . $ js_corr#coef.[3] < 0);
326 data.center_mincxx . . $ Joystick#CalibrationData#center_min. = corr.coefcxx . . $ js_corr#coef.[0];
327 data.center_maxcxx . . $ Joystick#CalibrationData#center_max. = corr.coefcxx . . $ js_corr#coef.[1];
328
329 if (data.invertcxx . . $ Joystick#CalibrationData#invert.)
330 {
331 corr.coefcxx . . $ js_corr#coef.[2] = -corr.coefcxx . . $ js_corr#coef.[2];
332 corr.coefcxx . . $ js_corr#coef.[3] = -corr.coefcxx . . $ js_corr#coef.[3];
333 }
334
335 // Need to use double and rint(), since calculation doesn't end
336 // up on clean integer positions (i.e. 0.9999 can happen)
337 data.range_mincxx . . $ Joystick#CalibrationData#range_min. = rintcxx . . $ rint(447c67c6676f75c3).(data.center_mincxx . . $ Joystick#CalibrationData#center_min. - ((32767.0 * 16384) / corr.coefcxx . . $ js_corr#coef.[2]));
338 data.range_maxcxx . . $ Joystick#CalibrationData#range_max. = rintcxx . . $ rint(447c67c6676f75c3).((32767.0 * 16384) / corr.coefcxx . . $ js_corr#coef.[3] + data.center_maxcxx . . $ Joystick#CalibrationData#center_max.);
339 }
340 else
341 {
342 data.calibratecxx . . $ Joystick#CalibrationData#calibrate. = false;
343 data.invertcxx . . $ Joystick#CalibrationData#invert. = false;
344 data.center_mincxx . . $ Joystick#CalibrationData#center_min. = 0;
345 data.center_maxcxx . . $ Joystick#CalibrationData#center_max. = 0;
346 data.range_mincxx . . $ Joystick#CalibrationData#range_min. = 0;
347 data.range_maxcxx . . $ Joystick#CalibrationData#range_max. = 0;
348 }
349
350 return data;
351 }
352
353 stdcxx . . $ std/::vectorcxx . . $ std/vector#<Joystickcxx . . $ Joystick#::CalibrationDatacxx . . $ Joystick#CalibrationData#>
354 Joystickcxx . . $ Joystick#::get_calibrationcxx . . $ Joystick#get_calibration(2ef09a8d9ed4db48).()
355 {
356 stdcxx . . $ std/::vectorcxx . . $ std/vector#<struct js_corrcxx . . $ js_corr#> corrcxx . . $ std/vector#vector(83fdeebbe0501a83).(get_axis_countcxx . . $ Joystick#get_axis_count(455f465bc33b4cdf).());
357
358 if (ioctl(fdcxx . . $ Joystick#fd., JSIOCGCORRcxx . . $ `<external>/11922856331072503508/joystick.h:62:9`!, &*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).corr.begincxx . . $ std/vector#begin(33b10a496a38335b).()) < 0)
359 {
360 stdcxx . . $ std/::ostringstreamcxx . . $ std/ostringstream# strcxx . . $ std/__cxx11/basic_ostringstream#basic_ostringstream(49f6e7a06ebc5aa8).;
361 str <<cxx . . $ std/`operator<<`(88df5bef833f7f83). filenamecxx . . $ Joystick#filename. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ": " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
362 throw stdcxx . . $ std/runtime_error#runtime_error(6be18eeaba0abf21).::runtime_errorcxx . . $ std/runtime_error#(str.strcxx . . $ std/__cxx11/basic_ostringstream#str(d33e1a6fd36255f7).());
363 }
364 else
365 {
366 stdcxx . . $ std/::vectorcxx . . $ std/vector#<CalibrationDatacxx . . $ Joystick#CalibrationData#> datacxx . . $ std/vector#vector(49f6e7a06ebc5aa8).;
367 stdcxx . . $ std/::transformcxx . . $ std/transform(da30451c4a040264).(corr.begincxx . . $ std/vector#begin(33b10a496a38335b).(), corr.endcxx . . $ std/vector#end(33b10a496a38335b).(), stdcxx . . $ std/::back_insertercxx . . $ std/back_inserter(7b559d6bdd90ff74).(data), corr2calcxx . . $ corr2cal(22040f2930458bb3).);
368 return datacxx . . $ std/vector#vector(b1ea180184b47f03).;
369 }
370 }
371
372 struct js_corrcxx . . $ js_corr# cal2corrcxx . . $ cal2corr(bf04f4590f5a340e).(const Joystickcxx . . $ Joystick#::CalibrationDatacxx . . $ Joystick#CalibrationData#& data)
373 {
374 struct js_corrcxx . . $ js_corr# corr;
375
376 if (data.calibratecxx . . $ Joystick#CalibrationData#calibrate. &&
377 (data.center_mincxx . . $ Joystick#CalibrationData#center_min. - data.range_mincxx . . $ Joystick#CalibrationData#range_min.) != 0 &&
378 (data.range_maxcxx . . $ Joystick#CalibrationData#range_max. - data.center_maxcxx . . $ Joystick#CalibrationData#center_max.) != 0)
379 {
380 corr.typecxx . . $ js_corr#type. = 1;
381 corr.preccxx . . $ js_corr#prec. = 0;
382 corr.coefcxx . . $ js_corr#coef.[0] = data.center_mincxx . . $ Joystick#CalibrationData#center_min.;
383 corr.coefcxx . . $ js_corr#coef.[1] = data.center_maxcxx . . $ Joystick#CalibrationData#center_max.;
384
385 corr.coefcxx . . $ js_corr#coef.[2] = (32767 * 16384) / (data.center_mincxx . . $ Joystick#CalibrationData#center_min. - data.range_mincxx . . $ Joystick#CalibrationData#range_min.);
386 corr.coefcxx . . $ js_corr#coef.[3] = (32767 * 16384) / (data.range_maxcxx . . $ Joystick#CalibrationData#range_max. - data.center_maxcxx . . $ Joystick#CalibrationData#center_max.);
387
388 if (data.invertcxx . . $ Joystick#CalibrationData#invert.)
389 {
390 corr.coefcxx . . $ js_corr#coef.[2] = -corr.coefcxx . . $ js_corr#coef.[2];
391 corr.coefcxx . . $ js_corr#coef.[3] = -corr.coefcxx . . $ js_corr#coef.[3];
392 }
393 }
394 else
395 {
396 corr.typecxx . . $ js_corr#type. = 0;
397 corr.preccxx . . $ js_corr#prec. = 0;
398 memset(corr.coefcxx . . $ js_corr#coef., 0, sizeof(corr.coefcxx . . $ js_corr#coef.));
399 }
400
401 return corr;
402 }
403
404 void
405 Joystickcxx . . $ Joystick#::set_calibrationcxx . . $ Joystick#set_calibration(6fc732b2aab18c50).(const stdcxx . . $ std/::vectorcxx . . $ std/vector#<CalibrationDatacxx . . $ Joystick#CalibrationData#>& data)
406 {
407 stdcxx . . $ std/::vectorcxx . . $ std/vector#<struct js_corrcxx . . $ js_corr#> corrcxx . . $ std/vector#vector(49f6e7a06ebc5aa8).;
408
409 stdcxx . . $ std/::transformcxx . . $ std/transform(da30451c4a040264).(data.begincxx . . $ std/vector#begin(359ca5030082c9f).(), data.endcxx . . $ std/vector#end(359ca5030082c9f).(), stdcxx . . $ std/::back_insertercxx . . $ std/back_inserter(7b559d6bdd90ff74).(corr), cal2corrcxx . . $ cal2corr(bf04f4590f5a340e).);
410
411 if (ioctl(fdcxx . . $ Joystick#fd., JSIOCSCORRcxx . . $ `<external>/11922856331072503508/joystick.h:61:9`!, &*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).corr.begincxx . . $ std/vector#begin(33b10a496a38335b).()) < 0)
412 {
413 stdcxx . . $ std/::ostringstreamcxx . . $ std/ostringstream# strcxx . . $ std/__cxx11/basic_ostringstream#basic_ostringstream(49f6e7a06ebc5aa8).;
414 str <<cxx . . $ std/`operator<<`(88df5bef833f7f83). filenamecxx . . $ Joystick#filename. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ": " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
415 throw stdcxx . . $ std/runtime_error#runtime_error(6be18eeaba0abf21).::runtime_errorcxx . . $ std/runtime_error#(str.strcxx . . $ std/__cxx11/basic_ostringstream#str(d33e1a6fd36255f7).());
416 }
417 }
418
419 void
420 Joystickcxx . . $ Joystick#::clear_calibrationcxx . . $ Joystick#clear_calibration(49f6e7a06ebc5aa8).()
421 {
422 stdcxx . . $ std/::vectorcxx . . $ std/vector#<CalibrationDatacxx . . $ Joystick#CalibrationData#> datacxx . . $ std/vector#vector(49f6e7a06ebc5aa8).;
423
424 for(int i = 0; i < get_axis_countcxx . . $ Joystick#get_axis_count(455f465bc33b4cdf).(); ++i)
425 {
426 CalibrationDatacxx . . $ Joystick#CalibrationData# cal;
427
428 cal.calibratecxx . . $ Joystick#CalibrationData#calibrate. = false;
429 cal.invertcxx . . $ Joystick#CalibrationData#invert. = false;
430 cal.center_mincxx . . $ Joystick#CalibrationData#center_min. = 0;
431 cal.center_maxcxx . . $ Joystick#CalibrationData#center_max. = 0;
432 cal.range_mincxx . . $ Joystick#CalibrationData#range_min. = 0;
433 cal.range_maxcxx . . $ Joystick#CalibrationData#range_max. = 0;
434
435 data.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(cal);
436 }
437
438 set_calibrationcxx . . $ Joystick#set_calibration(6fc732b2aab18c50).(data);
439 }
440
441 void
442 Joystickcxx . . $ Joystick#::reset_calibrationcxx . . $ Joystick#reset_calibration(49f6e7a06ebc5aa8).()
443 {
444 set_calibrationcxx . . $ Joystick#set_calibration(6fc732b2aab18c50).(orig_calibration_datacxx . . $ Joystick#orig_calibration_data.);
445 }
446
447 stdcxx . . $ std/::vectorcxx . . $ std/vector#<int>
448 Joystickcxx . . $ Joystick#::get_button_mappingcxx . . $ Joystick#get_button_mapping(95cc8889724c44b9).()
449 {
450 uint16_tcxx . . $ uint16_t# btnmap[KEY_MAXcxx . . $ `<external>/16711976702688784642/input-event-codes.h:837:9`! - BTN_MISCcxx . . $ `<external>/16711976702688784642/input-event-codes.h:344:9`! + 1];
451 if (ioctl(fdcxx . . $ Joystick#fd., JSIOCGBTNMAPcxx . . $ `<external>/11922856331072503508/joystick.h:67:9`!, btnmap) < 0)
452 {
453 stdcxx . . $ std/::ostringstreamcxx . . $ std/ostringstream# strcxx . . $ std/__cxx11/basic_ostringstream#basic_ostringstream(49f6e7a06ebc5aa8).;
454 str <<cxx . . $ std/`operator<<`(88df5bef833f7f83). filenamecxx . . $ Joystick#filename. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ": " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
455 throw stdcxx . . $ std/runtime_error#runtime_error(6be18eeaba0abf21).::runtime_errorcxx . . $ std/runtime_error#(str.strcxx . . $ std/__cxx11/basic_ostringstream#str(d33e1a6fd36255f7).());
456 }
457 else
458 {
459 stdcxx . . $ std/::vectorcxx . . $ std/vector#<int> mappingcxx . . $ std/vector#vector(49f6e7a06ebc5aa8).;
460 stdcxx . . $ std/::copycxx . . $ std/copy(88304b602929f6f4).(btnmap, btnmap + button_countcxx . . $ Joystick#button_count., stdcxx . . $ std/::back_insertercxx . . $ std/back_inserter(7b559d6bdd90ff74).(mapping));
461 return mappingcxx . . $ std/vector#vector(b1ea180184b47f03).;
462 }
463 }
464
465 stdcxx . . $ std/::vectorcxx . . $ std/vector#<int>
466 Joystickcxx . . $ Joystick#::get_axis_mappingcxx . . $ Joystick#get_axis_mapping(95cc8889724c44b9).()
467 {
468 uint8_tcxx . . $ uint8_t# axismap[ABS_MAXcxx . . $ `<external>/16711976702688784642/input-event-codes.h:928:9`! + 1];
469 if (ioctl(fdcxx . . $ Joystick#fd., JSIOCGAXMAPcxx . . $ `<external>/11922856331072503508/joystick.h:65:9`!, axismap) < 0)
470 {
471 stdcxx . . $ std/::ostringstreamcxx . . $ std/ostringstream# strcxx . . $ std/__cxx11/basic_ostringstream#basic_ostringstream(49f6e7a06ebc5aa8).;
472 str <<cxx . . $ std/`operator<<`(88df5bef833f7f83). filenamecxx . . $ Joystick#filename. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ": " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
473 throw stdcxx . . $ std/runtime_error#runtime_error(6be18eeaba0abf21).::runtime_errorcxx . . $ std/runtime_error#(str.strcxx . . $ std/__cxx11/basic_ostringstream#str(d33e1a6fd36255f7).());
474 }
475 else
476 {
477 stdcxx . . $ std/::vectorcxx . . $ std/vector#<int> mappingcxx . . $ std/vector#vector(49f6e7a06ebc5aa8).;
478 stdcxx . . $ std/::copycxx . . $ std/copy(88304b602929f6f4).(axismap, axismap + axis_countcxx . . $ Joystick#axis_count., stdcxx . . $ std/::back_insertercxx . . $ std/back_inserter(7b559d6bdd90ff74).(mapping));
479 return mappingcxx . . $ std/vector#vector(b1ea180184b47f03).;
480 }
481 }
482
483 void
484 Joystickcxx . . $ Joystick#::set_button_mappingcxx . . $ Joystick#set_button_mapping(ae0b87eb58a4c9e5).(const stdcxx . . $ std/::vectorcxx . . $ std/vector#<int>& mapping)
485 {
486 assertcxx . . $ `<external>/4398592474888995393/assert.h:137:11`!((int)mapping.size() == button_count);
487
488 uint16_tcxx . . $ uint16_t# btnmap[KEY_MAXcxx . . $ `<external>/16711976702688784642/input-event-codes.h:837:9`! - BTN_MISCcxx . . $ `<external>/16711976702688784642/input-event-codes.h:344:9`! + 1];
489 memset(btnmap, 0, sizeof(btnmap));
490 stdcxx . . $ std/::copycxx . . $ std/copy(88304b602929f6f4).(mapping.begincxx . . $ std/vector#begin(359ca5030082c9f).(), mapping.endcxx . . $ std/vector#end(359ca5030082c9f).(), btnmap);
491
492 if (0)
493 for(int i = 0; i < button_countcxx . . $ Joystick#button_count.; ++i)
494 {
495 stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). i <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " -> " <<cxx . . $ std/basic_ostream#`operator<<`(9f4dd0ebeeaaa173). btnmap[i] <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).;
496 }
497
498 if (ioctl(fdcxx . . $ Joystick#fd., JSIOCSBTNMAPcxx . . $ `<external>/11922856331072503508/joystick.h:66:9`!, btnmap) < 0)
499 {
500 stdcxx . . $ std/::ostringstreamcxx . . $ std/ostringstream# strcxx . . $ std/__cxx11/basic_ostringstream#basic_ostringstream(49f6e7a06ebc5aa8).;
501 str <<cxx . . $ std/`operator<<`(88df5bef833f7f83). filenamecxx . . $ Joystick#filename. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ": " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
502 throw stdcxx . . $ std/runtime_error#runtime_error(6be18eeaba0abf21).::runtime_errorcxx . . $ std/runtime_error#(str.strcxx . . $ std/__cxx11/basic_ostringstream#str(d33e1a6fd36255f7).());
503 }
504 }
505
506 int
507 Joystickcxx . . $ Joystick#::get_axis_statecxx . . $ Joystick#get_axis_state(7864480464b09eea).(int id)
508 {
509 if (id >= 0 && id < (int)axis_statecxx . . $ Joystick#axis_state..sizecxx . . $ std/vector#size(fe4d2d262d4164a8).())
510 return axis_statecxx . . $ Joystick#axis_state.[cxx . . $ std/vector#`operator[]`(428bb168810b9e52).id];
511 else
512 return 0;
513 }
514
515 void
516 Joystickcxx . . $ Joystick#::set_axis_mappingcxx . . $ Joystick#set_axis_mapping(ae0b87eb58a4c9e5).(const stdcxx . . $ std/::vectorcxx . . $ std/vector#<int>& mapping)
517 {
518 assertcxx . . $ `<external>/4398592474888995393/assert.h:137:11`!((int)mapping.size() == axis_count);
519
520 uint8_tcxx . . $ uint8_t# axismap[ABS_MAXcxx . . $ `<external>/16711976702688784642/input-event-codes.h:928:9`! + 1];
521
522 stdcxx . . $ std/::copycxx . . $ std/copy(88304b602929f6f4).(mapping.begincxx . . $ std/vector#begin(359ca5030082c9f).(), mapping.endcxx . . $ std/vector#end(359ca5030082c9f).(), axismap);
523
524 if (ioctl(fdcxx . . $ Joystick#fd., JSIOCSAXMAPcxx . . $ `<external>/11922856331072503508/joystick.h:64:9`!, axismap) < 0)
525 {
526 stdcxx . . $ std/::ostringstreamcxx . . $ std/ostringstream# strcxx . . $ std/__cxx11/basic_ostringstream#basic_ostringstream(49f6e7a06ebc5aa8).;
527 str <<cxx . . $ std/`operator<<`(88df5bef833f7f83). filenamecxx . . $ Joystick#filename. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ": " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
528 throw stdcxx . . $ std/runtime_error#runtime_error(6be18eeaba0abf21).::runtime_errorcxx . . $ std/runtime_error#(str.strcxx . . $ std/__cxx11/basic_ostringstream#str(d33e1a6fd36255f7).());
529 }
530 }
531
532 void
533 Joystickcxx . . $ Joystick#::correct_calibrationcxx . . $ Joystick#correct_calibration(30bcad1052d5d57f).(const stdcxx . . $ std/::vectorcxx . . $ std/vector#<int>& mapping_old, const stdcxx . . $ std/::vectorcxx . . $ std/vector#<int>& mapping_new)
534 {
535 int axes[ABS_MAXcxx . . $ `<external>/16711976702688784642/input-event-codes.h:928:9`! + 1]; // axes[name] -> old_idx
536 for(stdcxx . . $ std/::vectorcxx . . $ std/vector#<int>::const_iteratorcxx . . $ std/vector#const_iterator# i = mapping_old.begincxx . . $ std/vector#begin(359ca5030082c9f).(); i !=cxx . . $ __gnu_cxx/`operator!=`(ef3c5749062e825c). mapping_old.endcxx . . $ std/vector#end(359ca5030082c9f).(); ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).i)
537 {
538 axes[*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).i] = i -cxx . . $ __gnu_cxx/operator-(a40477c209547c13). mapping_old.begincxx . . $ std/vector#begin(359ca5030082c9f).();
539 }
540
541 stdcxx . . $ std/::vectorcxx . . $ std/vector#<CalibrationDatacxx . . $ Joystick#CalibrationData#> callib_old = get_calibrationcxx . . $ std/vector#vector(b1ea180184b47f03).();
542 stdcxx . . $ std/::vectorcxx . . $ std/vector#<CalibrationDatacxx . . $ Joystick#CalibrationData#> callib_newcxx . . $ std/vector#vector(49f6e7a06ebc5aa8).;
543 for(stdcxx . . $ std/::vectorcxx . . $ std/vector#<int>::const_iteratorcxx . . $ std/vector#const_iterator# i = mapping_new.begincxx . . $ std/vector#begin(359ca5030082c9f).(); i !=cxx . . $ __gnu_cxx/`operator!=`(ef3c5749062e825c). mapping_new.endcxx . . $ std/vector#end(359ca5030082c9f).(); ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(93f2e9c3bc4efc49).i)
544 {
545 callib_new.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(callib_old[cxx . . $ std/vector#`operator[]`(428bb168810b9e52).axes[*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(c076846f881f3e7e).i]]);
546 }
547
548 set_calibrationcxx . . $ Joystick#set_calibration(6fc732b2aab18c50).(callib_new);
549 }
550
551 stdcxx . . $ std/::stringcxx . . $ std/string#
552 Joystickcxx . . $ Joystick#::get_evdevcxx . . $ Joystick#get_evdev(219584694fe2b248).() const
553 {
554 // See /usr/share/doc/linux-doc-2.6.28/devices.txt.gz
555 for(int i = 0; i < 32; ++i)
556 {
557 stdcxx . . $ std/::ostringstreamcxx . . $ std/ostringstream# outcxx . . $ std/__cxx11/basic_ostringstream#basic_ostringstream(49f6e7a06ebc5aa8).;
558 out <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "/dev/input/event" <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). i;
559
560 int evdev_fd;
561 if ((evdev_fd = open(out.strcxx . . $ std/__cxx11/basic_ostringstream#str(d33e1a6fd36255f7).().c_strcxx . . $ std/__cxx11/basic_string#c_str(1016ee5406d91ab9).(), O_RDONLYcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:43:9`!)) < 0)
562 {
563 // ignore
564 }
565 else
566 {
567 char evdev_name[256];
568 if (ioctl(evdev_fd, EVIOCGNAMEcxx . . $ `<external>/10572407642449696722/input.h:140:9`!(sizeof(evdev_name)), evdev_name) < 0)
569 {
570 stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(88df5bef833f7f83). out.strcxx . . $ std/__cxx11/basic_ostringstream#str(d33e1a6fd36255f7).() <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ": " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!) <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).;
571 }
572 else
573 {
574 if (orig_namecxx . . $ Joystick#orig_name. ==cxx . . $ std/`operator==`(4b17aa87c9f300c6). evdev_name)
575 {
576 // Found a device that matches, so return it
577 close(evdev_fd);
578 return outcxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f)..strcxx . . $ std/__cxx11/basic_ostringstream#str(d33e1a6fd36255f7).();
579 }
580 }
581
582 close(evdev_fd);
583 }
584 }
585
586 throw stdcxx . . $ std/runtime_error#runtime_error(6be18eeaba0abf21).::runtime_errorcxx . . $ std/runtime_error#("couldn't find evdev for " +cxx . . $ std/operator+(42c652dfebe55ad7). filenamecxx . . $ Joystick#filename.);
587 }
588
589 stdcxx . . $ std/::stringcxx . . $ std/string#
590 Joystickcxx . . $ Joystick#::get_js_type_from_configcxx . . $ Joystick#get_js_type_from_config(ae472d0fb84499ed).(const JoystickConfigcxx . . $ JoystickConfig#& js_cfg)
591 {
592 return js_cfgcxx . . $ std/__cxx11/basic_string#basic_string(a47f53d4115f6ce5)..js_typecxx . . $ JoystickConfig#js_type.;
593 }
594
595 #ifdef __TEST__
596
597 // g++ -D__TEST__ joystick.cpp evdev_helper.cpp xml_writer.cpp xml_reader.cpp -o joystick-test `pkg-config --cflags --libs gtkmm-2.4 sigc++-2.0`
598
599 int main(int argc, char** argv)
600 {
601 for(int i = 1; i < argc; ++i)
602 {
603 Joystick joystick(argv[i]);
604
605 std::cout << "Filename: '" << joystick.get_filename() << "'\n";
606 std::cout << "Name: '" << joystick.get_name() << "'\n";
607 std::cout << "js_id: " << joystick.get_js_id() << "\n";
608 std::cout << "Vendor_id: " << joystick.get_vendor_id() << "\n";
609 std::cout << "Product_id: " << joystick.get_product_id() << "\n";
610 std::cout << "usb_id: " << joystick.get_usb_id() << "\n";
611 std::cout << "Axis: " << joystick.get_axis_count() << "\n";
612 std::cout << "Button: " << joystick.get_button_count() << "\n";
613 std::cout << "Evdev: '" << joystick.get_evdev() << "'\n";
614 }
615 return 0;
616 }
617 #endif
618
619 /* EOF */