Dell Active Pen PN350M 无法正常工作

Dell Active Pen PN350M 无法正常工作

我在 Dell Inspiron 15 7591 2-in-1 上运行 Ubuntu 20.04。笔记本电脑配有一支触控笔,即 Dell PN350M Active Pen,不幸的是,它在我的系统下无法正常工作。我发现这支笔使用 Microsoft Pen 协议与我的设备配对。以下是一些可能有助于解决此问题的输出。

我发现可以sudo evtest完美显示压力读数,但是xinput --test根本没有显示压力读数,并且尖端被视为按钮 1。

sudo evtest
[sudo] password for parth: 
No device specified, trying to scan all of /dev/input/event*
Available devices:
/dev/input/event0:  Lid Switch
/dev/input/event1:  Power Button
/dev/input/event2:  Sleep Button
/dev/input/event3:  AT Translated Set 2 keyboard
/dev/input/event4:  Integrated_Webcam_HD: Integrate
/dev/input/event5:  DELL0908:00 04F3:30E3 Mouse
/dev/input/event6:  Dell WMI hotkeys
/dev/input/event7:  Intel HID events
/dev/input/event8:  Intel HID 5 button array
/dev/input/event9:  PS/2 Generic Mouse
/dev/input/event10: 2.4G Mouse
/dev/input/event11: 2.4G Mouse
/dev/input/event12: DELL0908:00 04F3:30E3 Touchpad
/dev/input/event13: Video Bus
/dev/input/event14: Video Bus
/dev/input/event15: CUST0000:00 27C6:0118
/dev/input/event16: CUST0000:00 27C6:0118 Stylus
/dev/input/event17: CUST0000:00 27C6:0118 UNKNOWN
/dev/input/event18: sof-hda-dsp Headphone Mic
/dev/input/event19: sof-hda-dsp HDMI/DP,pcm=3
/dev/input/event20: sof-hda-dsp HDMI/DP,pcm=4
/dev/input/event21: sof-hda-dsp HDMI/DP,pcm=5
Select the device event number [0-21]: 16
Input driver version is 1.0.1
Input device ID: bus 0x18 vendor 0x27c6 product 0x118 version 0x100
Input device name: "CUST0000:00 27C6:0118 Stylus"
Supported events:
  Event type 0 (EV_SYN)
  Event type 1 (EV_KEY)
  Event type 3 (EV_ABS)
    Event code 47 (ABS_MT_SLOT)
      Value      0
      Min        0
      Max        9
    Event code 53 (ABS_MT_POSITION_X)
      Value      0
      Min        0
      Max     5760
      Resolution      17
    Event code 54 (ABS_MT_POSITION_Y)
      Value      0
      Min        0
      Max     3240
      Resolution      17
    Event code 57 (ABS_MT_TRACKING_ID)
      Value      0
      Min        0
      Max    65535
    Event code 58 (ABS_MT_PRESSURE)
      Value      0
      Min        0
      Max     1023
    Event code 59 (ABS_MT_DISTANCE)
      Value      0
      Min        0
      Max        1
Properties:
  Property type 1 (INPUT_PROP_DIRECT)
Testing ... (interrupt to exit)
Event: time 1599396868.187587, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value 43
Event: time 1599396868.187587, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 3767
Event: time 1599396868.187587, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 1597
Event: time 1599396868.187587, -------------- SYN_REPORT ------------
Event: time 1599396868.189591, type 3 (EV_ABS), code 59 (ABS_MT_DISTANCE), value 0
Event: time 1599396868.189591, type 3 (EV_ABS), code 58 (ABS_MT_PRESSURE), value 11
Event: time 1599396868.189591, -------------- SYN_REPORT ------------
xinput --test 15
motion a[0]=44467 a[1]=32959 
button press   1 a[0]=44467 a[1]=32959 
motion a[0]=44467 a[1]=32939 
motion a[0]=44490 a[1]=32919 
motion a[0]=44501 a[1]=32878 
motion a[0]=44524 a[1]=32858 
motion a[0]=44546 a[1]=32818 
motion a[0]=44592 a[1]=32757 
motion a[0]=44626 a[1]=32716 
motion a[0]=44672 a[1]=32676 
motion a[0]=44717 a[1]=32656 
motion a[0]=44774 a[1]=32615 
motion a[0]=44831 a[1]=32595 
motion a[0]=44888 a[1]=32575 
motion a[0]=44956 a[1]=32575 
motion a[0]=45013 a[1]=32575 
motion a[0]=45070 a[1]=32575 
motion a[0]=45127 a[1]=32555 
motion a[0]=45195 a[1]=32555 
motion a[0]=45252 a[1]=32534 
motion a[0]=45309 a[1]=32514 
motion a[0]=45366 a[1]=32494 
motion a[0]=45422 a[1]=32454 
motion a[0]=45491 a[1]=32433 
motion a[0]=45548 a[1]=32413 
motion a[0]=45616 a[1]=32393 
motion a[0]=45695 a[1]=32373 
motion a[0]=45775 a[1]=32332 
motion a[0]=45832 a[1]=32312 
motion a[0]=45877 a[1]=32292 
motion a[0]=45912 a[1]=32292 
motion a[0]=45934 a[1]=32272 
motion a[0]=45934 a[1]=32251 
motion a[0]=45946 a[1]=32231 
motion a[0]=45946 a[1]=32211 
motion a[0]=45946 a[1]=32191 
motion a[0]=45957 a[1]=32150 
motion a[0]=45957 a[1]=32110 
motion a[0]=45968 a[1]=32049 
motion a[0]=45980 a[1]=32009 
motion a[0]=45991 a[1]=31928 
motion a[0]=46048 a[1]=31665 
motion a[0]=46037 a[1]=31705 
motion a[0]=46105 a[1]=31422 
motion a[0]=46094 a[1]=31443 
motion a[0]=46105 a[1]=31402 
motion a[0]=46116 a[1]=31341 
motion a[0]=46116 a[1]=31341 
button release 1 a[0]=46116 a[1]=31341

任何帮助,将不胜感激!

答案1

我设法使用 evdev 和 libevdev 库创建了一个 Python 驱动程序。我正在创建一个虚拟设备,然后简单地传递我从触控笔找到的事件。它可以处理压力事件和跟踪,但我无法让按钮工作。

只需复制此文件并将其标记为可执行文件,您就会看到一个名为“Custom Stylus”的设备,它可以工作。为了使其无缝衔接,我将其添加到,gnome-session-properties以便在启动时运行脚本。

希望这可以帮助!

#!/usr/bin/env python3
import sys
import libevdev
import time
import evdev
from evdev import UInput, AbsInfo, ecodes
import os


def main(args):
    p = 0
    i = 0
    devices = evdev.list_devices()

    for dev in devices:
        # print('%-12i%s' % (p, evdev.InputDevice(dev).name))
        if evdev.InputDevice(dev).name == 'CUST0000:00 27C6:0118 Stylus':
            i = p
        p += 1

    # i=int(input("Enter number: "))

    device = evdev.InputDevice(devices[i])

    print(device)

    # print(mouse.capabilities(verbose=True))

    device.grab()

    x, y = 0, 0

    dev = libevdev.Device()
    dev.name = "Custom Stylus"

    dev.enable(libevdev.INPUT_PROP_DIRECT)
    dev.enable(libevdev.EV_KEY.BTN_TOOL_PEN)
    dev.enable(libevdev.EV_KEY.BTN_TOOL_RUBBER)
    # Click
    dev.enable(libevdev.EV_KEY.BTN_TOUCH)
    # Press button 1 on pen
    dev.enable(libevdev.EV_KEY.BTN_STYLUS)
    # Press button 2 on pen, see great doc
    dev.enable(libevdev.EV_KEY.BTN_STYLUS2)
    # Send absolute X coordinate
    dev.enable(libevdev.EV_ABS.ABS_X,
               libevdev.InputAbsInfo(minimum=0, maximum=5760, resolution=17))
    # Send absolute Y coordinate
    dev.enable(libevdev.EV_ABS.ABS_Y,
               libevdev.InputAbsInfo(minimum=0, maximum=3240, resolution=17))
    # Send absolute pressure
    dev.enable(libevdev.EV_ABS.ABS_PRESSURE,
               libevdev.InputAbsInfo(minimum=0, maximum=1023))
    dev.enable(libevdev.EV_SYN.SYN_REPORT)
    dev.enable(libevdev.EV_SYN.SYN_DROPPED)
    try:
        uinput = dev.create_uinput_device()
        print("New device at {} ({})".format(uinput.devnode, uinput.syspath))
        # Sleep for a bit so udev, libinput, Xorg, Wayland, ...
        # all have had a chance to see the device and initialize
        # it. Otherwise the event will be sent by the kernel but
        # nothing is ready to listen to the device yet. And it
        # will never be detected in the futur ;-)
        time.sleep(1)
        # Reports that the PEN is close to the surface
        # Important to make sure xinput can detect (and list)
        # the pen. Otherwise, it won't write anything in gimp.
        uinput.send_events([
            libevdev.InputEvent(libevdev.EV_KEY.BTN_TOUCH,
                                value=0),
            libevdev.InputEvent(libevdev.EV_KEY.BTN_TOOL_PEN,
                                value=1),
            libevdev.InputEvent(libevdev.EV_SYN.SYN_REPORT,
                                value=0),
        ])
        # Says that the pen it out of range of the tablet. Useful
        # to make sure you can move your mouse, and to avoid
        # strange things during the first draw.
        uinput.send_events([
            libevdev.InputEvent(libevdev.EV_KEY.BTN_TOUCH,
                                value=0),
            libevdev.InputEvent(libevdev.EV_KEY.BTN_TOOL_PEN,
                                value=0),
            libevdev.InputEvent(libevdev.EV_SYN.SYN_REPORT,
                                value=0),
        ])

        for event in device.read_loop():
            code, val = event.code, event.value

            if code == ecodes.ABS_MT_POSITION_X:
                uinput.send_events([
                    libevdev.InputEvent(libevdev.EV_ABS.ABS_X,
                                        value=int(val)),
                    libevdev.InputEvent(libevdev.EV_KEY.BTN_TOUCH,
                                        value=1),
                    libevdev.InputEvent(libevdev.EV_KEY.BTN_STYLUS,
                                        value=0),
                    libevdev.InputEvent(libevdev.EV_KEY.BTN_STYLUS2,
                                        value=0),
                    libevdev.InputEvent(libevdev.EV_KEY.BTN_TOOL_PEN,
                                        value=1),
                    libevdev.InputEvent(libevdev.EV_SYN.SYN_REPORT,
                                        value=0)])
                # vpen.write(ecodes.EV_ABS, ecodes.ABS_X, int(val))

            if code == ecodes.ABS_MT_POSITION_Y:
                uinput.send_events([
                    libevdev.InputEvent(libevdev.EV_ABS.ABS_Y,
                                        value=int(val)),
                    libevdev.InputEvent(libevdev.EV_KEY.BTN_TOUCH,
                                        value=1),
                    libevdev.InputEvent(libevdev.EV_KEY.BTN_STYLUS,
                                        value=0),
                    libevdev.InputEvent(libevdev.EV_KEY.BTN_STYLUS2,
                                        value=0),
                    libevdev.InputEvent(libevdev.EV_KEY.BTN_TOOL_PEN,
                                        value=1),
                    libevdev.InputEvent(libevdev.EV_SYN.SYN_REPORT,
                                        value=0)])

            if code == ecodes.ABS_MT_PRESSURE:
                uinput.send_events([
                    libevdev.InputEvent(libevdev.EV_ABS.ABS_PRESSURE,
                                        value=int(val)),
                    libevdev.InputEvent(libevdev.EV_KEY.BTN_TOUCH,
                                        value=1),
                    libevdev.InputEvent(libevdev.EV_KEY.BTN_STYLUS,
                                        value=0),
                    libevdev.InputEvent(libevdev.EV_KEY.BTN_STYLUS2,
                                        value=0),
                    libevdev.InputEvent(libevdev.EV_KEY.BTN_TOOL_PEN,
                                        value=1),
                    libevdev.InputEvent(libevdev.EV_SYN.SYN_REPORT,
                                        value=0)])

        device.ungrab()

    except KeyboardInterrupt:
        pass


if __name__ == "__main__":
    main(sys.argv)

相关内容