Select Git revision
graphicWindow.cpp
Forked from
gmsh / gmsh
Source project has a limited visibility.
GamePad.cpp 7.59 KiB
// Gmsh - Copyright (C) 1997-2013 C. Geuzaine, J.-F. Remacle
//
// See the LICENSE.txt file for license information. Please report all
// bugs and problems to the public mailing list <gmsh@geuz.org>.
//
// Contributed by Gilles Marckmann <gilles.marckmann@ec-nantes.fr>
#if defined(WIN32) || defined(__APPLE__)
#include <cstring>
#include <string>
#include <iostream>
#include <stdio.h>
#include "GamePad.h"
GamePad::GamePad() : active(false), frequency(.01), gamepad_fd(0) {
for (int i=0;i<9;i++) button_map[i]=i;
for (int i=0;i<7;i++) axe_map[i]=i;
axe_map[6]=1;
// other recognized map "Thrustmaster Run'N' Drive Wireless PS3"
if ( strcmp(name,"Thrustmaster Run'N' Drive Wireless PS3" ) == 0){
button_map[0]=1;
button_map[1]=0;
button_map[5]=6;
button_map[6]=5;
}
}
GamePad::~GamePad() { gamepad_fd = 0;}
bool GamePad::toggle(const int _nbut) {
bool res;
if( toggle_status[_nbut] ){ res = true; toggle_status[_nbut]=false;}
else { res=false; }
return res;
}
int GamePad::read_event() { return 1;}
void GamePad::affiche() {}
#else // if !win32 => if linux/apple
#include <cstring>
#include <string>
#include <iostream>
#include <stdio.h>
#include "GamePad.h"
#include "Context.h"
#include <unistd.h>
GamePad::GamePad() : active(false), frequency(.01), gamepad_fd(0) {
gamepad_fd = open(GAMEPAD_DEV, O_RDONLY | O_NONBLOCK);
if (gamepad_fd > 0) {
ioctl(gamepad_fd, JSIOCGNAME(256), name);
ioctl(gamepad_fd, JSIOCGVERSION, &version);
ioctl(gamepad_fd, JSIOCGAXES, &axes);
ioctl(gamepad_fd, JSIOCGBUTTONS, &buttons);
std::cout << "Joystick/Gamepad detected: " << name ;
std::cout << " (version " << version << " / " ;
std::cout << (int)axes <<" axes /" ;
std::cout << (int)buttons <<" buttons)" << std::endl;
active = true;
}