From 0fa112304ac1ae8d917d167a8a3d42d9fb7d7ca4 Mon Sep 17 00:00:00 2001 From: Matthew Date: Fri, 31 May 2024 17:46:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AF=B9=E7=94=B5=E6=B1=A0?= =?UTF-8?q?=E7=94=B5=E5=8E=8B=E7=9A=84=E4=BF=9D=E6=8A=A4=E5=A4=84=E7=90=86?= =?UTF-8?q?=E4=BB=A5=E5=8F=8A=E7=94=B5=E6=B5=81=E7=9A=84=E4=BC=B0=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/cpp/PhoneDevice.cpp | 66 +++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 19 deletions(-) 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;