1 // Gmsh - Copyright (C) 1997-2021 C. Geuzaine, J.-F. Remacle 2 // 3 // See the LICENSE.txt file in the Gmsh root directory for license information. 4 // Please report all issues on https://gitlab.onelab.info/gmsh/gmsh/issues. 5 // 6 // Contributed by Gilles Marckmann <gilles.marckmann@ec-nantes.fr> 7 8 #ifndef GAMEPAD_H 9 #define GAMEPAD_H 10 11 #define GP_RANGE 1.0 12 #define GP_DEV 16 13 #define GP_BUTTONS 32 14 #define GP_AXES 6 15 16 #include "GmshConfig.h" 17 18 #if defined(WIN32) 19 #include <windows.h> 20 #include <mmsystem.h> 21 #elif defined(HAVE_LINUX_JOYSTICK) 22 #include <linux/joystick.h> 23 #include <fcntl.h> 24 #define GAMEPAD_DEV "/dev/input/js0" 25 #endif 26 27 class GamePad { 28 public: 29 bool active; 30 bool toggle_status[GP_BUTTONS]; 31 bool event_read; 32 double frequency; 33 GamePad(); 34 ~GamePad(); 35 double axe[GP_AXES]; 36 bool button[GP_BUTTONS]; 37 bool toggle(const int _nbut); 38 int read_event(); 39 void affiche(); 40 int button_map[10]; 41 int axe_map[8]; 42 43 private: 44 char name[256]; 45 #if defined(WIN32) 46 int gamepad_fd; 47 JOYCAPS caps; 48 JOYINFOEX infoex; 49 JOYINFO info; 50 int axes; 51 int buttons; 52 #elif defined(HAVE_LINUX_JOYSTICK) 53 int gamepad_fd; 54 js_event event; 55 __u32 version; 56 __u8 axes; 57 __u8 buttons; 58 #else 59 int axes; 60 int buttons; 61 #endif 62 }; 63 64 #endif 65