fix: Preventing division through 0 errors
This commit is contained in:
parent
07a8de4034
commit
78f1a3c0a6
@ -7,7 +7,7 @@ namespace dlore
|
|||||||
std::string readData(std::filesystem::path path)
|
std::string readData(std::filesystem::path path)
|
||||||
{
|
{
|
||||||
std::ifstream file(path, std::ios::in);
|
std::ifstream file(path, std::ios::in);
|
||||||
if(!file) return "";
|
if(!file) return "0";
|
||||||
std::string ret;
|
std::string ret;
|
||||||
std::getline(file, ret);
|
std::getline(file, ret);
|
||||||
file.close();
|
file.close();
|
||||||
@ -26,8 +26,10 @@ namespace dlore
|
|||||||
info.ChargeFull = std::stoi(readData(classPath / "charge_full")) / 1000;
|
info.ChargeFull = std::stoi(readData(classPath / "charge_full")) / 1000;
|
||||||
info.ChargeFullDesign = std::stoi(readData(classPath / "charge_full_design")) / 1000;
|
info.ChargeFullDesign = std::stoi(readData(classPath / "charge_full_design")) / 1000;
|
||||||
|
|
||||||
info.ChargeFullPercentageDesign = 100 * info.ChargeFull / info.ChargeFullDesign;
|
if(info.ChargeFullDesign != 0) {
|
||||||
info.CapacityDesign = 100 * info.ChargeNow / info.ChargeFullDesign;
|
info.ChargeFullPercentageDesign = 100 * info.ChargeFull / info.ChargeFullDesign;
|
||||||
|
info.CapacityDesign = 100 * info.ChargeNow / info.ChargeFullDesign;
|
||||||
|
}
|
||||||
|
|
||||||
int Vnow = std::stoi(readData(classPath / "voltage_now")) / 1000;
|
int Vnow = std::stoi(readData(classPath / "voltage_now")) / 1000;
|
||||||
int Vmin = std::stoi(readData(classPath / "voltage_min_design")) / 1000;
|
int Vmin = std::stoi(readData(classPath / "voltage_min_design")) / 1000;
|
||||||
|
Loading…
Reference in New Issue
Block a user