jfedor2 / magellan-spacemouse

Adapter to use RS-232 Magellan/SpaceMouse with modern software
36 stars 8 forks source link

Request to create firmware for space mouse classic usb #1

Open Platidors opened 1 year ago

Platidors commented 1 year ago

Hello. I assembled hid-remapper for your project on one raspberry pi pico board. Tried connecting my old Space Mouse Classic USB controller. On some computers, the Space Mouse Classic USB is not installed correctly. I tried with the help of your device to solve this problem. Space Mouse certainly didn't work with hid-remapper. I want to ask you to make Space Mouse Compact emulation firmware for Space Mouse Classic USB based on the hid-remapper board. Ready to become a firmware tester.

photo_2023-03-08_22-54-15

photo_2023-03-08_22-56-41

photo_2023-03-08_22-56-51

jfedor2 commented 1 year ago

Do you have means to dump the HID report descriptor of the device?

On Linux it can be done with usbhid-dump or hid-recorder from the hid-tools package. And on Windows with Wireshark.

Even now you should probably be able to map the device's buttons/axes to mouse or keyboard with HID Remapper, it's just that you have to know the HID usage codes that it sends. Does is show some strange looking hex codes in the input list when it's connected? Like 0x00010033 or something.

jfedor2 commented 1 year ago

Nice enclosure BTW.

Platidors commented 1 year ago

usb.zip I tried using Wireshark. I don't know if I did it right.

jfedor2 commented 1 year ago

I can see the device and configuration descriptors (and actual traffic), but not the report descriptor. I think there was some trick to getting it with Wireshark. Did you unplug and re-plug the device while capturing?

Platidors commented 1 year ago

USB2.zip here is the disconnect and connect file

jfedor2 commented 1 year ago

Yeah, that's it!

So based on this, assuming HID Remapper works with this device on hardware level, when you connect it and just keep the default configuration, the button labelled "1" should work as the left mouse button. If that's working then we can try to make it emulate a modern SpaceMouse so that it works with current software.

Platidors commented 1 year ago

It didn't work for me. Or am I doing something wrong. When a regular mouse is connected, the LED blinks, when a space mouse is connected, the LED does not glow. Button "1" does nothing.

jfedor2 commented 1 year ago

The single Pico version doesn't work with some devices, even if such cases are rare with the newest version. You could try making the dual Pico variant.

Platidors commented 1 year ago

The dual version HID-remapper will still not work as an emulator. What can be obtained by making a double version?

jfedor2 commented 1 year ago

We can easily make it into an emulator by changing the output report descriptor (and the USB vendor/product IDs). But it has to be able to receive inputs from your Classic, which the single Pico version seems to have trouble with.

Platidors commented 1 year ago

Okay, I'll try to build a double version tomorrow

Platidors commented 1 year ago

Today I collected a double version. When you connect a space mouse, it starts acting on the cursor. When the puck moves, the cursor moves to the lower right corner, pressing the buttons has the same effect on the cursor. The LED on the remapper starts blinking when the space mouse is actuated.

photo_2023-03-10_16-46-47

photo_2023-03-10_16-46-42

jfedor2 commented 1 year ago

OK, this is a good sign I think.

Try flashing your HID Remapper with this test firmware:

remapper_dual_a_spacemouse.zip

With this firmware it should pretend to be a SpaceMouse Compact. Because of this you won't be able to use the web configuration tool to change the mappings, but the default passthrough configuration should be good at least to test.

When I tested with a real SpaceMouse Compact connected to it, I noticed some choppiness in the movements so there's probably more to look into, but it worked well enough to fool the 3Dconnexion drivers and Fusion 360.

Platidors commented 1 year ago

After the firmware, the remapper became defined as a compact space mouse. Pressing the buttons and moving the joystick opens the radial menu 3Dconnexion. The object in the programs does not move

jfedor2 commented 1 year ago

Weird. It's as if we're somehow misinterpreting the data coming from the device, but I didn't notice any strange things in the descriptor or the captured traffic that could be the cause. Let me think of some way to debug this.

jfedor2 commented 1 year ago

Do you have a USB-TTL adapter by any chance? To read serial output from the Pico?

Platidors commented 1 year ago

Unfortunately, no such device is available.

Platidors commented 1 year ago

It was necessary to flash only part A? When idle, the reassigner constantly sends a report request 2023-03-10 193945

jfedor2 commented 1 year ago

What's inside these reports (responses in particular)? It might be that there's some noise in the sensors and your device keeps sending reports as well and the remapper passes them on to the PC.

And let me make sure I understood correctly, does the 3Dconnexion radial menu open even when not pressing any buttons on the device (just moving the controller)?

Platidors commented 1 year ago

Yes, any movement of the space mouse classic works out pressing 2 buttons of the space mouse compact

Platidors commented 1 year ago

The report request is constantly even if you disconnect the space mouse from the remapper USB3.zip

jfedor2 commented 1 year ago

This in itself is not a problem I think. It happens because in the SpaceMouse Classic report descriptor, all the X/Y/Z/RX/RY/RZ inputs are defined as absolute. In the SpaceMouse Compact report descriptor, which we're using for the PC side, they are defined as relative (which is a mistake in my opinion, but it doesn't matter normally). HID Remapper just repeats the last seen state, even if the device that originally generated that state was disconnected.

Maybe I will try and program another HID Remapper to emulate a SpaceMouse Classic, connect it to the first one and see if there's something in the behavior that I missed.

jfedor2 commented 1 year ago

OK, I've found one issue that was preventing the axes from working properly.

This doesn't explain the button behavior, but at least maybe the rotations/translation will work now.

Try this firmware.

remapper_dual_a_spacemouse2.zip

Platidors commented 1 year ago

The behavior of the joystick on this firmware has not changed. The command to launch the two buttons of the space mouse compact

jfedor2 commented 1 year ago

Hmm then I'm out of ideas for now.

Platidors commented 1 year ago

I have an arduino nano. I can make a ttl usb converter out of it.

jfedor2 commented 1 year ago

Sounds like a plan. The default TX pin on the dual HID Remapper is GPIO 0 and the baud rate is 921600 (connect it to the A side Pico). By default it just prints the number of received and sent reports every second. Let me know if you can see that and I'll make a build with some diagnostics.

Platidors commented 1 year ago

Conected image

jfedor2 commented 1 year ago

It should currently be outputting something like this (in readable ASCII), assuming no inputs are sent:

0 0
0 0
0 0

Not sure what the setup is, but you probably need to set the parameters in the Arduino sketch, not on PC side (baud rate etc.).

jfedor2 commented 1 year ago

Data bits should be 8 (again, on both sides).

Platidors commented 1 year ago

image

jfedor2 commented 1 year ago

Great!

Try this then.

remapper_dual_a_spacemouse3.zip

It should output something like this when moving the joystick:

recv: 00 00 a1 ff 00 00 15 00 00 00 00 00 00 00 
00010035: 0
00010034: 0
00010033: 0
00090001: 0
00090002: 0
00090003: 0
00090004: 0
00090005: 0
00090006: 0
00090007: 0
00090008: 0
00090009: 0
0009000c: 0
00010031: 0
00010030: -95
00010032: 21

It's what it receives and how it interprets it. 0009000x are buttons, 0001003x are translations/rotations. In the "recv" line, there should be two bytes for the buttons and then two bytes for X, Y, Z, RX, RY, RZ. Try to see if it corresponds to what you're doing with the controller. Particularly if it looks like the buttons are activated when they're not.

You might also get some "overflow!" messages, don't worry about them for now, I will think on how to fix it, but it should be a separate issue.

Platidors commented 1 year ago

joystick.txt key1.txt

jfedor2 commented 1 year ago

Weird! It looks like we're receiving the reports split into two parts, 8+6 bytes. Not sure why.

(EDIT: I guess it's split because the maximum packet length is 8 and the report length is 14. Should this be handled by the application on the receiving end? Or somewhere in the library?)

Anyway, try this build with a workaround:

remapper_dual_a_spacemouse4.zip

Platidors commented 1 year ago

Yes, it works. Buttons 1 and 2 work as configured in 3Dconexion control center . The joystick also works on all axes, but in my opinion some axis does not work there. But that's good.)

Platidors commented 1 year ago

Confused "up" "down" with "zoom in" "zoom out"

jfedor2 commented 1 year ago

Cool. Here's a build with the diagnostics removed. Let me know if you're seeing any "overflow!" messages while using the joystick.

remapper_dual_a_spacemouse5.zip

Platidors commented 1 year ago

overflow.txt

jfedor2 commented 1 year ago

OK, this should solve that issue.

remapper_dual_a_spacemouse6.zip

Do the axes work correctly now, by the way? You can configure a lot of the behavior in 3Dconnexion's utility.

Platidors commented 1 year ago

Yes, everything seems to be fine in the terminal.

image

In software 3Dconnexion control panel, I can only invert the direction of the axes. But I can't replace one axle with another. Axis "up" "down" should be replaced with "zoom in" "zoom out". When the joystick is raised, the object is approaching, it must go up

jfedor2 commented 1 year ago

Actually there is a "Zoom Direction" setting, do you have it set to "Forward / Backward"?

Do the rotation axes work the way you expect them to?

Swapping axes is of course not a problem, it is after all a HID Remapper.

Platidors commented 1 year ago

rotation and tilt seem to work correctly

Platidors commented 1 year ago

Actually there is a "Zoom Direction" setting, do you have it set to "Forward / Backward"?

I tried switching, it gets worse

jfedor2 commented 1 year ago

OK, this swaps Y and Z axes, which I think is what we want.

remapper_dual_a_spacemouse7.zip

Platidors commented 1 year ago

The axes are swapped, the zoom works well. up and down works inversely. I led you into confusion, the tilt and turn axes are the same mixed up.

jfedor2 commented 1 year ago

OK, so like I said, since this is actually HID Remapper, you can swap and invert the axes yourself. The only problem is that since we're faking the USB Vendor/Product IDs, the regular web config interface won't recognize the device. So I made a custom version that ignores the IDs and lets you select from the list of all devices.

Load this firmware (the previous one has mappings disabled):

remapper_dual_a_spacemouse8.zip

And go here to set up the mappings:

https://www.jfedor.org/misc2/spacemouse-remap/

For example like this: Screenshot from 2023-03-11 22-15-47 Or you might need to set scaling to -1 for one of the rotation axes as well. Play around. If you haven't used HID Remapper before there's some documentation in the repository README.

Platidors commented 1 year ago

Thanks a lot for the great work. Finally managed to adjust the axis. The configuration looks like this image

hid-remapper-config.zip

And another question. Is it possible to assign any buttons or keyboard shortcuts to the remaining buttons?

jfedor2 commented 1 year ago

Not with the current version as I replaced the keyboard and mouse stuff with spacemouse emulation, but maybe it could be added back on a separate interface or something.

Platidors commented 1 year ago

I have a space explorer, it has 16 buttons. You can try to emulate it. Although it has been removed from support, it still works properly in all programs with 10.6.4 drivers. If you want to let me know, you can experiment with it. But even now it works very well.

jfedor2 commented 1 year ago

If you can, just dump the report descriptor with Wireshark like you did with the Classic.

Ideally I'd like to get the descriptor for one of the modern supported devices with multiple buttons (SpaceMouse Pro or Enterprise).