浏览代码

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>
Chuck 4 年之前
父节点
当前提交
cc5fb49ff8
共有 3 个文件被更改,包括 16 次插入8 次删除
  1. 1 1
      components/services/battery.c
  2. 1 1
      components/services/monitor.h
  3. 14 6
      components/wifi-manager/code.js

+ 1 - 1
components/services/battery.c

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

+ 1 - 1
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);
 

+ 14 - 6
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')) {