Skip to content

Commit 56b67be

Browse files
committed
nicla-system: Catch error case.
1 parent d2c93a0 commit 56b67be

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

libraries/Nicla_System/src/Nicla_System.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,11 @@ void nicla::setRegulatedBatteryVoltage(float voltage){
206206
}
207207

208208
float nicla::getCurrentBatteryVoltage(){
209-
return getRegulatedBatteryVoltage() / 100 * getBatteryPercentage();
209+
auto percentage = getBatteryPercentage();
210+
if (percentage < 0) {
211+
return 0;
212+
}
213+
return getRegulatedBatteryVoltage() / 100 * percentage;
210214
}
211215

212216
int8_t nicla::getBatteryPercentage(bool useLatchedValue) {

0 commit comments

Comments
 (0)