FreeSpacenav / spnavcfg

Spacenav interactive configuration GUI
GNU General Public License v3.0
59 stars 16 forks source link

Magellan SpaceMouse Plus XT USB: Assertion fail on button press #25

Closed thomask77 closed 2 years ago

thomask77 commented 2 years ago

Spacenav crashes with an assertion error, as soon as I press a button on my Magellan SpaceMouse

spnavcfg: src/ui.cc:321: void MainWin::spnav_input(): Assertion `ev.button.bnum < bnrow_count' failed.
[1]    11295 IOT instruction (core dumped)  spnavcfg
jtsiomb commented 2 years ago

Can you run with a debugger and examine the values of ev.button.bnum and bnrow_count when that happens ?

thomask77 commented 2 years ago

bnrow_count is 12.

But when I press buttons, ev.button.bnum is:

So there seems to be an offset of 32.

I'm also not sure, if bnrow_count == 12 is correct. My Magellan SpaceMouse Plus XT only seems to have the 11 buttons listed above.

thomask77 commented 2 years ago

Quick follow up:

The manual says, that there's a virtual 12th "Quick Tip" button, that can be activated by quickly tapping on the controller. But that doesn't seem to be implemented at all. It really has only 11 hardware buttons.

https://www.microsoft.com/buxtoncollection/a/pdf/Magellan%20Manual.pdf

jtsiomb commented 2 years ago

Interesting. I have no idea why the raw button numbers start from 32. That shouldn't happen. I'll have to connect my magellan spacemouse and try to reproduce this.

Could you paste the spacenavd log file? It should be /var/log/spnavd.log. If it is too long use pastebin or upload it somewhere.

thomask77 commented 2 years ago

Here's a log file after starting spacenavd, plugging in my USB device, starting spnavcfg and pressing "1" (-> crash)

spnavd.log

thomask77 commented 2 years ago

And here's output from lsusb if that helps:

# echo -n 3-2:1.0 >/sys/bus/usb/drivers/usbhid/unbind   # unbind from HID to see descriptors
# lsusb -d 046d:c603 -v

Bus 003 Device 007: ID 046d:c603 Logitech, Inc. 3Dconnexion Spacemouse Plus XT
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.01
  bDeviceClass            0 
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0         8
  idVendor           0x046d Logitech, Inc.
  idProduct          0xc603 3Dconnexion Spacemouse Plus XT
  bcdDevice            1.00
  iManufacturer           4 LogiCad3D
  iProduct               24 Magellan Plus USB
  iSerial                 0 
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x0022
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration         60 Standard Configuration
    bmAttributes         0x80
      (Bus Powered)
    MaxPower              100mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      0 
      bInterfaceProtocol      0 
      iInterface            106 HID 3D-Input-Device Interface
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
          bcdHID               1.01
          bCountryCode            0 Not supported
          bNumDescriptors         1
          bDescriptorType        34 Report
          wDescriptorLength      99
          Report Descriptor: (length is 99)
            Item(Global): Usage Page, data= [ 0x01 ] 1
                            Generic Desktop Controls
            Item(Local ): Usage, data= [ 0x04 ] 4
                            Joystick
            Item(Main  ): Collection, data= [ 0x01 ] 1
                            Application
            Item(Global): Usage Page, data= [ 0x09 ] 9
                            Buttons
            Item(Global): Logical Minimum, data= [ 0x00 ] 0
            Item(Global): Logical Maximum, data= [ 0x01 ] 1
            Item(Local ): Usage Minimum, data= [ 0x01 ] 1
                            Button 1 (Primary)
            Item(Local ): Usage Maximum, data= [ 0x0c ] 12
                            (null)
            Item(Global): Report Count, data= [ 0x0c ] 12
            Item(Global): Report Size, data= [ 0x01 ] 1
            Item(Main  ): Input, data= [ 0x02 ] 2
                            Data Variable Absolute No_Wrap Linear
                            Preferred_State No_Null_Position Non_Volatile Bitfield
            Item(Global): Report Count, data= [ 0x01 ] 1
            Item(Global): Report Size, data= [ 0x04 ] 4
            Item(Main  ): Input, data= [ 0x03 ] 3
                            Constant Variable Absolute No_Wrap Linear
                            Preferred_State No_Null_Position Non_Volatile Bitfield
            Item(Global): Usage Page, data= [ 0x01 ] 1
                            Generic Desktop Controls
            Item(Local ): Usage, data= [ 0x01 ] 1
                            Pointer
            Item(Main  ): Collection, data= [ 0x00 ] 0
                            Physical
            Item(Local ): Usage, data= [ 0x30 ] 48
                            Direction-X
            Item(Local ): Usage, data= [ 0x31 ] 49
                            Direction-Y
            Item(Local ): Usage, data= [ 0x32 ] 50
                            Direction-Z
            Item(Local ): Usage, data= [ 0x33 ] 51
                            Rotate-X
            Item(Local ): Usage, data= [ 0x34 ] 52
                            Rotate-Y
            Item(Local ): Usage, data= [ 0x35 ] 53
                            Rotate-Z
            Item(Global): Logical Minimum, data= [ 0x0c 0xfe ] 65036
            Item(Global): Logical Maximum, data= [ 0xf4 0x01 ] 500
            Item(Global): Report Size, data= [ 0x10 ] 16
            Item(Global): Report Count, data= [ 0x06 ] 6
            Item(Main  ): Input, data= [ 0x02 ] 2
                            Data Variable Absolute No_Wrap Linear
                            Preferred_State No_Null_Position Non_Volatile Bitfield
            Item(Global): Usage Page, data= [ 0x01 ] 1
                            Generic Desktop Controls
            Item(Local ): Usage, data= [ 0x01 ] 1
                            Pointer
            Item(Local ): Usage, data= [ 0x46 ] 70
                            Vector
            Item(Global): Logical Minimum, data= [ 0x00 ] 0
            Item(Global): Logical Maximum, data= [ 0xff 0x00 ] 255
            Item(Global): Report Size, data= [ 0x08 ] 8
            Item(Global): Report Count, data= [ 0x0e ] 14
            Item(Main  ): Feature, data= [ 0x02 ] 2
                            Data Variable Absolute No_Wrap Linear
                            Preferred_State No_Null_Position Non_Volatile Bitfield
            Item(Global): Usage Page, data= [ 0x08 ] 8
                            LEDs
            Item(Local ): Usage Minimum, data= [ 0x4b ] 75
                            Generic Indicator
            Item(Local ): Usage Maximum, data= [ 0x4d ] 77
                            External Power Connected
            Item(Global): Logical Minimum, data= [ 0x00 ] 0
            Item(Global): Logical Maximum, data= [ 0x01 ] 1
            Item(Global): Report Count, data= [ 0x03 ] 3
            Item(Global): Report Size, data= [ 0x01 ] 1
            Item(Main  ): Output, data= [ 0x02 ] 2
                            Data Variable Absolute No_Wrap Linear
                            Preferred_State No_Null_Position Non_Volatile Bitfield
            Item(Global): Report Count, data= [ 0x01 ] 1
            Item(Global): Report Size, data= [ 0x05 ] 5
            Item(Main  ): Output, data= [ 0x03 ] 3
                            Constant Variable Absolute No_Wrap Linear
                            Preferred_State No_Null_Position Non_Volatile Bitfield
            Item(Main  ): End Collection, data=none
            Item(Main  ): End Collection, data=none
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0008  1x 8 bytes
        bInterval              10
Device Status:     0x0000
  (Bus Powered)
thomask77 commented 2 years ago

..and output from usbhid-dump when pressing buttons 1, 2 and 3:

$ sudo usbhid-dump -d 046d:c603 -ea
003:007:000:DESCRIPTOR         1661244230.482754
 05 01 09 04 A1 01 05 09 15 00 25 01 19 01 29 0C
 95 0C 75 01 81 02 95 01 75 04 81 03 05 01 09 01
 A1 00 09 30 09 31 09 32 09 33 09 34 09 35 16 0C
 FE 26 F4 01 75 10 95 06 81 02 05 01 09 01 09 46
 15 00 26 FF 00 75 08 95 0E B1 02 05 08 19 4B 29
 4D 15 00 25 01 95 03 75 01 91 02 95 01 75 05 91
 03 C0 C0

Starting dumping interrupt transfer stream
with 1 minute timeout.

003:007:000:STREAM             1661244232.159470
 01 00 00 00 00 00 00 00

003:007:000:STREAM             1661244232.167396
 00 00 00 00 00 00

003:007:000:STREAM             1661244232.559572
 00 00 FE FF 00 00 FF FF

003:007:000:STREAM             1661244232.567419
 00 00 01 00 00 00

003:007:000:STREAM             1661244233.544118
 02 00 00 00 00 00 00 00

003:007:000:STREAM             1661244233.552153
 00 00 00 00 00 00

003:007:000:STREAM             1661244233.960099
 00 00 00 00 FF FF 00 00

003:007:000:STREAM             1661244233.968071
 00 00 00 00 FE FF

003:007:000:STREAM             1661244234.975633
 04 00 FE FF FF FF FF FF

003:007:000:STREAM             1661244234.983472
 00 00 01 00 FE FF

003:007:000:STREAM             1661244235.392159
 00 00 00 00 00 00 00 00

003:007:000:STREAM             1661244235.400293
 00 00 00 00 00 00
jtsiomb commented 2 years ago

Thank you this is all very helpful. I thought you meant the serial Magellan SpaceMouse. I don't have a SpaceMouse Plus USB to test, but I will try to see if I can figure something out from the logs you provided.

thomask77 commented 2 years ago

I can also repeat the tests with a serial 1995-ish SpaceMouse Classic and a 2006 SpaceNavigator later!

thomask77 commented 2 years ago

My USB SpaceNavigator from ~2006 works. Left button is id 0, right button is id 1. I couldn't get my SpaceMouse Classic running, because I can't find a working USB-serial converter right now.

jtsiomb commented 2 years ago

Ok I see what the problem is.

First of all your USB HID report descriptor defines 12 buttons, so that part is correct.

The button offset comes from the fact that the device declares itself as a Joystick, which causes the linux kernel to start the button numbers from BTN_JOYSTICK (0x120), instead of BTN_MISC (0x100) which is what it does for other 3Dconnexion devices like the space navigator, which declares itself as a "Multi-axis Controller".

Spacenavd expects these devices to start from BTN_MISC, and therefore subtracts the constant offset of 256 from all reported button numbers, which is clearly not correct in this case.

In the very short term, if you want to use the device without crashes, go to the spacenavd source code, dev_usb_linux.c line 269, (case EV_KEY in read_evdev), and change it from inp->idx = iev.code - BTN_0; to inp->idx = iev.code - BTN_JOYSTICK;. I will go through the code soon and see if I can find a nice way to ensure it detects the offset correctly.

jtsiomb commented 2 years ago

I added button offset detection in spacenavd. Please try the latest revision and let me know if it fixes your problem. Also please post the line of the log file where it reports the number of buttons, which should now include the detected button offset (should be 288 in your case).

thomask77 commented 2 years ago

Just tested with the latest spacenavd version - problem is fixed!

$ sudo ./spacenavd -v -d
Spacenav daemon v1.0-5-ga067ab7
reading config file: /etc/spnavrc
failed to open config file /etc/spnavrc: No such file or directory. using defaults.
found usb device [46d:c603]: "LogiCad3D Magellan Plus USB" (/dev/input/event5) 
adding device (id: 0).
device name: LogiCad3D Magellan Plus USB
  Number of axes: 6 (6a 0r)
  Number of buttons: 12 (evdev offset: 288)
  Axis 0 value range: -500 - 500 (fuzz: 3)
  Axis 1 value range: -500 - 500 (fuzz: 3)
  Axis 2 value range: -500 - 500 (fuzz: 3)
  Axis 3 value range: -500 - 500 (fuzz: 3)
  Axis 4 value range: -500 - 500 (fuzz: 3)
  Axis 5 value range: -500 - 500 (fuzz: 3)
using device: LogiCad3D Magellan Plus USB (/dev/input/event5)
trying to open X11 display ":0.0"
   XAUTHORITY=/home/tkindler/.Xauthority
Using XTEST to send key events

Thanks a lot!

afhp-2020 commented 2 years ago

Similar problem here, Space Explorer USB, FreeBSD 13.1-RELEASE. "simple" test program reacts normally and reports all button presses.

spnavcfg "Buttons" tab is empty, and the program crashes when pressing any button, whether we're on this tab or not:

Assertion failed: (ev.button.bnum < bnrow_count), function spnav_input, file src/ui.cc, line 334.

A core dump is generated.

jtsiomb commented 2 years ago

Please post all details, including spacenavd log output, and what button numbers are reported by the simple program when you press each button on the device.

afhp-2020 commented 2 years ago

spacenavd output from the start of spnavcfg to the crash on button press:

client name: spnavcfg
request SET_EVMASK - ffff 0 0 0 0 0
request DEV_NAME - 0 0 0 0 0 0
request DEV_PATH - 0 0 0 0 0 0
request DEV_PATH - 0 0 0 0 0 0
request DEV_NBUTTONS - 0 0 0 0 0 0
request DEV_NAXES - 0 0 0 0 0 0
request DEV_TYPE - 0 0 0 0 0 0
request GCFG_SENS - 0 0 0 0 0 0
request GCFG_SENS_AXIS - 0 0 0 0 0 0
request GCFG_INVERT - 0 0 0 0 0 0
request GCFG_SWAPYZ - 0 0 0 0 0 0
request GCFG_LED - 0 0 0 0 0 0
request GCFG_GRAB - 0 0 0 0 0 0
request GCFG_SERDEV - 0 0 0 0 0 0
afhp-2020 commented 2 years ago

simple_x11 output with button pressed:

Label Reported
1     b(0)
2     b(1)
T     b(2)
L     b(3)
R     b(4)
F     b(5)
ESC   b(6)
ALT   b(7)
SHIFT b(8)
CTRL  b(9)
FIT   b(10)
PANEL b(11)
+     b(12)
-     b(13)
2D    b(14)
jtsiomb commented 2 years ago

I did not want just from the start of spnavcfg, but the whole log. In any case don't post it here. It's obviously not the same problem, Please create a new issue.

afhp-2020 commented 2 years ago

simple_af_unix output: Initially

spacenav AF_UNIX protocol version: 1
Device: 
Path: /dev/uhid0
Buttons: 0
Axes: 0

Pressing button 1 for the first time:

got button press event b(0)
got button press event b(16)
got button press event b(17)
got button press event b(18)
got button press event b(19)
got button press event b(20)
got button press event b(21)
got button press event b(22)
got button press event b(23)
got motion event: t(0, 0, 0) r(0, 0, 0)
got button release event b(0)
got button release event b(16)
got button release event b(17)
got button release event b(18)
got button release event b(19)
got button release event b(20)
got button release event b(21)
got button release event b(22)
got button release event b(23)
got motion event: t(0, 0, 0) r(0, 0, 0)

All subsequent 1 presses:

got button press event b(0)
got motion event: t(0, 0, 0) r(0, 0, 0)
got button release event b(0)
got motion event: t(0, 0, 0) r(0, 0, 0)

Button 2:

got button press event b(1)
got motion event: t(0, 0, 0) r(0, 0, 0)
got button release event b(1)
got motion event: t(0, 0, 0) r(0, 0, 0)

Button T:

got button press event b(2)
got motion event: t(0, 0, 0) r(0, 0, 0)
got button release event b(2)
got motion event: t(0, 0, 0) r(0, 0, 0)

... and so on, similar to the reports from simple_x11.

The actual, non-summarized output of simple_x11 is the same 4 lines per button as above, with "button press, motion, button release, motion" info ; it does not include the header with protocol info, axis count etc. simple_x11 also reports the first button press correctly.

afhp-2020 commented 2 years ago

Complete spacenavd log from starting the daemon, launching spnavcfg, pressing a button (spnavcfg crashes), stopping the daemon:

Spacenav daemon v1.1
reading config file: /usr/local/etc/spnavrc
Device detection, checking "/dev/uhid*"
checking "/dev/uhid0"... found usb device [46d:c627]: "SpaceExplorer" (/dev/uhid0) 
found usb device: [46d:c627]: "SpaceExplorer" (/dev/uhid0 )
adding device (id: 0).
BUG: Tried to add 6dof device flags to a device with 0 axes. Please report this as a bug
using device:  (/dev/uhid0)
trying to open X11 display ":0"
   XAUTHORITY=/home/alexisp/.Xauthority
Using XTEST to send key events
request SET_NAME - 616e7073 67666376 0 0 0 0
client name: spnavcfg
request SET_EVMASK - ffff 0 0 0 0 0
request DEV_NAME - 0 0 0 0 0 0
request DEV_PATH - 0 0 0 0 0 0
request DEV_PATH - 0 0 0 0 0 0
request DEV_NBUTTONS - 0 0 0 0 0 0
request DEV_NAXES - 0 0 0 0 0 0
request DEV_TYPE - 0 0 0 0 0 0
request GCFG_SENS - 0 0 0 0 0 0
request GCFG_SENS_AXIS - 0 0 0 0 0 0
request GCFG_INVERT - 0 0 0 0 0 0
request GCFG_SWAPYZ - 0 0 0 0 0 0
request GCFG_LED - 0 0 0 0 0 0
request GCFG_GRAB - 0 0 0 0 0 0
request GCFG_SERDEV - 0 0 0 0 0 0
adding dev event for device: /dev/uhid0
closing X11 connection to display ":0"
removing device:  (id: 0 path: /dev/uhid0)
removing pending device event of: /dev/uhid0
afhp-2020 commented 2 years ago

On Sun, Sep 11, 2022 at 3:43 PM John Tsiombikas @.***> wrote:

(I received this message directly via e-mail but I don't see it on github.)

In any case don't post it here. It's obviously not the same problem, Please create a new issue.

No problem, I will.

I did not want just from the start of spnavcfg, but the whole log.

However at this point I'm now unclear on which log(s) you want and on which timeframe ?

The latest spacenavd log I provided (only surrounding spnavcfg startup and crash) was recorded for the purpose of this bug chase. A previous log did not contain much more (a couple "Caught BadWindow, dropping client", that's all).

I do not have a complete work session log with spacenavd, since at this point no software outside of the test programs use it ; right now I only run the daemon to perform tests.

Regards, Alexis