-
Notifications
You must be signed in to change notification settings - Fork 17.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AP_Mount: Only save converted mount parameter if mount was previously set in the first place #27109
AP_Mount: Only save converted mount parameter if mount was previously set in the first place #27109
Conversation
Hi @joshanne, Thanks for this. Have you noticed any issue with this save? This is actually done on purpose so that we don't run the parameter conversion on each boot. |
If you flash the flight controller then boot, the parameter is immediately considered configured. So if you update to software with a configured The conversion probably should only occur if the old ie. Do not run the conversion if:
What we want to achieve is don't trample the user config if updating from an old version of software. |
At the very least the conversion should only occur if the old mount type is set to a non-zero mount type. The underlying problem is this conversion runs and writes that mount parameter even if the flight controller only ever saw a later version of software. |
…e first place The mount library force configures the mount type on conversion, even if the mount was never configured in the first place
402839b
to
10f1731
Compare
} | ||
_params[0].type.set_and_save(mnt_type); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving this inside the else ensures that we only write a value to MNT1_TYPE
if the previous MNT_TYPE
was set to a non zero value.
ie. don't set MNT1_TYPE
to a configured value of zero, as this is no longer "default".
@rmackay9 - updated the changes, comments added to both source and PR. |
I still lean toward the initial commit, because upgrading of the other mount parameters could be perfectly valid if the mount type was not set at the time of the upgrade. |
OK, thanks. The existing code is a very common pattern though so I think we should discuss with @tridge (and perhaps others) at the EU dev call later today. I think the ideal change would actually be to set the MNT1_TYPE parameter to the default value of the parameter instead of 0. I think that would maintain the current behaviour and give you what you want. As far as I know we don't have an easy way to retrieve what the default of a parameter is. |
if (mnt_type > 0) { | ||
if (mnt_type == 0) { | ||
// if the mount was not previously set, no need to perform the upgrade logic | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the old MNT_TYPE
value is zero, it is not configured, and upgrade is not required - so bail.
The mount library force configures the mount type on conversion, even if the mount was never configured in the first place.