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

Refine battery % calculation #31

Closed
Achronite opened this issue Mar 29, 2023 · 2 comments · Fixed by #39
Closed

Refine battery % calculation #31

Achronite opened this issue Mar 29, 2023 · 2 comments · Fixed by #39
Labels
bug Something isn't working

Comments

@Achronite
Copy link
Owner

After some testing, when the switch statement for battery % calculation uses this formula:
9412 - 23449*(v/batteries) + 19240*(vv/batteries) - 5176(vvv/batteries)

It does not seem to work properly and can return a -ve value. Fix this to work!

@Achronite Achronite added the bug Something isn't working label Mar 29, 2023
@Achronite
Copy link
Owner Author

Thoughts: Could try using the table here: https://en.wikipedia.org/wiki/Alkaline_battery#Voltage

@Achronite
Copy link
Owner Author

New code for calculation released to development branch based on the values above:

let v = msg[key]/batteries;
let charge = 0;
if (v >= 1.55){
   charge = 100;
} else if (v < 1.1 ){
   charge = 0
} else if (v < 1.18 ){
   charge = 5;
} else {
   // use a simple linear equation for the rest (y=mx+c), based on 1.44v=90% and 1.2v=10%
   charge = (333.3*v) - 390;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant