diff --git a/components/services/battery.c b/components/services/battery.c index 6d2694b2..e1882b72 100644 --- a/components/services/battery.c +++ b/components/services/battery.c @@ -43,7 +43,7 @@ static struct { /**************************************************************************************** * */ -int battery_value_svc(void) { +float battery_value_svc(void) { return battery.avg; } diff --git a/components/services/monitor.h b/components/services/monitor.h index e8aa1dd9..bf54676f 100644 --- a/components/services/monitor.h +++ b/components/services/monitor.h @@ -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); diff --git a/components/wifi-manager/code.js b/components/wifi-manager/code.js index 52e1d32f..890b3f8d 100644 --- a/components/wifi-manager/code.js +++ b/components/wifi-manager/code.js @@ -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')) {