gvalkov / python-evdev

Python bindings for the Linux input subsystem
https://python-evdev.rtfd.org/
BSD 3-Clause "New" or "Revised" License
337 stars 112 forks source link

Surface Dial Haptics #179

Closed ThreepE0 closed 2 years ago

ThreepE0 commented 2 years ago

Hello and thank you for this code. I'm trying to get haptics working on the Surface Dial and I am hopelessly lost. Would absolutely be willing to pay for your time and assistance in getting this working.

In your examples I see searching for FF force feedback events, but the Surface Dial doesn't appear to support that. Here's the output from capabilities:

{('EV_SYN', 0): [('SYN_REPORT', 0), ('SYN_CONFIG', 1), ('?', 4)], ('EV_KEY', 1): [('KEY_SLEEP', 142),                              ('KEY_WAKEUP', 143)], ('EV_MSC', 4): [('MSC_SCAN', 4)]}
{('EV_SYN', 0): [('SYN_REPORT', 0), ('SYN_CONFIG', 1), ('SYN_MT_REPORT', 2), ('?', 4)], ('EV_KEY', 1)                             : [(['BTN_0', 'BTN_MISC'], 256)], ('EV_REL', 2): [('REL_DIAL', 7)], ('EV_MSC', 4): [('MSC_SCAN', 4)]}
{('EV_SYN', 0): [('SYN_REPORT', 0), ('SYN_CONFIG', 1), ('SYN_DROPPED', 3), ('?', 4)], ('EV_KEY', 1):                              [('BTN_TOUCH', 330)], ('EV_ABS', 3): [(('ABS_X', 0), AbsInfo(value=0, min=0, max=4096, fuzz=0, flat=0                             , resolution=8)), (('ABS_Y', 1), AbsInfo(value=0, min=0, max=4096, fuzz=0, flat=0, resolution=14)), (                             ('ABS_MT_SLOT', 47), AbsInfo(value=0, min=0, max=9, fuzz=0, flat=0, resolution=0)), (('ABS_MT_POSITIO                             N_X', 53), AbsInfo(value=0, min=0, max=4096, fuzz=0, flat=0, resolution=8)), (('ABS_MT_POSITION_Y', 5                             4), AbsInfo(value=0, min=0, max=4096, fuzz=0, flat=0, resolution=14)), (('ABS_MT_TRACKING_ID', 57), A                             bsInfo(value=0, min=0, max=65535, fuzz=0, flat=0, resolution=0))], ('EV_MSC', 4): [('MSC_TIMESTAMP',                              5)]}

I noticed this other repo seems to have gotten the haptics working via other means, but I don't know enough about Rust or hid devices to figure out what's happening. I'm working on a headless device and the app written here wouldn't be a good fit for me: https://github.com/daniel5151/surface-dial-linux

sezanzeb commented 2 years ago

I don't have a surface, so I don't think I'll be able to reproduce anything here.

However, it seems the capabilities output is cut off.

Checking the output of sudo evtest might also be interesting besides the complete capabilities. If there are EV_FF events incoming, I would expect evtest to show them. evtest also shows capabilities by the way.

In evtest, there might be multiple input devices for your dial. Make sure to check all of them.

ThreepE0 commented 2 years ago

Hello, thank you so much for the reply, I appreciate it. Evtest doesn't show any haptic events incoming as they happen on this device it seems.

Playing around a bit, I was able to get the hidapi library to work by writing to the /dev/hidraw1 device:

device = hidraw.device() device.open(1118,2331) test = device.write([0x01, 0x01, 0x03, 0x00, 0x00]) I'd like to boil it down to a single library instead of using one for haptics and one for reading if possible.

I'm wondering if evdev can be used to write this string, and if so, is it set up to interface with hidraw devices?

Sorry for being obtuse, I'm a bit out of my comfort zone and I've been on a journey trying to learn this stuff over the last two days.

sezanzeb commented 2 years ago

I'm wondering if evdev can be used to write this string, and if so, is it set up to interface with hidraw devices?

I'm pretty sure this is not possible with python-evdev.

I tried to find information how hidraw, hiddev and evdev are connected, but couldn't find stuff. The proper solution might be to create an evdev device in /dev/input/ for the dial, which I don't know how that works. It might require writing kernel drivers