diff --git a/app/src/main/cpp/PhoneDevice.cpp b/app/src/main/cpp/PhoneDevice.cpp index 3a75b7cc..f54d47d8 100644 --- a/app/src/main/cpp/PhoneDevice.cpp +++ b/app/src/main/cpp/PhoneDevice.cpp @@ -689,17 +689,18 @@ float CPhoneDevice::QueryBattaryVoltage(int timesForAvg, bool* isCharging) *isCharging = chargingBusVoltage > 10.0; } - for (int idx = 0; idx < timesForAvg; ) + int matched = 0; + for (int idx = 0; idx < timesForAvg; idx++) { val = GpioControl::getBatteryVoltage(); // // BatVol if (val > 0) { totalVals += val > BATTARY_VOLTAGE_MAX ? BATTARY_VOLTAGE_MAX : val; - idx++; + matched++; } } - return (float)totalVals / 1000.0 / timesForAvg; + return (matched > 0) ? ((float)totalVals / 1000.0 / matched) : 0; } bool CPhoneDevice::RequestPosition()