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

Potential logic error on the battery level determination #462

Closed
gigapod opened this issue May 12, 2023 · 2 comments
Closed

Potential logic error on the battery level determination #462

gigapod opened this issue May 12, 2023 · 2 comments

Comments

@gigapod
Copy link
Member

gigapod commented May 12, 2023

Found a potential logic error here:

Code execution never reaches the final else statement - actual code:

if (battLevel < 10)
      snprintf(tempStr, sizeof(tempStr), "Red");
    else if (battLevel < 50)
      snprintf(tempStr, sizeof(tempStr), "Yellow");
    else if (battLevel >= 50)
      snprintf(tempStr, sizeof(tempStr), "Green");
    else
      snprintf(tempStr, sizeof(tempStr), "No batt");

I think it should be something like this:

if (battLevel < 10)
      snprintf(tempStr, sizeof(tempStr), "Red");
    else if (battLevel < 50)
      snprintf(tempStr, sizeof(tempStr), "Yellow");
    else if (battLevel < 105)
      snprintf(tempStr, sizeof(tempStr), "Green");
    else
      snprintf(tempStr, sizeof(tempStr), "No batt");

I found on the DL board that if the value returned from getSOC() is > ~105, then a battery isn't connected, and the system is being powered by USB. But this could be subjective.

-K

@nseidle
Copy link
Member

nseidle commented May 12, 2023

Agreed. I can't remember my original plan but it was likely a belt-and-suspender catchall.

I too have seen the fuel gauge return >100% if no battery is attached. This is a fine solution. I may throw an upper limit of 110% with an error above that (belt and suspenders again).

@gigapod
Copy link
Member Author

gigapod commented May 12, 2023

Yeah - I'm using 110. in DL for this situation. I've seen the gauge return up to 103 in my testing with battery connected ... then backs down to 100 as it's algorithm dampens out is rate curve/gathers more data ...

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

No branches or pull requests

2 participants