Skip to content

Commit

Permalink
Fix overflow in currentSensorToCentiamps()
Browse files Browse the repository at this point in the history
  • Loading branch information
shellixyz committed Apr 27, 2018
1 parent bd044de commit bd65cc2
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/sensors/battery.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ uint16_t batteryAdcToVoltage(uint16_t src)

int32_t currentSensorToCentiamps(uint16_t src)
{
int32_t microvolts = ((uint32_t)src * ADCVREF * 1000) / 0xFFF - (int32_t)batteryConfig()->current.offset * 1000;
int32_t microvolts = ((uint32_t)src * ADCVREF * 100) / 0xFFF * 10 - (int32_t)batteryConfig()->current.offset * 1000;
return microvolts / batteryConfig()->current.scale; // current in 0.01A steps
}

Expand Down

0 comments on commit bd65cc2

Please sign in to comment.