I am unsure if this is the correct place for this question. I am attempting to obtain the axis position values from a joystick /dev/input/js0 on my system. If I run jstest /dev/input/js0 it will give me live feedback on all buttons and axis positions. I am trying to feed this information into my C program to control servos. The xboxdrv adds a udev entry already crw-rw-T 1 root input 13, 0 Mar 30 17:54 /dev/input/js0 – PhillyNJ Mar 30 '14 at 18:16 4 Then, please answer yr own question by providing a clear answer and marking it as answered with a green check-mark. Because Xorg will create a test input keyboard and a test input mouse (both virtual) during its startup. Also, it will aggregate the test keyboard with the actual keyboard into a main virtual device. It will perform muxing of the input. The same will happen to the test and actual mouse.
- Create Device File Dev Input Js0 C X
- Create Device File Dev Input Js0 C 1
- Create Device File Dev Input Js0 C 0
- Create Device File Dev Input Js0 C E
Index
Overview
This program listen in the background for gamepad inputs. If a special button combination is getting pressed,the provided command line will be invoked. It runs a command once defined buttons were pressed. It was developed for Raspbian and PS3 wireless controller but should work everywhere with udev and joystick support.
Usage
I have a Raspberry Pi. The installed operation system is raspbian. The Kodi package runs pretty well as a media center. The remote control is an App on a smartphone. So no other controller is needed.
After couple of month I found this great RetroPie project. There is also another great one which brings it on a software level instead making a boot image. It's called EmulationStation. The setup with my preferred PS3 controller and the configuration went well and it worked fantastic. The game console works perfectly fine and brings me back to the good old jump'n'run 90s but now with big screen and cool wireless controller!
But one thing was an issue. I wanted to use the same hardware and don't miss my system (raspbian). Dual boot is not cool and takes too long. So basically what i needed is some kind of trigger to end any X11/Kodi processes and start EmulationStation ... and of course vice versa.
In my configuration Kodi runs as default. Media center is still the primary usage. But the idea was to take the PS3 controller press some button combination and the EmulationStation will apear. After I played enough, just press this buttons again and media center will apear and I can put the PS3 controller back.
After searching the internet, I found nothing really interesting. Kodi addon will not work because gamepad support is still missing. EmulationStation addon might work but than ... Kodi solution will be missing. So I had to go one level up to the OS. But even here I found nothing really easy to setup or working. So I decided to write this program. It runs as a daemon in the background and listening in nonblocking mode to /dev/input/js* devices. To make it hotplug capable, it's monitoring the udev signals if no device is present.
Update 12/22/2018:If you have many different /dev/inputs, you can pass it as an arguement at the startup:
jslisten --device /dev/input/js0
** jslisten will also default to listen to the first device found if the defined device is not found.
Create Device File Dev Input Js0 C X
Update 02/12/2019:Changed the default service user to 'pi' in jslisten.service
Use user root only if it's really required.
Update 02/16/2019:Added a different mode to easier trigger scripts.
When started with
--mode plain
(the default) the program behaves as used. This is fine if you need the button combination once in a while.However if you want to activate a script a few times in a short time, lets say to adjust your audio volume or if you have a led stripe installed in your arcade and want to adjust the brightness, thenthe
--mode hold
comes in handy.When started with
--mode hold
and you have at least two buttons defined to enter an action, then you hold down the first one, while tipping the second one. If you have three buttons defined you canhold the second two and then just tip the third. In a four button set you will have to hold the first three.As soon as you release any but the last button (according to the order in the
jslisten.cfg
) you will have to press the all buttons again.So the difference to the plain mode is that once you have entered the engaged/elevated state with a three button set for example, you hold down the first two and can quickly trigger the action bypressing the third. In plain mode you would have to press all three buttons over again to do audio or brightness adjustment.
Also added
--help
for the command line for a brief summary of options.Installation
Following example for Raspbian. Should work for many other distributions almost the same way.
- run '# make' to create the binary
- Place the binary to '/opt/bin' (if you change the folder, please update your init script)
- Copy the configuration script to /etc/jslisten.cfg
- Modify the configuration script to your needs
- Copy the service script 'utils/jslisten.service' to '/etc/systemd/system'
- Update the systemd daemon: '# systemctl daemon-reload'
- Start the daemon '# systemctl start jslisten.service'
- Make it start at boot '# systemctl enable jslisten'
Configuration
- I assume your joystick setup is already done and you can see with 'jstest /dev/input/js0' nice looking key strokes coming up. There are many tutorials out there and you should not proceed if this doesn't work for you!
- Run ./jslisten once to create ~/.jslisten config file or copy utils/jslisten.cfg to /etc
- Think which button combination will work for your gamepad. You can configure up to 4 button combination. In my case i picked 'Left Shoulder' + 'Right Shoulder' + SELECT. I'm pretty sure i will not need to press this buttons at the same time for any games.
- Get the number ID's for this buttons with jstest (or any other similar program)
- Edit the configuration file (either /etc/jslisten.cfg or ~/.jslisten) and maintain the button ID's and the program which you want to run.
- Make sure this script/program can handle multiple simultanios calls! Even if the daemon will wait till this program ends, you never know... And we like to press key combinations many times, if something doesn't work immediately...
Here is my config example:
Known limitations
- Kodi and X11 are blocking /dev/input/* events. For X11 you can add an exception in /usr/share/X11/xorg.conf.d/10-quirks.conf but Kodi is ... nasty ... As long as they don't implement a niceunified unput support, my workaround is to revoke the kodi group rights to the input devices. :(
- If you experience any issues, feel free to use '--loglevel debug' option and check syslog.
Multiple key combinations
You can have different key sets to run different programs:
Please note that there are build dependencies from OpenTX Companion to the OpenTX firmware. This means that the complete OpenTX code base, not just the Companion part, must be available. It also means that you have to install the OpenTX firmware build chain before you continue.
Additional note: If you are building a new version of the Companion software, you will need to copy the hex file from radio/src to where ever you keep your firmware files to be written to the radio.
Install Build Toolchain
You need to retrieve the following products ...
- subversion
- git
- gcc-c++
Retrieve the following packages on Fedora
On Fedora >= 26 the following command retrieves all the needed packages
On Fedora >= 22 the following command retrieves all the needed packages
On Fedora < 22
Retrieve the following packages on Ubuntu or Mint
On the Debian based distributions, the following command retrieves all the needed packages (note: A few are probably not needed anymore. ruby and libqtwebkit-dev are removal candidates. But they will not hurt)NOTE: QT4 may need to be updated from the link above
Install cmake 2.8.12
At the time of writing cmake 2.8.12 is not included in the Debian/Ubuntu/Mint repositories. The Companion build however requires at least this version. It will no doubt be available soon, but until then, you have to build it manually. Start by checking your installed version:
If the result is less than 2.8.12 you need to do the following
Check the version again to establish that you have really installed version 2.8.12
Set up the source code tree structure
Navigate to wherever you want to store the source code. Issue the following command (it will take quite a while to complete):
Git has now set up a repository clone in a folder called
opentx
with content from branch 2.1
of the project.In the past, the branches were named
master
and next
. They no longer seem to exist in the repository and since we are building the 2.1 version, going with 2.1
branch is a safe choice.Enter the
opentx/companion
folder and create a build folder here:This folder is where you should build Companion. Building here avoids mixing temporary build files with the source code.
Build Companion
In order to be able to build Companion a Makefile has to be created. You have to select if you are going to build a debug or release version.
For a release version you enter:
For a release version you enter:
Alternatively, for a debug version you enter:
In either case we are now ready to compile Companion
When the build process completes you will have a binary file named 'companion21'.
You can start OpenTX Companion in the folder like this:
Or do a proper installation like this:
Enable non-root use of USBASP programmer
![Device Device](/uploads/1/2/6/2/126297817/511484298.png)
Create Device File Dev Input Js0 C 1
If you intend to use an USBASP device to communicate to Atmel equiped radios (the 9x and 9XR), you have to enable AVRDUDE to run without root priviliges.
If you do not do this you will always have to run Companion with root priviliges, which is not a good practice.
Plug in the programmer and run
If you do not do this you will always have to run Companion with root priviliges, which is not a good practice.
Plug in the programmer and run
You should get a line like this:
Notice the two numbers after ID XXXX:YYYY
In next command replace XXXX and YYYY with the numbers.
In next command replace XXXX and YYYY with the numbers.
then execute
Setup SAM-BA for Sky9x / 9XR-PRO boards on 64bits Fedora
Joystick support
Companion does support joystick for firmware simulator control.
The latest version of SDL by default uses a device that cannot be calibrated properly by the OS.
To avoid problems use the following command before launching Companion:
The latest version of SDL by default uses a device that cannot be calibrated properly by the OS.
To avoid problems use the following command before launching Companion:
Where js0 is your joystick / RC Sim adapter.
or write
or write
in /etc/environment
In Companion you will have two joysticks. Choose the first one.
If you experience calibration problems, have a look to the jscal utility.
If you experience calibration problems, have a look to the jscal utility.
Create Device File Dev Input Js0 C 0
calibrating:
directory for storing:
Create Device File Dev Input Js0 C E
store the calibration: