Simpit-team / KerbalSimpitRevamped-Arduino

BSD 2-Clause "Simplified" License
18 stars 19 forks source link

[Feature]: Add bitmask enum for Autopilot(SAS) modes #30

Closed hbandura closed 1 year ago

hbandura commented 1 year ago

Currently there is no bitmask enum for the SAS/Autopilot modes .
Diving in the KSP api documentation I confirmed that the bitmask is not from their api, but actually from the simpit code.
Here's a link to where the mask is created:https://github.com/Simpit-team/KerbalSimpitRevamped/blob/9ba58716efb6135461f780bc4ff2c3dd327d2b0b/KerbalSimpit/Providers/AxisControl.cs#L351

So we can conclude that the bitmask is in order respective to the definition of the ksp api enum (which is also available in this lib)
Feature request: be able to do radialInEnabled = modeBitmask & SAS_MODE_RADIAL_IN

PBechon commented 1 year ago

The autopilot modes are defined here : https://github.com/Simpit-team/KerbalSimpitRevamped-Arduino/blob/5b465bb5960908add90a12c32ceacf70d2666097/src/KerbalSimpitMessageTypes.h#L423

There is no need to define bit masks as there is only one mode active at once. When you receive 3, it means that the mode 3 is active, not that the mode 1 and 2 are active. Are you sure the code you provided is working ?

hbandura commented 1 year ago

Sorry, I wasn't clear. I'm not talking about the selected sas mode, but the available sas mode bitmask.

This: https://github.com/Simpit-team/KerbalSimpitRevamped-Arduino/blob/5b465bb5960908add90a12c32ceacf70d2666097/src/PayloadStructs.h#L23

PBechon commented 1 year ago

You can do it with one line with bool sas_radialin_available = SASModeAvailability & (1 << AP_RADIALIN) for instance. Do you want to define all the values for 1 << AP_RADIALIN for all the possibles values ? I'm not sure this will make the code clearer.

hbandura commented 1 year ago

Ah! You are absolutely right. No, that's enough, I just didn't realize the order of the AP_* enum was exactly the same as the one used for the bitmask.

PBechon commented 1 year ago

I have added this example in the documentation