Skip to content

Commit

Permalink
Battery gauge fix (#52)
Browse files Browse the repository at this point in the history
* Fix battery reporting in status.json, and adjust scaling for bettery level representation

* remove comment verbosity

* change battery_value_svc to return float

Co-authored-by: rochuck <chuck@zethus.ca>
  • Loading branch information
rochuck and rochuck committed Sep 12, 2020
1 parent 189bc76 commit cc5fb49
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion components/services/battery.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static struct {
/****************************************************************************************
*
*/
int battery_value_svc(void) {
float battery_value_svc(void) {
return battery.avg;
}

Expand Down
2 changes: 1 addition & 1 deletion components/services/monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ extern bool jack_inserted_svc(void);
extern void (*spkfault_handler_svc)(bool inserted);
extern bool spkfault_svc(void);

extern int battery_value_svc(void);
extern float battery_value_svc(void);
extern uint8_t battery_level_svc(void);

20 changes: 14 additions & 6 deletions components/wifi-manager/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -1028,19 +1028,27 @@ function checkStatus() {
if (data.hasOwnProperty('Voltage')) {
var voltage = data['Voltage'];
var layer;

/* Assuming Li-ion 18650s as a power source, 3.9V per cell, or above is treated
as full charge (>75% of capacity). 3.4V is empty. The gauge is loosely
following the graph here:
https://learn.adafruit.com/li-ion-and-lipoly-batteries/voltages
using the 0.2C discharge profile for the rest of the values.
*/

if (voltage > 0) {
if (inRange(voltage, 5.8, 6.2) || inRange(voltage, 8.8, 9.2)) {
if (inRange(voltage, 5.8, 6.8) || inRange(voltage, 8.8, 10.2)) {
layer = bat0;
} else if (inRange(voltage, 6.2, 6.8) || inRange(voltage, 9.2, 10.0)) {
} else if (inRange(voltage, 6.8, 7.4) || inRange(voltage, 10.2, 11.1)) {
layer = bat1;
} else if (inRange(voltage, 6.8, 7.1) || inRange(voltage, 10.0, 10.5)) {
} else if (inRange(voltage, 7.4, 7.5) || inRange(voltage, 11.1, 11.25)) {
layer = bat2;
} else if (inRange(voltage, 7.1, 7.5) || inRange(voltage, 10.5, 11.0)) {
layer = bat3;
} else if (inRange(voltage, 7.5, 7.8) || inRange(voltage, 11.25, 11.7)) {
layer = bat3;
} else {
layer = bat4;
}
layer.setAttribute("display", "inline");
layer.setAttribute("display","inline");
}
}
if (data.hasOwnProperty('Jack')) {
Expand Down

0 comments on commit cc5fb49

Please sign in to comment.