Are there X11 XInput2 raw events for joysticks and controllers? - linux

I am using the XInput2 interface in C++ to get raw input events for keyboard and mouse on my X11 application to linux. That works fine.
I have a joystick and a bluetooth connected game controller (xbox controller like)
I don't see any events from either of those using XInput2
Should I expect to be able to get events from those as well as keyboard & mouse or is there a different method I should use for them?
A brief look seems to indicate that I can use read events from /dev/input/event* for them. Is this the correct way to interface with them in low level linux. That seems a pity as I'll need two entirely different input event systems, one for keyboard & mouse, and one for controller and joystick so wanted to make sure before going that way.

Related

createBond doesn't always show pin dialog

After performing a bleScan and giving the user their device to select, I then take that get that device via the getRemoteDevice(address) call.
Once I get that BluetoothDevice object, I then call createBond(). Since createBond() triggers an async operation, I have BroadcastReceiver listening for the results and confirm that the device has paired/bonded when I received a BONDED result in the receiver.
This is pretty standard procedure for bonding with a BT device.
The issue I'm running into is that under seemingly random conditions, the built in pair/connect dialog does not appear.
Through some testing I found that if I swipe down on the phone, long press bluetooth and click "Pair a New Device" and the device shows up in the list...I can then return to my app, call createBond() and the PIN dialog appears.
This tells me there's something iffy with some type of Bluetooth Cache or something along those lines.
I'm trying to determine why this might be and if there's something I should be ensuring that I do BEFORE calling createBond to ensure the pin dialog appears.
I can post relevant code but it's really just a one-liner
boolean bondInitiated = getDevice().createBond();
After I call create bond there's typically a 1-2 second pause and then the pin dialog appears.
Can someone offer some insight here? Is there a better way to pair with a BT device from Android other than calling createBond()
I'd LOVE to just give the user a PIN text box, let them enter the pin shown on the BT device (it's a glucometer) and then pair that way but I've not seen a way to do that.
Unfortunately, there isn't a standard way to always show the pairing dialog to the user. This is because the pairing process is dependant on the hardware, and some OEMs have modified how it works at the OS level. As such, there are variations depending on the hardware that is being used.
However, there might be some "hacks" that you can implement to get this to work. Have a look at this link as it includes details on the bondong process and the pairing popup. It's a bit outdated (3 years ago), but it includes the following paragraph:-
So if you want you can try to make the popup always appear in the
foreground by doing discovering for 1 second before connecting to a
device. It is a bit of a hack but it works.

What is the difference between /dev/input/eventX and /dev/input/jsX?

When I connect a gamepad on my Linux kernel v5.14 there are two new devices that show up:
/dev/input/event23
/dev/input/js1
If I cat <file> | xxd both device files provide gamepad event information. But event23 is much more verbose than js1.
Also, evtest gives error Invalid Argument on js1 but works fine on event23. The same happens when I use libevdev both device files.
It looks like with every event, js1 dumps the contents of an input_event struct (defined in linux/input.h)
What is the difference between the device files? Why do they have different information and what more information does event23 provide over js1?
/dev/input/js* devices are created by the joydev legacy joystick driver. It only supports joysticks and joystick-like devices.
https://www.kernel.org/doc/html/latest/input/joydev/joystick.html
/dev/input/event* devices are created by the evdev input event interface. It supports all types of input devices, not just joysticks.
https://linux.die.net/man/4/evdev
The joydev interface exposes a subset of the information exposed through evdev, specifically it will only expose an input if it looks like a joystick button or axis. New applications should prefer to use evdev, but joydev is usually still available.
The "looks like a joystick button or axis" heuristic can sometimes be a problem for joydev. When a HID gamepad is connected, evdev and joydev use information in the device's HID report descriptor to detect the number of button and axis inputs. joydev only considers buttons from the HID Button usage page, but newer gamepads sometimes define special buttons with different usages. This is especially common for Android gamepads, which have non-Button usages for the Home and Back buttons. These buttons don't get picked up by joydev.
Another big difference: joydev is purely for input. evdev supports gamepad rumble and force feedback effects.

Epson projector

I have a projector that can accept control commands like turn on/off and queries like amount of time it was on.
Control commands work, but I can't seem to capture responses from queries; when I connect via USB, I get two additional raw input files in the dev directory.
I wrote a C program that captures events from input devices it captures mouse movements and keyboard events, but it doesn't capture replies from the projector at all, not even the event itself. Why is that?
In Windows, everything works.

HID input on linux for games

What is the best way to capture HID input on linux for games? I don't need anything special. Just mouse and keyboard. Right now I'm using Xlib. I have a separate input thread, which has its own connection to the X Server (Display instance) and it handles events for main render window. It is working just fine, but it is a bit limited. For example, I'm missing mouse raw input.
Have you tried opening and reading device files in /dev/input?

What would be the simplest way to interface custom hardware with one input to have switch somewhere in /proc?

I have a device that takes low current 3-12v input signal to do it's magic and I would like to interface it to my linux box. What kind of options do I have on this? It would be great to have some low-cost possibly user-space solution.
If I understand right, you need to control your box by changing 3-12v input signals to it. Here's the choices I can think of from the top of my head:-
a: Using RS232 serial handshake lines. RTS/CTS can usually controlled programatically as "on/off" signals without driver development using IOCTL calls.
b: Use a "GPI dongle" such as the Advantech ADAM range. These typically take serial or TCP/IP inputs and convert them to suitable output signals.
c: You may be able to do something with a parallel printer port if your PC stil has such a thing.
As shodanex says, be aware that RS232 levels are NOT directly compatible with TTL/CMOS inputs so you may need some minor level shifting/clamping electronics to fix this.

Resources