magellan-spacemouse
magellan-spacemouse copied to clipboard
Internal workings
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 😀
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.
Alright, thank you for that information. What data does the trans_report, rot_report and buttons_report expect?
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.
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)?
They are absolute (despite the fact that the report descriptor says they're relative).