diff --git a/app/src/main/cpp/PhoneDevice.cpp b/app/src/main/cpp/PhoneDevice.cpp index 2ed3776e..3a75b7cc 100644 --- a/app/src/main/cpp/PhoneDevice.cpp +++ b/app/src/main/cpp/PhoneDevice.cpp @@ -334,6 +334,7 @@ bool CPhoneDevice::QuerySystemProperties(std::map& pro char value[PROP_VALUE_MAX] = { 0 }; std::map powerInfo; int res = 0; + int bv = -1; for (std::map::iterator it = properties.begin(); it != properties.end(); ++it) { @@ -474,33 +475,36 @@ bool CPhoneDevice::QuerySystemProperties(std::map& pro break; } } - else if (it->first == (PROP_BATTERY_VOLTAGE)) + else if (it->first == (PROP_BATTERY_POWER)) + { + it->second = std::to_string(GpioControl::getBatteryPower()); + } + else if (it->first == (PROP_BATTERY_BUS_VOL) || it->first == (PROP_BATTERY_VOLTAGE)) { - // double val = GpioControl::getBatteryVoltage() * 3.0 / 1000.0; // // BatVol int val = -1; // // BatVol - char str[32] = { 0 }; - for (int idx = 0; idx < 3; idx++) + for (int idx = 0; idx < DEFAULT_BATTERY_QUERY_RETRIES; idx++) { - val = GpioControl::getBatteryVoltage(); // // BatVol + val = GpioControl::getBatteryBusVoltage(); // // BatVol if (val >= 0) { break; } + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + } + + if (val > 0) + { + bv = val; + char str[32] = { 0 }; + snprintf(str, sizeof(str), "%.1f", val / 1000.0); + it->second = str; + } + else + { +#ifdef _DEBUG + int aa = 0; +#endif } - snprintf(str, sizeof(str), "%.1f", val / 1000.0); - it->second = str; - } - else if (it->first == (PROP_BATTERY_CURRENT)) - { - it->second = std::to_string(GpioControl::getBatteryCurrent()); - } - else if (it->first == (PROP_BATTERY_POWER)) - { - it->second = std::to_string(GpioControl::getBatteryPower()); - } - else if (it->first == (PROP_BATTERY_BUS_VOL)) - { - it->second = std::to_string(GpioControl::getBatteryBusVoltage()); } else if ((it->first == (PROP_SIGNAL_4G)) || (it->first == (PROP_SIGNAL_2G)) || (it->first == (PROP_SIGNAL_LEVEL))) { @@ -520,6 +524,30 @@ bool CPhoneDevice::QuerySystemProperties(std::map& pro } } + std::map::iterator it = properties.find(PROP_BATTERY_CURRENT); + if (it != properties.end()) + { + if (bv == -1) + { + for (int idx = 0; idx < DEFAULT_BATTERY_QUERY_RETRIES; idx++) + { + bv = GpioControl::getBatteryBusVoltage(); // // BatVol + if (bv >= 0) + { + break; + } + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + } + } + + if (bv > 0) + { + char str[32] = { 0 }; + float batteryCurrent = STANDARD_CURRENT_64V / ((float)bv / 1000.0f / STANDARD_VOLTAGE_64V); + snprintf(str, sizeof(str), "%d", (int)batteryCurrent); + it->second = str; + } + } // __system_property_get("ro.telephony.default_network", value); return true;