Skip to content
Snippets Groups Projects
Commit d723a33c authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

more work on joystick detection

parent 4d2c5d87
No related branches found
No related tags found
No related merge requests found
...@@ -955,6 +955,11 @@ if(DLFCN_H) ...@@ -955,6 +955,11 @@ if(DLFCN_H)
list(APPEND EXTERNAL_LIBRARIES ${CMAKE_DL_LIBS}) list(APPEND EXTERNAL_LIBRARIES ${CMAKE_DL_LIBS})
endif(DLFCN_H) endif(DLFCN_H)
check_include_file(linux/joystick.h LINUX_JOYSTICK_H)
if(LINUX_JOYSTICK_H)
set_config_option(HAVE_LINUX_JOYSTICK "LinuxJoystick")
endif(LINUX_JOYSTICK_H)
if(MSVC) if(MSVC)
add_definitions(-D_USE_MATH_DEFINES -DNOMINMAX add_definitions(-D_USE_MATH_DEFINES -DNOMINMAX
-D_CRT_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_DEPRECATE) -D_CRT_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_DEPRECATE)
......
...@@ -54,7 +54,6 @@ ...@@ -54,7 +54,6 @@
#include <iostream> #include <iostream>
#include <stdio.h> #include <stdio.h>
#include "GamePad.h" #include "GamePad.h"
#include "Context.h"
#if !defined(WIN32) #if !defined(WIN32)
#include <unistd.h> #include <unistd.h>
...@@ -105,11 +104,7 @@ GamePad::GamePad() : active(false), frequency(.01), gamepad_fd(0) ...@@ -105,11 +104,7 @@ GamePad::GamePad() : active(false), frequency(.01), gamepad_fd(0)
for(int i = 0; i < axes; i++) axe[i] = 0; for(int i = 0; i < axes; i++) axe[i] = 0;
joyGetPosEx(gamepad_fd, &infoex); joyGetPosEx(gamepad_fd, &infoex);
infoex.dwFlags = JOY_RETURNALL; infoex.dwFlags = JOY_RETURNALL;
#elif defined(__APPLE__) #elif defined(HAVE_LINUX_JOYSTICK)
// ??
#else // LINUX
gamepad_fd = open(GAMEPAD_DEV, O_RDONLY | O_NONBLOCK); gamepad_fd = open(GAMEPAD_DEV, O_RDONLY | O_NONBLOCK);
if (gamepad_fd > 0) { if (gamepad_fd > 0) {
ioctl(gamepad_fd, JSIOCGNAME(256), name); ioctl(gamepad_fd, JSIOCGNAME(256), name);
...@@ -141,7 +136,7 @@ GamePad::~GamePad() ...@@ -141,7 +136,7 @@ GamePad::~GamePad()
{ {
active = false; active = false;
gamepad_fd = 0; gamepad_fd = 0;
#if !defined(WIN32) && !defined(__APPLE__) #if defined(HAVE_LINUX_JOYSTICK)
close(gamepad_fd); close(gamepad_fd);
#endif #endif
} }
...@@ -199,11 +194,7 @@ int GamePad::read_event() ...@@ -199,11 +194,7 @@ int GamePad::read_event()
std::cout<< infoex.dwButtonNumber << std::endl; std::cout<< infoex.dwButtonNumber << std::endl;
std::cout<< infoex.dwPOV << std::endl; std::cout<< infoex.dwPOV << std::endl;
*/ */
#elif defined(__APPLE__) #elif defined(HAVE_LINUX_JOYSTICK)
// ??
#else // LINUX
int result = read(gamepad_fd, &event, sizeof(event)); int result = read(gamepad_fd, &event, sizeof(event));
if (result > 0){ if (result > 0){
switch (event.type){ switch (event.type){
...@@ -232,18 +223,18 @@ int GamePad::read_event() ...@@ -232,18 +223,18 @@ int GamePad::read_event()
void GamePad::affiche() void GamePad::affiche()
{ {
for (int i = 0; i < 6; i++) std::cout<<("_________"); for (int i = 0; i < 6; i++) std::cout << "_________";
std::cout << std::endl; std::cout << " axis "; std::cout << std::endl; std::cout << " axis ";
for (int i = 0; i < 6; i++) std::cout << " | "<<i; for (int i = 0; i < 6; i++) std::cout << " | "<<i;
std::cout << std::endl; std::cout << " "; std::cout << std::endl; std::cout << " ";
for (int i = 0; i < 6; i++) std::cout << " | "<< axe[i] ; for (int i = 0; i < 6; i++) std::cout << " | "<< axe[i] ;
std::cout << std::endl; std::cout << std::endl;
for (int i = 0; i < 10; i++) std::cout<< ("_____"); for (int i = 0; i < 10; i++) std::cout << "_____";
std::cout << std::endl; std::cout << " b."; std::cout << std::endl; std::cout << " b.";
for (int i = 0; i < 10; i++) std::cout << " | " << i; for (int i = 0; i < 10; i++) std::cout << " | " << i;
std::cout << std::endl; std::cout << " "; std::cout << std::endl; std::cout << " ";
for (int i = 0; i < 10; i++) std::cout << " | " << button[i]; for (int i = 0; i < 10; i++) std::cout << " | " << button[i];
std::cout << std::endl; std::cout << std::endl;
for (int i = 0; i < 10; i++) std::cout<< ("_____"); for (int i = 0; i < 10; i++) std::cout << "_____";
std::cout << std::endl; std::cout << std::endl;
} }
...@@ -13,12 +13,12 @@ ...@@ -13,12 +13,12 @@
#define GP_BUTTONS 32 #define GP_BUTTONS 32
#define GP_AXES 6 #define GP_AXES 6
#include "GmshConfig.h"
#if defined(WIN32) #if defined(WIN32)
#include <windows.h> #include <windows.h>
#include <mmsystem.h> #include <mmsystem.h>
#elif defined(__APPLE__) #elif defined(HAVE_LINUX_JOYSTICK)
// ??
#else // LINUX
#include <linux/joystick.h> #include <linux/joystick.h>
#include <fcntl.h> #include <fcntl.h>
#define GAMEPAD_DEV "/dev/input/js0" #define GAMEPAD_DEV "/dev/input/js0"
...@@ -44,28 +44,20 @@ class GamePad { ...@@ -44,28 +44,20 @@ class GamePad {
int axe_max[8]; int axe_max[8];
int gamepad_fd; int gamepad_fd;
char name[256]; char name[256];
#if defined(WIN32) #if defined(WIN32)
JOYCAPS caps; JOYCAPS caps;
JOYINFOEX infoex; JOYINFOEX infoex;
JOYINFO info; JOYINFO info;
int axes; int axes;
int buttons; int buttons;
#elif defined(HAVE_LINUX_JOYSTICK)
#elif defined(__APPLE__)
// ??
int axes;
int buttons;
#else // LINUX
js_event event; js_event event;
__u32 version; __u32 version;
__u8 axes; __u8 axes;
__u8 buttons; __u8 buttons;
#else
int axes;
int buttons;
#endif #endif
}; };
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#cmakedefine HAVE_LIBJPEG #cmakedefine HAVE_LIBJPEG
#cmakedefine HAVE_LIBPNG #cmakedefine HAVE_LIBPNG
#cmakedefine HAVE_LIBZ #cmakedefine HAVE_LIBZ
#cmakedefine HAVE_LINUX_JOYSTICK
#cmakedefine HAVE_MATHEX #cmakedefine HAVE_MATHEX
#cmakedefine HAVE_MED #cmakedefine HAVE_MED
#cmakedefine HAVE_MESH #cmakedefine HAVE_MESH
......
...@@ -638,7 +638,8 @@ void Navigator::move() ...@@ -638,7 +638,8 @@ void Navigator::move()
} }
// head movement is damped to avoid nausea // head movement is damped to avoid nausea
if(pad->button[ pad->button_map[4] ] ){ if(pad->button[ pad->button_map[4] ] ){
ax0 = int(pad->axe[ pad->axe_map[0] ]*10)/10.; ax1 =int( pad->axe[ pad->axe_map[1] ]*10)/10.; ax0 = int(pad->axe[ pad->axe_map[0] ]*10)/10.;
ax1 =int( pad->axe[ pad->axe_map[1] ]*10)/10.;
if(ax1 >0.) ax0=-ax0; if(ax1 >0.) ax0=-ax0;
} }
else { else {
...@@ -687,7 +688,8 @@ void Navigator::move() ...@@ -687,7 +688,8 @@ void Navigator::move()
else{ else{
speed= -4.0 * (pad->axe[ pad->axe_map[3] ]) *reference_speed ; speed= -4.0 * (pad->axe[ pad->axe_map[3] ]) *reference_speed ;
} }
ctx->camera.move_and_look(speed,lateral,lift,0.,0.,angular_lat,azimut,elevation); ctx->camera.move_and_look(speed, lateral, lift, 0., 0.,
angular_lat, azimut, elevation);
//------------------------------------- //-------------------------------------
break; // end of mode PESDESTRIAN break; // end of mode PESDESTRIAN
...@@ -722,7 +724,8 @@ void Navigator::move() ...@@ -722,7 +724,8 @@ void Navigator::move()
angular_lat= -1.0 * (pad->axe[ pad->axe_map[2] ]) *reference_angle; angular_lat= -1.0 * (pad->axe[ pad->axe_map[2] ]) *reference_angle;
angular_up = 1.0 * (pad->axe[ pad->axe_map[3] ]) *reference_angle; angular_up = 1.0 * (pad->axe[ pad->axe_map[3] ]) *reference_angle;
ctx->camera.move_and_look(speed,lateral,lift,angular_fr,angular_up,angular_lat,azimut,elevation); ctx->camera.move_and_look(speed, lateral, lift, angular_fr, angular_up,
angular_lat, azimut, elevation);
//------------------------------------- //-------------------------------------
break; // end of mode DIVER break; // end of mode DIVER
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment