Battery gauge fix (#52)

* 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>
This commit is contained in:
Chuck
2020-09-12 09:31:28 -06:00
committed by GitHub
parent 189bc763dd
commit cc5fb49ff8
3 changed files with 16 additions and 8 deletions

View File

@@ -43,7 +43,7 @@ static struct {
/****************************************************************************************
*
*/
int battery_value_svc(void) {
float battery_value_svc(void) {
return battery.avg;
}

View File

@@ -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);

View File

@@ -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')) {