67 for (
int i = JOYSTICKID1 ; i < JOYSTICKID2 ; i++) {
68 if(JOYERR_NOERROR == joyGetDevCaps(i, &caps,
sizeof(JOYCAPS)) ) {
93 if((1./
frequency < (
double)caps.wPeriodMin) ||
94 (1./
frequency > (
double)caps.wPeriodMax)){
101 for (
int i = 0; i <
axes; i++)
axe[i] = 0.;
106 for(
int i = 0; i <
axes; i++)
axe[i] = 0;
107 joyGetPosEx(gamepad_fd, &infoex);
108 infoex.dwFlags = JOY_RETURNALL;
109 #elif defined(HAVE_LINUX_JOYSTICK)
110 gamepad_fd = open(GAMEPAD_DEV, O_RDONLY | O_NONBLOCK);
111 if (gamepad_fd > 0) {
112 ioctl(gamepad_fd, JSIOCGNAME(256),
name);
113 ioctl(gamepad_fd, JSIOCGVERSION, &version);
114 ioctl(gamepad_fd, JSIOCGAXES, &
axes);
115 ioctl(gamepad_fd, JSIOCGBUTTONS, &
buttons);
116 std::cout <<
"Joystick/Gamepad detected: " <<
name ;
117 std::cout <<
" (version " << version <<
" / " ;
118 std::cout << (int)
axes <<
" axes /" ;
119 std::cout << (int)
buttons <<
" buttons)" << std::endl;
124 for (
int i = 0; i < std::min(9, (
int)
buttons); i++) {
127 for (
int i = 0; i < std::min(7, (
int)
axes); i++)
axe[i] = 0.;
129 for (
int i = 0; i < std::min(7, (
int)
axes); i++)
axe_map[i] = i;
133 if(strcmp(
name,
"Thrustmaster Run'N' Drive Wireless PS3") == 0){
145 #if defined(HAVE_LINUX_JOYSTICK)
146 if (gamepad_fd) close(gamepad_fd);
162 infoex.dwFlags = JOY_RETURNALL;
163 joyGetPosEx(gamepad_fd, &infoex) ;
164 axe[0] = (double)((1. * infoex.dwXpos - 32767.) / 32767.);
165 axe[1] = (double)((1. * infoex.dwYpos - 32767.) / 32767.);
166 axe[2] = (double)((1. * infoex.dwRpos - 32767.) / 32767.);
167 axe[3] = (double)((1. * infoex.dwZpos - 32767.) / 32767.);
168 if(infoex.dwPOV < 38000.) {
169 double alpha = 3.14159 / 18000. * infoex.dwPOV;
170 axe[4] = 1.001 * sin(alpha);
171 axe[5] = -1.001 * cos(alpha);
176 for (
int i = 0; i < 6; i++)
if(fabs(
axe[i]) < .01)
axe[i] = 0.;
179 bool event_value =
false;
180 for (
int i = 0; i <
buttons; i++){
181 int bin = pow(2.0, i);
182 if(
button[i] != (
bool)(infoex.dwButtons & bin)) {
185 event_value = (bool)(infoex.dwButtons & bin);
190 button[event_num] = event_value;
204 #elif defined(HAVE_LINUX_JOYSTICK)
205 int result = read(gamepad_fd, &event,
sizeof(event));
210 case JS_EVENT_INIT | JS_EVENT_AXIS:
212 case JS_EVENT_INIT | JS_EVENT_BUTTON:
215 axe[(int)event.number] = (
double)
event.value / 32767.;
217 case JS_EVENT_BUTTON:
218 if(
button[(
int)
event.number] == 0. && (bool)event.value) {
221 button[(int)event.number] = (
bool)
event.value ;
233 for (
int i = 0; i < 6; i++) std::cout <<
"_________";
234 std::cout << std::endl; std::cout <<
" axis ";
235 for (
int i = 0; i < 6; i++) std::cout <<
" | "<<i;
236 std::cout << std::endl; std::cout <<
" ";
237 for (
int i = 0; i < 6; i++) std::cout <<
" | "<<
axe[i] ;
238 std::cout << std::endl;
239 for (
int i = 0; i < 10; i++) std::cout <<
"_____";
240 std::cout << std::endl; std::cout <<
" b.";
241 for (
int i = 0; i < 10; i++) std::cout <<
" | " << i;
242 std::cout << std::endl; std::cout <<
" ";
243 for (
int i = 0; i < 10; i++) std::cout <<
" | " <<
button[i];
244 std::cout << std::endl;
245 for (
int i = 0; i < 10; i++) std::cout <<
"_____";
246 std::cout << std::endl;