Skip to content
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

Fixed Anti Gravity Gain value #2005

Merged
merged 1 commit into from May 6, 2020

Conversation

asizon
Copy link
Member

@asizon asizon commented May 5, 2020

Fixes #2007
Kudos to @selimmch for finding it
This is a bug in the code presented since this feature was added, also before, if you unchek antigravity without saving,you lost you configured value. Now we can note this bug when we aplies new 3.5 default value recently, before, we had 1.1,the limit to enable disable this feature.

@asizon
Copy link
Member Author

asizon commented May 5, 2020

what about this sonar issue??And maybe we can rename MAX_ACCELERATOR_GAIN to DEFAULT_ACCELERATOR_GAIN ??

@asizon asizon changed the title Fix antigravity gain value Fixed Anti Gravity Gain value May 5, 2020
@McGiverGim
Copy link
Member

The Sonar issue only tells you to change the == by an ===. The difference is that the triple one validates that both sides have same type. Is the recommended way.
And yes, it seems the constant contains the DEFAULT one, so I think you can rename it.

@@ -182,8 +182,12 @@ TABS.pid_tuning.initialize = function (callback) {
var checked = $(this).is(':checked');
if (checked) {
const MAX_ACCELERATOR_GAIN = semver.gte(CONFIG.apiVersion, API_VERSION_1_43) ? 3.5 : 1.1;
const itermAcceleratorGain = Math.max(ADVANCED_TUNING.itermAcceleratorGain / 1000, MAX_ACCELERATOR_GAIN);
$('.antigravity input[name="itermAcceleratorGain"]').val(itermAcceleratorGain);
const itermAcceleratorGain = Math.max(ADVANCED_TUNING.itermAcceleratorGain / 1000);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you forgot the second parameter to the Math.max function? Or you forgot to remove it completely? I suppose the second one...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes sorry, I forgot to remove the math, fixed all issues now :)

$('.antigravity input[name="itermAcceleratorGain"]').val(MAX_ACCELERATOR_GAIN);
const DEFAULT_ACCELERATOR_GAIN = semver.gte(CONFIG.apiVersion, API_VERSION_1_43) ? 3.5 : 1.1;
const itermAcceleratorGain = (ADVANCED_TUNING.itermAcceleratorGain / 1000);
if (ADVANCED_TUNING.itermAcceleratorGain === 1000) {
Copy link
Member

@McGiverGim McGiverGim May 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to not see this in the first review ;)
After removing the Math.max, the DEFAULT_ACCELERATOR_GAIN is only used inside the if, so better to move inside it:

 if (ADVANCED_TUNING.itermAcceleratorGain === 1000) {
   const DEFAULT_ACCELERATOR_GAIN = semver.gte(CONFIG.apiVersion, API_VERSION_1_43) ? 3.5 : 1.1;
   $('.antigravity input[name="itermAcceleratorGain"]').val(DEFAULT_ACCELERATOR_GAIN);
} else {

Another solution is to change the complete if-else by a:

$('.antigravity input[name="itermAcceleratorGain"]').val(ADVANCED_TUNING.itermAcceleratorGain === 1000 ?  DEFAULT_ACCELERATOR_GAIN : itermAcceleratorGain);

But maybe in this case is clearer with the if-else.

Take the form that you prefer...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont worry,fixed now, i think that I prefer if/else in this case,as you said looks more clearer.

Copy link
Member

@McGiverGim McGiverGim May 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It happens the same with the itermAcceleratorGain :( It is used only in the else part...

I think this confinement has made me slower in reactions...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking exactly that for itermAcceleratorGain

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, and it is modified too some lines up:

$('.antigravity input[name="itermAcceleratorGain"]').val(ADVANCED_TUNING.itermAcceleratorGain / 1000);

so we end assigning it twice. I think this line can be removed but is outside the scope of this PR. To me is OK now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@McGiverGim all is done now!

$('.antigravity input[name="itermAcceleratorGain"]').val(MAX_ACCELERATOR_GAIN);
const DEFAULT_ACCELERATOR_GAIN = semver.gte(CONFIG.apiVersion, API_VERSION_1_43) ? 3.5 : 1.1;
const itermAcceleratorGain = (ADVANCED_TUNING.itermAcceleratorGain / 1000);
if (ADVANCED_TUNING.itermAcceleratorGain === 1000) {
Copy link
Member

@McGiverGim McGiverGim May 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It happens the same with the itermAcceleratorGain :( It is used only in the else part...

I think this confinement has made me slower in reactions...

@sonarcloud
Copy link

sonarcloud bot commented May 5, 2020

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@mikeller mikeller added this to the 10.7.0 milestone May 6, 2020
@mikeller mikeller merged commit 41a8281 into betaflight:master May 6, 2020
sonar issue,remove unneded math,const renamed

Moved const inside if

Moved const inside else
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Anti Gravity GUI update
3 participants