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

Only use serial crsf battery sensor if detected #1968

Merged
merged 6 commits into from Mar 2, 2023

Conversation

JyeSmith
Copy link
Member

@JyeSmith JyeSmith commented Nov 26, 2022

If a receiver contains an internal battery sensor, and a user also connects a FC with vbat tlm, then they will both be sent to the handset. This may cause confusion with the numbers being displayed, or alarms configured.

This PR disables devAnalogVbat (the internal battery sensor) if a serial crsf battery sensor is detected.

@@ -74,5 +76,6 @@ class Telemetry
bool callEnterBind;
bool callUpdateModelMatch;
bool sendDeviceFrame;
bool crsfBatterySensorDetected;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I could be wrong, but its probably not the best practice to assume this bool will initialise to false...

Copy link
Collaborator

Choose a reason for hiding this comment

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

C++ guarantees that variables are created with a specific initial value. And for booleans that is the false value 😄

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thats not what 5mins on stackoverflow taught me, but fair enough. I was always told that member vars should always be initialised (i.e. in the class constructor etc.)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Im happy to change it just for the readability. But there are multiple instances that should be updated and probably not as part of this PR.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yep, you are right Wez, only globals are automatically set to defaults.

Copy link
Collaborator

@wvarty wvarty left a comment

Choose a reason for hiding this comment

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

Approving this on the assumption that the un-initialised bool is working fine, given there are plenty of other examples in the code where it seems to be.

@pkendall64 pkendall64 merged commit f371894 into master Mar 2, 2023
@pkendall64 pkendall64 deleted the only-use-serial-crsf-battery-sensor-if-detected branch March 2, 2023 04:24
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.

None yet

3 participants