jahnf / Projecteur

Linux Desktop Application for the Logitech Spotlight device (and similar devices) - Digital Laser Pointer
MIT License
379 stars 33 forks source link

Support for AVATTO H100 Spotlight 2.4GHz Wireless Digital Laser Pointer #27

Closed alezzandro closed 4 years ago

alezzandro commented 5 years ago

Hi!

A friend of mine just bought this little digital pointer on the net. https://www.aliexpress.com/item/32931337912.html

Any chances to get it work with this application?

I can take additional HW info if needed:

I: Bus=0003 Vendor=046a Product=0011 Version=0111
N: Name="HID 046a:0011"
P: Phys=usb-0000:00:14.0-4.3/input0
S: Sysfs=/devices/pci0000:00/0000:00:14.0/usb1/1-4/1-4.3/1-4.3:1.0/0003:046A:0011.000D/input/input31
U: Uniq=
H: Handlers=sysrq kbd leds event20 
B: PROP=0
B: EV=120013
B: KEY=1000000000007 ff980000000007ff febeffdfffefffff fffffffffffffffe
B: MSC=10
B: LED=7

I: Bus=0003 Vendor=0c45 Product=8101 Version=0101
N: Name="USB USB Device Consumer Control"
P: Phys=usb-0000:00:14.0-2.4/input0
S: Sysfs=/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2.4/1-2.4:1.0/0003:0C45:8101.000E/input/input32
U: Uniq=
H: Handlers=kbd event21 
B: PROP=0
B: EV=1f
B: KEY=3f000300ff 0 0 483ffff17aff32d bfd4444600000000 1 130ff38b17c000 677bfad9415fed 19ed68000004400 10000002
B: REL=1040
B: ABS=100000000
B: MSC=10

I: Bus=0003 Vendor=0c45 Product=8101 Version=0101
N: Name="USB USB Device System Control"
P: Phys=usb-0000:00:14.0-2.4/input0
S: Sysfs=/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2.4/1-2.4:1.0/0003:0C45:8101.000E/input/input33
U: Uniq=
H: Handlers=kbd event22 
B: PROP=0
B: EV=13
B: KEY=40000000000000 0 0 0 40000010cc00 10000000000000 0
B: MSC=10

I: Bus=0003 Vendor=0c45 Product=8101 Version=0101
N: Name="USB USB Device Keyboard"
P: Phys=usb-0000:00:14.0-2.4/input0
S: Sysfs=/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2.4/1-2.4:1.0/0003:0C45:8101.000E/input/input34
U: Uniq=
H: Handlers=sysrq kbd leds event23 
B: PROP=0
B: EV=120013
B: KEY=1000000000007 ff9f207ac14057ff febeffdfffefffff fffffffffffffffe
B: MSC=10
B: LED=1f

I: Bus=0003 Vendor=0c45 Product=8101 Version=0101
N: Name="USB USB Device"
P: Phys=usb-0000:00:14.0-2.4/input1
S: Sysfs=/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2.4/1-2.4:1.1/0003:0C45:8101.000F/input/input35
U: Uniq=
H: Handlers=mouse3 event24 
B: PROP=0
B: EV=17
B: KEY=1f0000 0 0 0 0
B: REL=903
B: MSC=10

I: Bus=0003 Vendor=0c45 Product=8101 Version=0101
N: Name="USB USB Device"
P: Phys=usb-0000:00:14.0-2.4/input3
S: Sysfs=/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2.4/1-2.4:1.3/0003:0C45:8101.0011/input/input36
U: Uniq=
H: Handlers=event25 js0 
B: PROP=0
B: EV=1b
B: KEY=7fff000000000000 0 0 0 0
B: ABS=1000003063f
B: MSC=10
rj-jesus commented 5 years ago

If I'm not mistaken you could get it to work by adjusting the udev rule to

# Rule for USB Receiver
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0c45", ATTRS{idProduct}=="8101", MODE="660", GROUP="plugdev", ENV{USB_HUB_TYPE}="0c45:8101"

and modifying the vendor and product IDs in spotlight.cc:

-  constexpr quint16 vendorId = 0x46d;
-  constexpr quint16 usbProductId = 0xc53e;
+  constexpr quint16 vendorId = 0x0c45;
+  constexpr quint16 usbProductId = 0x8101;

I would also be interested in this!

jahnf commented 5 years ago

Hi, I am not familiar with that device, but if it works similar to the Logitech one it should be possible the way @rj-jesus already described. I am also interested in the outcome. In September/October I will allocate some time to work on this project and documentation. Would be cool to include another device.

alezzandro commented 5 years ago

Yes! :)

@rj-jesus I've already tried editing the udev rules and the code without success, it could be really useful to have some documentation and some debug output to see where the Device has been rejected as "Not Spotlight". I've also tried commenting out some other checks that the code makes for ensuring that the device is a Spotlight one, for example:

  /* unsigned long bitmask = 0;
  const int len = ioctl(evfd, EVIOCGBIT(0, sizeof(bitmask)), &bitmask);
  if ( len < 0 )
  {
    ::close(evfd);
    return ConnectionResult::NotASpotlightDevice;
  }

  const bool hasRelEv = !!(bitmask & (1 << EV_REL));
  if (!hasRelEv) { return ConnectionResult::NotASpotlightDevice; } */

@jahnf if you can share some docs or include some Debug / Verbose output on the command line it could be really useful.

I don't own a Logitech device but in the meantime I can confirm you that this device seems to work fine with Linux, if I keep pressed the single button on top then the mouse-like input is activated and then moving the device around let the mouse pointer move aroung too on the screen.

rj-jesus commented 5 years ago

@alezzandro

I actually have one of these devices (arrived like two days ago, what a coincidence!) and I could get it recognized with the modifications I wrote above.

Maybe you're not a member of the plugdev group? I pasted the rule in a hurry and failed to mention I had edited the group assigned to the device so as to avoid having to create a new one just for this.

Check the groups you're a member of and confirm you're in plugdev. Otherwise just change the group in the rule to one you're member of.

-- Ricardo Jesus

jahnf commented 5 years ago

Well basically at startup in connectDevices() we loop over all devices in /dev/input starting with event*

You should not just disable the checks, just add some Debug output yourself. ( I know debug output is missing currently, but will be added in the next version..) For example you can do sth like: (include the <QDebug> header at top of spotlight.cc)

  const int evfd = ::open(devicePath.toLocal8Bit().constData(), O_RDONLY, 0);
  if (evfd < 0) {
    qDebug() << "*** Could not open" << devicePath;
    return ConnectionResult::CouldNotOpen;
  }

  struct input_id id{};
  ioctl(evfd, EVIOCGID, &id);

  constexpr quint16 vendorId = 0x46d;
  constexpr quint16 usbProductId = 0xc53e;
  constexpr quint16 btProductId = 0xb503;

  if (id.vendor != vendorId || (id.product != usbProductId && id.product != btProductId))
  {
    qDebug() << "*** VENDOR or PRODUCT id mismatch for: " << devicePath;
    ::close(evfd);
    return ConnectionResult::NotASpotlightDevice;
  }

  unsigned long bitmask = 0;
  const int len = ioctl(evfd, EVIOCGBIT(0, sizeof(bitmask)), &bitmask);
  if ( len < 0 )
  {
    qDebug() << "*** Could not get Info via iotcl for:  " << devicePath;
    ::close(evfd);
    return ConnectionResult::NotASpotlightDevice;
  }

  const bool hasRelEv = !!(bitmask & (1 << EV_REL));
  if (!hasRelEv) { 
    qDebug() << "*** Device has no support for relative Mouse Events:  " << devicePath;
    return ConnectionResult::NotASpotlightDevice; 
  }
alezzandro commented 5 years ago

Thanks @rj-jesus !!!

It worked perfectly with your suggested changes.

@jahnf Can we move externally the device ID configuration?

Thanks, BR

If I'm not mistaken you could get it to work by adjusting the udev rule to

# Rule for USB Receiver
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0c45", ATTRS{idProduct}=="8101", MODE="660", GROUP="plugdev", ENV{USB_HUB_TYPE}="0c45:8101"

and modifying the vendor and product IDs in spotlight.cc:

-  constexpr quint16 vendorId = 0x46d;
-  constexpr quint16 usbProductId = 0xc53e;
+  constexpr quint16 vendorId = 0x0c45;
+  constexpr quint16 usbProductId = 0x8101;

I would also be interested in this!

jahnf commented 5 years ago

Can we move externally the device ID configuration?

I'll note that for the next minor release, probably allowing adding additional vendor/product ids in a config file or something similar.

jahnf commented 4 years ago

Relates to #31

alinelena commented 4 years ago

got one of these https://www.aliexpress.com/item/32825980124.html?spm=a2g0s.9042311.0.0.32254c4dCk669u i10 pro version... and confirm works after some changes on current git.

SUBSYSTEMS=="usb", ATTRS{idVendor}=="2571", ATTRS{idProduct}=="4109", MODE="0660", TAG+="uaccess"

and in the src/spotlight.cc add line 30

  26   // List of supported devices                                                                                                      
  27   const std::vector<Device> supportedDevices {                                                                                      
  28     {0x46d, 0xc53e, false},  // Logitech Spotlight (USB)                                                                            
  29     {0x46d, 0xb503, true},   // Logitech Spotlight (Bluetooth)                                                                      
  30     {0x2571, 0x4109, false},   // AVATTO i10 pro (USB)                                                                          
  31   };

spotlight works as expected.

few comments. this seems to have some cycling functions, spotlight/zoom/digital laser. I need to see what events are sent for cycling throw them. volume up and down with long press already works.

a nice feature will be to use the device list to generate the udev file.

Alin

jahnf commented 4 years ago

Support is planned. :white_check_mark: I didn't have much time lately for the project but expect new features soon.

jahnf commented 4 years ago

@alinelena You can give the feature branch https://github.com/jahnf/Projecteur/tree/feature/pointer-mode-uinput-dev a try - there is now a devices.conf file that will be read by the CMake build during configuration time.

This will do two things: 1) Devices listed in the file will be be detected as supported by the compiled application 2) The generated udev rule file will also include these devices.

alinelena commented 4 years ago

It works indeed.

two issues I had

  1. i get an error messaged on accesing /dev/uinput i access denied... which is correct since is root only
  2. after i crashed the app I cannot start it due to
    Another application instance is already running. Exiting.

which instance does not seem to exist.

jahnf commented 4 years ago

Thanks for giving it a try.

  1. i get an error messaged on accesing /dev/uinput i access denied... which is correct since is root only

Did you also use the newly generated udev rule file? (And reloaded the rules?) The branch also introduces using uinput for custom button mappings (work in progress) In the newly generated udev rule file there should be a rule to make uinput accessible to the user.

  1. after i crashed the app I cannot start it due Another instance running

The instance is there, but it seems that the message box is preventing the system tray to show up. I will look into this (you can exit a running instance with projecteur -c quit)

alinelena commented 4 years ago

Rules reloaded the same error but permissions are l like this so is normal shall i create a uinput group?

crw------- 1 root root 10, 223 Feb  5 21:22 /dev/uinput

thanks indeed kicked it out.

jahnf commented 4 years ago

Interesting, does your rule file (/lib/udev/rules.d/55-spotlight.rules) contain the following rule?

KERNEL=="uinput", SUBSYSTEM=="misc", TAG+="uaccess", OPTIONS+="static_node=uinput"

(This rule is borrowed from Steam (See: https://github.com/ValveSoftware/steam-devices/issues/2)

Maybe there is a clash with a rule from another file on your system??

alinelena commented 4 years ago

ok the rule was ok but reloading the rules was not enough I had to restart the computer... now the uinput is fine.

I still have to figure out how to catch the lateral buttons codes... they do not show in xev but they interact with the volume...

jahnf commented 4 years ago

I still have to figure out how to catch the lateral buttons codes... they do not show in xev but they interact with the volume...

Yeah, This is a work in progress and is closely linked to the general feature request "Button Mapping"- The Logitech Spotlight device for example does register as two different devices (with the USB dongle) for example: One mouse and one keyboard device.

Currently only the Mouse devices and events are actually considered within the code. So there is the need for refactoring and restructuring to support devices that act as one but are actually two or more actual registered devices at system level.

alinelena commented 4 years ago

Great I see that makes sense I shall check on mine to see what happens.

[ 2907.990849] xhci_hcd 0000:39:00.0: xHCI Host Controller
[ 2907.990853] xhci_hcd 0000:39:00.0: new USB bus registered, assigned bus number 3
[ 2907.991969] xhci_hcd 0000:39:00.0: hcc params 0x200077c1 hci version 0x110 quirks 0x0000000200009810
[ 2907.992474] usb usb3: New USB device found, idVendor=1d6b, idProduct=0002, bcdDevice= 5.04
[ 2907.992475] usb usb3: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[ 2907.992476] usb usb3: Product: xHCI Host Controller
[ 2907.992477] usb usb3: Manufacturer: Linux 5.4.14-2-default xhci-hcd
[ 2907.992477] usb usb3: SerialNumber: 0000:39:00.0
[ 2907.992690] hub 3-0:1.0: USB hub found
[ 2907.992705] hub 3-0:1.0: 2 ports detected
[ 2907.993207] xhci_hcd 0000:39:00.0: xHCI Host Controller
[ 2907.993210] xhci_hcd 0000:39:00.0: new USB bus registered, assigned bus number 4
[ 2907.993213] xhci_hcd 0000:39:00.0: Host supports USB 3.1 Enhanced SuperSpeed
[ 2907.993441] usb usb4: New USB device found, idVendor=1d6b, idProduct=0003, bcdDevice= 5.04
[ 2907.993442] usb usb4: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[ 2907.993443] usb usb4: Product: xHCI Host Controller
[ 2907.993444] usb usb4: Manufacturer: Linux 5.4.14-2-default xhci-hcd
[ 2907.993445] usb usb4: SerialNumber: 0000:39:00.0
[ 2907.993611] hub 4-0:1.0: USB hub found
[ 2907.993621] hub 4-0:1.0: 2 ports detected
[ 2908.325901] usb 3-1: new low-speed USB device number 2 using xhci_hcd
[ 2908.483820] usb 3-1: New USB device found, idVendor=2571, idProduct=4109, bcdDevice= 1.00
[ 2908.483828] usb 3-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 2908.483832] usb 3-1: Manufacturer: Wireless Present
[ 2908.490358] hid-generic 0003:2571:4109.000A: ignoring exceeding usage max
[ 2908.490708] hid-generic 0003:2571:4109.000A: ignoring exceeding usage max
[ 2908.490991] hid-generic 0003:2571:4109.000A: ignoring exceeding usage max
[ 2908.492293] input: Wireless Present Keyboard as /devices/pci0000:00/0000:00:1c.4/0000:03:00.0/0000:04:02.0/0000:39:00.0/usb3/3-1/3-1:1.0/0003:2571:4109.000A/input/input50
[ 2908.550221] input: Wireless Present Consumer Control as /devices/pci0000:00/0000:00:1c.4/0000:03:00.0/0000:04:02.0/0000:39:00.0/usb3/3-1/3-1:1.0/0003:2571:4109.000A/input/input51
[ 2908.550696] hid-generic 0003:2571:4109.000A: input,hiddev96,hidraw3: USB HID v1.11 Keyboard [Wireless Present] on usb-0000:39:00.0-1/input0
[ 2908.553141] input: Wireless Present as /devices/pci0000:00/0000:00:1c.4/0000:03:00.0/0000:04:02.0/0000:39:00.0/usb3/3-1/3-1:1.1/0003:2571:4109.000B/input/input53
[ 2908.553402] hid-generic 0003:2571:4109.000B: input,hidraw4: USB HID v1.11 Mouse [Wireless Present] on usb-0000:39:00.0-1/input1
[ 2913.086125] pci_bus 0000:04: Allocating resources
[ 2913.086144] pcieport 0000:04:01.0: bridge window [io  0x1000-0x0fff] to [bus 06-38] add_size 1000
[ 2913.086146] pcieport 0000:04:02.0: bridge window [io  0x1000-0x0fff] to [bus 39] add_size 1000
[ 2913.086148] pcieport 0000:04:02.0: bridge window [mem 0x00100000-0x000fffff 64bit pref] to [bus 39] add_size 200000 add_align 100000
[ 2913.086149] pcieport 0000:04:04.0: bridge window [io  0x1000-0x0fff] to [bus 3a-6d] add_size 1000
[ 2913.086150] pcieport 0000:03:00.0: bridge window [io  0x1000-0x0fff] to [bus 04-6d] add_size 4000
[ 2913.086154] pcieport 0000:03:00.0: BAR 13: no space for [io  size 0x4000]
[ 2913.086155] pcieport 0000:03:00.0: BAR 13: failed to assign [io  size 0x4000]
[ 2913.086156] pcieport 0000:03:00.0: BAR 13: no space for [io  size 0x4000]
[ 2913.086157] pcieport 0000:03:00.0: BAR 13: failed to assign [io  size 0x4000]
[ 2913.086161] pcieport 0000:04:02.0: BAR 15: no space for [mem size 0x00200000 64bit pref]
[ 2913.086162] pcieport 0000:04:02.0: BAR 15: failed to assign [mem size 0x00200000 64bit pref]
[ 2913.086162] pcieport 0000:04:01.0: BAR 13: no space for [io  size 0x1000]
[ 2913.086163] pcieport 0000:04:01.0: BAR 13: failed to assign [io  size 0x1000]
[ 2913.086164] pcieport 0000:04:02.0: BAR 13: no space for [io  size 0x1000]
[ 2913.086165] pcieport 0000:04:02.0: BAR 13: failed to assign [io  size 0x1000]
[ 2913.086166] pcieport 0000:04:04.0: BAR 13: no space for [io  size 0x1000]
[ 2913.086166] pcieport 0000:04:04.0: BAR 13: failed to assign [io  size 0x1000]
[ 2913.086167] pcieport 0000:04:04.0: BAR 13: no space for [io  size 0x1000]
[ 2913.086168] pcieport 0000:04:04.0: BAR 13: failed to assign [io  size 0x1000]
[ 2913.086170] pcieport 0000:04:02.0: BAR 15: no space for [mem size 0x00200000 64bit pref]
[ 2913.086171] pcieport 0000:04:02.0: BAR 15: failed to assign [mem size 0x00200000 64bit pref]
[ 2913.086171] pcieport 0000:04:02.0: BAR 13: no space for [io  size 0x1000]
[ 2913.086172] pcieport 0000:04:02.0: BAR 13: failed to assign [io  size 0x1000]
[ 2913.086173] pcieport 0000:04:01.0: BAR 13: no space for [io  size 0x1000]
[ 2913.086174] pcieport 0000:04:01.0: BAR 13: failed to assign [io  size 0x1000]
jahnf commented 4 years ago

@alinelena

Rules reloaded the same error but permissions are l like this so is normal shall i create a uinput group?

I could reproduce the issue that the uinput rule was only working after a system restart on one of my systems. At least on my system a workaround was to run modprobe uinput - it seemed that the uniput module was not loaded - after that the rule was applied correctly without a reboot. If that is the case more systems I will either put modprobe uinput into the post-install commands (for generated packages) or put it as information in the troubleshooting section.

jahnf commented 4 years ago

I'm closing this issue since support for Avatto H100 (and other devices) is implemented in the current develop version. The feature for default and custom Key mappings for mouse and non-mouse events is addressed in other issues.