Consider capacity for battery sensor

This commit is contained in:
scorpion-26 2023-05-10 13:08:17 +02:00
parent 80ade2b06e
commit c51fadbc79

View file

@ -92,17 +92,27 @@ namespace System
{ {
std::ifstream fullChargeFile(Config::Get().batteryFolder + "/charge_full"); std::ifstream fullChargeFile(Config::Get().batteryFolder + "/charge_full");
std::ifstream currentChargeFile(Config::Get().batteryFolder + "/charge_now"); std::ifstream currentChargeFile(Config::Get().batteryFolder + "/charge_now");
if (!fullChargeFile.is_open() || !currentChargeFile.is_open()) if (fullChargeFile.is_open() && currentChargeFile.is_open())
{ {
return -1.f; std::string fullChargeStr;
std::string currentChargeStr;
std::getline(fullChargeFile, fullChargeStr);
std::getline(currentChargeFile, currentChargeStr);
uint32_t intFullCharge = atoi(fullChargeStr.c_str());
uint32_t intCurrentCharge = atoi(currentChargeStr.c_str());
return ((double)intCurrentCharge / (double)intFullCharge);
} }
std::string fullChargeStr;
std::string currentChargeStr; // Try capacity
std::getline(fullChargeFile, fullChargeStr); std::ifstream capacityFile(Config::Get().batteryFolder + "/capacity");
std::getline(currentChargeFile, currentChargeStr); if (capacityFile.is_open())
uint32_t intFullCharge = atoi(fullChargeStr.c_str()); {
uint32_t intCurrentCharge = atoi(currentChargeStr.c_str()); std::string capacityStr;
return ((double)intCurrentCharge / (double)intFullCharge); std::getline(capacityFile, capacityStr);
uint32_t intCapacity = atoi(capacityStr.c_str());
return (double)intCapacity / 100.0;
}
return -1;
} }
RAMInfo GetRAMInfo() RAMInfo GetRAMInfo()