diff --git a/source/battery.cpp b/source/battery.cpp index 99c7963..44a9562 100644 --- a/source/battery.cpp +++ b/source/battery.cpp @@ -20,7 +20,8 @@ void initBatteryADC() { float readBatteryVoltage() { // 8 quick reads, no delay() calls, no analogReference() change int32_t raw=0; for (int i=0; i<8; i++) raw += analogRead(PIN_VBAT_READ); raw /= 8; - return (raw / 4096.0f) * 3.0f * 2.0f; + // Seeed XIAO nRF52840 Sense: 1MΩ + 510kΩ voltage divider on VBAT → multiply by 1510/510 + return (raw / 4096.0f) * 3.0f * (1510.0f / 510.0f); } int batteryPercent(float v) { diff --git a/source/main.cpp b/source/main.cpp index 2d06eed..7f85929 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -231,7 +231,7 @@ void setup() { blehid.begin(); #ifdef FEATURE_BATTERY_MONITOR - blebas.begin(); blebas.write(100); + blebas.begin(); blebas.write(batteryPercent(readBatteryVoltage())); #endif #ifdef FEATURE_CONFIG_SERVICE diff --git a/web/app.js b/web/app.js index 81b051c..a8a3a77 100644 --- a/web/app.js +++ b/web/app.js @@ -125,8 +125,12 @@ async function discoverServices() { // Telemetry notify (1 Hz) — also carries chargeStatus chars.telemetry.addEventListener('characteristicvaluechanged', e => parseTelemetry(e.target.value)); await chars.telemetry.startNotifications(); - // Initial read so values show immediately + // 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(); // IMU stream — subscribed on demand via play button chars.imuStream.addEventListener('characteristicvaluechanged', e => parseImuStream(e.target.value));