magellan-spacemouse icon indicating copy to clipboard operation
magellan-spacemouse copied to clipboard

Internal workings

Open MohrJonas opened this issue 2 years ago • 5 comments

I'm trying to adapt this software to a DIY spacemouse and was wondering if you could elaborate on the internal workings a bit more. Looking at the source code, descriptors.c seems pretty clear to me. As far as I understand it, it defines the USB manufacturer, model and some other stuff.
My understanding of magellan.c is the following:

  • It sets up UART, USB and GPIO pins
  • What does this do? 🤔 https://github.com/jfedor2/magellan-spacemouse/blob/acfac3b99c4dd8fba192c1e298550e49746ed5b5/src/magellan.c#L43-L44
  • In the infinite loop, it calls tinyusb's tud_task() function to do some USB-related stuff
  • It then checks in https://github.com/jfedor2/magellan-spacemouse/blob/acfac3b99c4dd8fba192c1e298550e49746ed5b5/src/magellan.c#L51 https://github.com/jfedor2/magellan-spacemouse/blob/acfac3b99c4dd8fba192c1e298550e49746ed5b5/src/magellan.c#L55 https://github.com/jfedor2/magellan-spacemouse/blob/acfac3b99c4dd8fba192c1e298550e49746ed5b5/src/magellan.c#L59 if a translation, rotation or button press has occured that has to be reported via USB
  • After that, it reads a char from UART and that's basically where my understanding stops. Could you therefore please elaborate what this does? https://github.com/jfedor2/magellan-spacemouse/blob/acfac3b99c4dd8fba192c1e298550e49746ed5b5/src/magellan.c#L66-L131 Thank you in advance 😀

MohrJonas avatar Jun 24 '23 12:06 MohrJonas

That's the serial protocol that the legacy device speaks (the one we're adapting). If you're making your own it's not really relevant to you. You'll be reading the data from whatever sensors your device has instead.

jfedor2 avatar Jun 24 '23 13:06 jfedor2

Alright, thank you for that information. What data does the trans_report, rot_report and buttons_report expect?

MohrJonas avatar Jun 24 '23 14:06 MohrJonas

The translations and rotations are 16-bit signed values (though only -350..+350 range is used I think), one for each axis. Buttons are one bit per button, though not all of them are actually used. button_bits has some bit positions that are definitely mapped to something on a SpaceMouse Pro.

jfedor2 avatar Jun 24 '23 15:06 jfedor2

Awesome, thanks for the answer 😀 Are these values absolute or relative to the previous one, meaning if, for example, the X axis is rotated 20 degrees and is then rotated to 25 degrees, do you report 25 degrees (the absolute value) or 5 degrees (because that's the relative change that has occurred)?

MohrJonas avatar Jun 24 '23 22:06 MohrJonas

They are absolute (despite the fact that the report descriptor says they're relative).

jfedor2 avatar Jun 24 '23 23:06 jfedor2