vi / virtual_touchscreen

Simple evdev linux device driver and GUI program to simulate multitouch touchscreen
90 stars 33 forks source link

evdev throwing an error #7

Closed MGlolenstine closed 4 years ago

MGlolenstine commented 4 years ago

After the insmod or modprobe, the device appears and I can use libinput record or evtest for testing it and it works great, but it doesn't work in X. The X log shows this error

[    12.650] (EE) evdev: Touchscreen Virtual Device: Unable to query fd: Inappropriate ioctl for device

Which I think is connected to the TVD not working in the X.

What would have to be changed in the code to make the module work within X?

vi commented 4 years ago

For me it worked with Xorg properly (I initially implemented it to test Xorg apps without having a real touchscreen).

What are Linux kernel and Xorg versions? Have you tried running it for Xorg alone, without also attaching other clients like libinput record or evtest?

MGlolenstine commented 4 years ago

Thanks for your swift reply!

I'm currently running X.Org X Server 1.20.4 on a Raspberry Pi Compute Module 3+. This is my uname: Linux raspberrypi 5.4.45-v7+ #1321 SMP Wed Jun 10 17:33:27 BST 2020 armv7l GNU/Linux.

The reason for testing it out with evtest and libinput record was the touchscreen not working in OpenBox and i3.

vi commented 4 years ago

Have just tried it my X.Org X Server 1.20.4 Linux 4.19.128-64+ and it works.

What have you used to provide input to /dev/virtual_touchscreen? The supplied GUI app or something else? Naive x 0\ny 0\nS 0\n won't typically lead to any visible changes.

MGlolenstine commented 4 years ago

I've actually created a Rust application that reads data from a real touchscreen via I2c and then forwards data to the /dev/virtual_touchscreen.

Example data that's sent to the file (I output it from my program for debugging purposes) ``` "x 151\ny 179\nS 0\n" "d 0\nS 0\n" "x 151\ny 179\nS 0\n" "x 151\ny 179\nS 0\n" "x 152\ny 176\nS 0\n" "x 155\ny 173\nS 0\n" "x 159\ny 170\nS 0\n" "x 165\ny 167\nS 0\n" "x 173\ny 164\nS 0\n" "x 183\ny 163\nS 0\n" "x 193\ny 162\nS 0\n" "x 204\ny 162\nS 0\n" "x 214\ny 163\nS 0\n" "x 223\ny 164\nS 0\n" "x 230\ny 166\nS 0\n" "x 234\ny 168\nS 0\n" "x 237\ny 170\nS 0\n" "x 238\ny 173\nS 0\n" "x 238\ny 175\nS 0\n" "x 238\ny 178\nS 0\n" "x 237\ny 181\nS 0\n" "x 234\ny 184\nS 0\n" "x 230\ny 188\nS 0\n" "x 224\ny 191\nS 0\n" "x 218\ny 193\nS 0\n" "x 212\ny 194\nS 0\n" "x 205\ny 193\nS 0\n" "x 197\ny 191\nS 0\n" "x 188\ny 188\nS 0\n" "x 180\ny 184\nS 0\n" "x 173\ny 180\nS 0\n" "x 169\ny 175\nS 0\n" "x 166\ny 169\nS 0\n" "x 163\ny 163\nS 0\n" "x 163\ny 158\nS 0\n" "x 163\ny 154\nS 0\n" "x 164\ny 151\nS 0\n" "x 167\ny 147\nS 0\n" "x 171\ny 143\nS 0\n" "x 177\ny 141\nS 0\n" "x 184\ny 139\nS 0\n" "x 192\ny 139\nS 0\n" "x 199\ny 140\nS 0\n" "x 206\ny 143\nS 0\n" "x 211\ny 145\nS 0\n" "x 214\ny 148\nS 0\n" "x 216\ny 151\nS 0\n" "x 216\ny 153\nS 0\n" "x 215\ny 155\nS 0\n" "x 214\ny 157\nS 0\n" "x 213\ny 158\nS 0\n" "x 211\ny 160\nS 0\n" "x 208\ny 160\nS 0\n" "x 205\ny 161\nS 0\n" "x 199\ny 160\nS 0\n" "x 190\ny 158\nS 0\n" "x 179\ny 155\nS 0\n" "x 168\ny 149\nS 0\n" "x 158\ny 143\nS 0\n" "x 150\ny 137\nS 0\n" "x 145\ny 133\nS 0\n" "x 143\ny 128\nS 0\n" "x 143\ny 124\nS 0\n" "x 145\ny 120\nS 0\n" "x 145\ny 120\nS 0\n" "u 0\nS 0\n" ```
vi commented 4 years ago

Maybe you need to issue more commands?

Here is example output of the GUI app: https://github.com/vi/virtual_touchscreen/blob/master/example_commands.txt

Feeding this file to the device makes mouse move and click in Xorg:

pv -L100 example_commands.txt > /dev/virtual_touchscreen
MGlolenstine commented 4 years ago

This indeed is interesting. Your example data does move the mouse.

Would you be able to elaborate more on T and : commands I saw in the example_commands?

vi commented 4 years ago

I don't remember much myself. Need to dig the source code.

When I was implementing it, I mostly used trial and error until it worked.

MGlolenstine commented 4 years ago

Oh, I see... Then I guess I'll just have to do the same.

Thanks for your help and showing me that the dmesg error is nothing to worry about.

vi commented 4 years ago

Maybe if I remember the command set and properly document it, a Rust crate for a proper API for driving the virtual_touchscreen can be published. Are you interested in doing or reviewing it?

MGlolenstine commented 4 years ago

To be fair, I'm quite new to Rust myself, but I'd surely be up to doing that.

MGlolenstine commented 4 years ago

I just figured what the problem is. I was using x and y, but those two don't execute events, that's why the mouse wasn't moving. Now that I changed it to X and Y, the mouse cursor moves.

Current (working) output ``` "s 0\nS 0\n" "d 0\nS 0\n" "X 138\nY 155\nS 0\n" "X 138\nY 155\nS 0\n" "X 138\nY 155\nS 0\n" "X 138\nY 155\nS 0\n" "X 138\nY 155\nS 0\n" "X 138\nY 155\nS 0\n" "X 140\nY 156\nS 0\n" "X 146\nY 161\nS 0\n" "X 159\nY 168\nS 0\n" "X 176\nY 174\nS 0\n" "X 196\nY 179\nS 0\n" "X 217\nY 182\nS 0\n" "X 239\nY 183\nS 0\n" "X 260\nY 184\nS 0\n" "X 280\nY 183\nS 0\n" "X 300\nY 180\nS 0\n" "X 318\nY 173\nS 0\n" "X 335\nY 164\nS 0\n" "X 349\nY 152\nS 0\n" "X 360\nY 142\nS 0\n" "X 368\nY 132\nS 0\n" "X 373\nY 124\nS 0\n" "X 374\nY 118\nS 0\n" "X 372\nY 114\nS 0\n" "X 364\nY 108\nS 0\n" "X 348\nY 101\nS 0\n" "X 326\nY 93\nS 0\n" "X 299\nY 87\nS 0\n" "X 270\nY 85\nS 0\n" "X 241\nY 85\nS 0\n" "X 211\nY 90\nS 0\n" "X 184\nY 98\nS 0\n" "X 162\nY 107\nS 0\n" "X 147\nY 119\nS 0\n" "X 138\nY 132\nS 0\n" "X 135\nY 144\nS 0\n" "X 139\nY 156\nS 0\n" "X 148\nY 165\nS 0\n" "X 148\nY 165\nS 0\n" "u 0\nS 0\n" ```
vi commented 4 years ago

Note: issuing cat /dev/virtual_touchscreen shows a help message about commands.

MGlolenstine commented 4 years ago

I've noticed that, but most of the descriptions aren't really verbose and could be misinterpreted (imo).

I've created/reserved a crate on crates.io and also made a repository on GitHub for it.

vi commented 4 years ago

Looks empty. Also *-rs is not the recommended name for Rust crates (no need to change it just because of that, as you have already reserved it). Also crate reservations are sometimes frowned upon in the Rust community.

If you want me to review the crate, you can write a comment here when you publish the real version.

MGlolenstine commented 4 years ago

I did not know about the *-rs naming scheme, but good to know for the future crates.

It currently still is empty, as I just finished with work and am on my way home. I'll write it when I get home.

I've only reserved the crate so I wouldn't forget to do it later 😅. I hope crate reservations for few hours aren't being frowned upon too hard.

MGlolenstine commented 4 years ago

@vi I've committed a basic crate, which I hope should do until we figure out more. The crate has no tests yet, but I'm planning on writing them.

Please review last few commits and the crate, when you find the time. Source and Crate