Merge pull request #2550 from notEvil/chargent

chargent: added threshold
pull/2552/head
Gordon Williams 2023-02-01 15:46:04 +00:00 committed by GitHub
commit f609c6d9a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 11 deletions

View File

@ -1,2 +1,3 @@
0.01: First version
0.02: Support BangleJS2
0.03: Added threshold

View File

@ -6,6 +6,8 @@ The first stage of charging Li-ion ends at ~80% capacity when the charge voltage
This app has no UI and no configuration. To disable the app, you have to uninstall it.
New in v0.03: before the very first buzz, the average value after the peak is written to chargent.json and used as threshold for future charges. This reduces the time spent in the second charge stage.
Side notes
- Full capacity is reached after charge current drops to an insignificant level. This is quite some time after charge voltage reached its peak / `E.getBattery()` returns 100.
- This app starts buzzing some time after `E.getBattery()` returns 100 (~15min on my watch), and at least 5min after the peak to account for noise.

View File

@ -6,19 +6,27 @@
if (charging) {
if (!id) {
var max = 0;
var count = 0;
var cnt = 0;
var sum = 0;
var lim = (require('Storage').readJSON('chargent.json', true) || {}).limit || 0;
id = setInterval(() => {
var battlvl = analogRead(pin);
if (max < battlvl) {
max = battlvl;
count = 0;
var val = analogRead(pin);
if (max < val) {
max = val;
cnt = 1;
sum = val;
} else {
count++;
if (10 <= count) { // 10 * 30s == 5 min // TODO ? customizable
// TODO ? customizable
Bangle.buzz(500);
setTimeout(() => Bangle.buzz(500), 1000);
cnt++;
sum += val;
}
if (10 < cnt || (lim && lim <= max)) { // 10 * 30s == 5 min // TODO ? customizable
if (!lim) {
lim = sum / cnt;
require('Storage').writeJSON('chargent.json', {limit: lim});
}
// TODO ? customizable
Bangle.buzz(500);
setTimeout(() => Bangle.buzz(500), 1000);
}
}, 30*1000);
}

View File

@ -1,6 +1,6 @@
{ "id": "chargent",
"name": "Charge Gently",
"version": "0.02",
"version": "0.03",
"description": "When charging, reminds you to disconnect the watch to prolong battery life.",
"icon": "icon.png",
"type": "bootloader",
@ -9,5 +9,8 @@
"readme": "README.md",
"storage": [
{"name": "chargent.boot.js", "url": "boot.js"}
],
"data": [
{"name": "chargent.json"}
]
}