fix: Preventing division through 0 errors

This commit is contained in:
datalore 2024-07-26 10:13:41 +02:00
parent 07a8de4034
commit 78f1a3c0a6

View File

@ -7,7 +7,7 @@ namespace dlore
std::string readData(std::filesystem::path path)
{
std::ifstream file(path, std::ios::in);
if(!file) return "";
if(!file) return "0";
std::string ret;
std::getline(file, ret);
file.close();
@ -26,8 +26,10 @@ namespace dlore
info.ChargeFull = std::stoi(readData(classPath / "charge_full")) / 1000;
info.ChargeFullDesign = std::stoi(readData(classPath / "charge_full_design")) / 1000;
if(info.ChargeFullDesign != 0) {
info.ChargeFullPercentageDesign = 100 * info.ChargeFull / info.ChargeFullDesign;
info.CapacityDesign = 100 * info.ChargeNow / info.ChargeFullDesign;
}
int Vnow = std::stoi(readData(classPath / "voltage_now")) / 1000;
int Vmin = std::stoi(readData(classPath / "voltage_min_design")) / 1000;