增加对电池电压的保护处理以及电流的估算

hdrplus
Matthew 1 year ago
parent d8cd973b01
commit 0fa112304a

@ -334,6 +334,7 @@ bool CPhoneDevice::QuerySystemProperties(std::map<std::string, std::string>& pro
char value[PROP_VALUE_MAX] = { 0 };
std::map<std::string, std::string> powerInfo;
int res = 0;
int bv = -1;
for (std::map<std::string, std::string>::iterator it = properties.begin(); it != properties.end(); ++it)
{
@ -474,33 +475,36 @@ bool CPhoneDevice::QuerySystemProperties(std::map<std::string, std::string>& 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 if (it->first == (PROP_BATTERY_CURRENT))
{
it->second = std::to_string(GpioControl::getBatteryCurrent());
}
else if (it->first == (PROP_BATTERY_POWER))
else
{
it->second = std::to_string(GpioControl::getBatteryPower());
#ifdef _DEBUG
int aa = 0;
#endif
}
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<std::string, std::string>& pro
}
}
std::map<std::string, std::string>::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;

Loading…
Cancel
Save