4 #include <linux/joystick.h> 12 if ((
m_fd = open(dev, O_RDONLY|O_NONBLOCK)) < 0){
18 ioctl(
m_fd, JSIOCGAXES, &number_of_axes );
19 std::cout <<
"number_of_axes = " << (
int)number_of_axes << std::endl;
20 m_axes.resize(number_of_axes);
22 char number_of_buttons;
23 ioctl(
m_fd, JSIOCGBUTTONS, &number_of_buttons );
24 std::cout <<
"number_of_buttons = " << (
int)number_of_buttons << std::endl;
28 for (
int i=0;
i<number_of_axes+number_of_buttons;
i++){
44 const float MAX_VALUE_16BIT = 32767.0f;
47 int rdlen = read(
m_fd, &e,
sizeof(js_event) );
51 if( errno == EAGAIN ){
56 }
else if( rdlen < (
int)
sizeof(js_event) ) {
57 std::cout<<
"ERROR: read"<<std::endl;
60 if( e.type & JS_EVENT_AXIS ) {
63 fval = (float)e.value/MAX_VALUE_16BIT;
68 m_buttons[e.number] = e.value==0 ?
false :
true;
std::vector< bool > m_buttons
joystick(const char *dev)
std::vector< float > m_axes