FIx battery quirks
This commit is contained in:
+6
-9
@@ -137,14 +137,11 @@ async function discoverServices() {
|
||||
await checkHashMatch();
|
||||
|
||||
// Telemetry notify (1 Hz) - also carries chargeStatus
|
||||
chars.telemetry.addEventListener('characteristicvaluechanged', e => parseTelemetry(e.target.value));
|
||||
console.log('[TELEM] subscribing to notifications');
|
||||
chars.telemetry.addEventListener('characteristicvaluechanged', e => {
|
||||
const val = e.target.value; // capture immediately — Chrome reuses the DataView buffer on next notify
|
||||
parseTelemetry(val);
|
||||
});
|
||||
await chars.telemetry.startNotifications();
|
||||
console.log('[TELEM] subscribed, reading initial value');
|
||||
// Initial read so values show immediately. Also force updateChargeUI() here
|
||||
// because parseTelemetry() only calls it on a *change*, and currentChargeStatus
|
||||
// starts at 0 (discharging) - so a discharging device would never trigger the
|
||||
// update and ciStatus would stay at '--'.
|
||||
parseTelemetry(await chars.telemetry.readValue());
|
||||
updateChargeUI();
|
||||
|
||||
@@ -447,16 +444,16 @@ function parseTelemetry(dv) {
|
||||
const tEl = document.getElementById('telTemp');
|
||||
tEl.className = 'telem-val '+(temp>40?'warn':'accent');
|
||||
|
||||
// chargeStatus is now delivered via telemetry (no separate characteristic)
|
||||
if (chargeStatus !== currentChargeStatus) {
|
||||
currentChargeStatus = chargeStatus;
|
||||
console.log('[TELEM] charge status:', ['discharging','charging','full'][chargeStatus] ?? chargeStatus);
|
||||
updateChargeUI();
|
||||
}
|
||||
|
||||
if (battVoltage !== null) {
|
||||
currentBattVoltage = battVoltage;
|
||||
document.getElementById('ciVolt').textContent = battVoltage.toFixed(2) + 'V';
|
||||
const pct = Math.round(Math.min(100, Math.max(0, (battVoltage - 3.00) / (4.20 - 3.00) * 100)));
|
||||
if (pct !== currentBattPct) { currentBattPct = pct; updateBatteryBar(pct, currentChargeStatus); }
|
||||
}
|
||||
}
|
||||
function formatUptime(s) {
|
||||
|
||||
Reference in New Issue
Block a user