Skip to content

Potential logic error on the battery level determination  #462

@gigapod

Description

@gigapod

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions