Skip to content

ibov/qjoystick

Repository files navigation

qjoystick

  • This qjoystick class is rewritten based on the library: https://github.com/drewnoakes/joystick. Please look at this library if you want to see more detail and explanation.
  • I create the library and examples in Qt. See the headers for more details of the class functions.

Note that, your gamepad should be recognized under Linux, for example, mine is located at "/dev/input/js0".

This library should work on Linux-based OS. I only tested the library on Ubuntu 18.04. It'll up to you to adapt to other OS.

If your gamepad is not found under Linux, try the xpad driver from https://github.com/paroj/xpad. Good luck!

  • Author: N.D.Quan - 10/2021

New functions added:

  • Auto reconnect to joystick after unplugging / plugging
  • Emit signals including:
    • button / axis values
    • disconnected state

Tested on:

  • Ubuntu 18.04
  • Qt5

Creation and Handle functions:

joystick = new Joystick("/dev/input/js0");
connect(joystick, &Joystick::onButtonChange,this,&JoystickMonitor::onButtonEvent);
connect(joystick, &Joystick::onAxisChange,this,&JoystickMonitor::onAxisEvent);
connect(joystick, &Joystick::onDisconnected,this,&JoystickMonitor::onDisconnectedEvent);
joystick->start();
Example results with x-mode joystick:
Axis  4 : 31341
Axis  4 : 22535
Axis  4 : 0
Button  2 : 1
Button  2 : 0
Button  1 : 1
Button  1 : 0
Button  2 : 1
Button  2 : 0
Button  0 : 1
Button  0 : 0
Axis  1 : -520
Axis  1 : -8549
Axis  1 : -18133
Axis  1 : -28494
Axis  1 : -16061
Axis  1 : -4405
Axis  1 : 0
Joystick is disconnected:  true
Joystick is disconnected:  true
Joystick is disconnected:  true
Joystick is disconnected:  true
Joystick is disconnected:  false
Button  0 : 0
Button  1 : 0
Button  2 : 0
Button  3 : 0
Button  4 : 0
Button  5 : 0
Button  6 : 0
Button  7 : 0
Button  8 : 0
Button  9 : 0
Button  10 : 0
Axis  0 : 0
Axis  1 : 0
Axis  2 : -32767
Axis  3 : 0
Axis  4 : 0
Axis  5 : -32767
Axis  6 : 0
Axis  7 : 0

About

testing joystick under Linux environment, support monitoring disconnection state and auto recovery mode

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published